autowp/image

View on GitHub

Showing 100 of 100 total issues

File Storage.php has 1026 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Autowp\Image;
Severity: Major
Found in src/Storage.php - About 2 days to fix

    File Sampler.php has 558 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    declare(strict_types=1);
    
    namespace Autowp\Image;
    Severity: Major
    Found in src/Sampler.php - About 1 day to fix

      Storage has 53 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Storage implements StorageInterface
      {
          private const EXTENSION_DEFAULT = 'jpg';
      
          private const INSERT_MAX_ATTEMPTS = 15;
      Severity: Major
      Found in src/Storage.php - About 7 hrs to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function flop(int $imageId): void
            {
                $imageRow = $this->getImageRow($imageId);
        
                if (! $imageRow) {
        Severity: Major
        Found in src/Storage.php and 1 other location - About 6 hrs to fix
        src/Storage.php on lines 1293..1331

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 223.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function normalize(int $imageId): void
            {
                $imageRow = $this->getImageRow($imageId);
        
                if (! $imageRow) {
        Severity: Major
        Found in src/Storage.php and 1 other location - About 6 hrs to fix
        src/Storage.php on lines 1249..1287

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 223.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if ($format->isReduceOnly() && $sizeLess) {
                    // dont crop
                    if (! $heightLess) {
                        // resize by height
                        $scaleHeight = $formatHeight;
        Severity: Major
        Found in src/Sampler.php and 1 other location - About 6 hrs to fix
        src/Sampler.php on lines 170..194

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 205.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                if ($format->isReduceOnly() && $sizeLess) {
                    if (! $heightLess) {
                        // resize by height
                        $scaleHeight = $formatHeight;
                        $scaleWidth  = (int) round($scaleHeight * $srcRatio);
        Severity: Major
        Found in src/Sampler.php and 1 other location - About 6 hrs to fix
        src/Sampler.php on lines 111..136

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 205.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Method doFormatImage has 116 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function doFormatImage(int $imageId, string $formatName): int
            {
                // find source image
                /** @var ResultSet $resultSet */
                $resultSet = $this->imageTable->select([
        Severity: Major
        Found in src/Storage.php - About 4 hrs to fix

          Function convertImagick has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
          Open

              public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
              {
                  if (! $format instanceof Sampler\Format) {
                      if (! is_array($format)) {
                          throw new Sampler\Exception("Unexpected type of format");
          Severity: Minor
          Found in src/Sampler.php - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Format has 33 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class Format
          {
              public const
                  FIT_TYPE_INNER   = 0, // вписать
                  FIT_TYPE_OUTER   = 1, // описать
          Severity: Minor
          Found in src/Sampler/Format.php - About 4 hrs to fix

            Method convertImagick has 84 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function convertImagick(Imagick $imagick, ?array $crop, $format): Imagick
                {
                    if (! $format instanceof Sampler\Format) {
                        if (! is_array($format)) {
                            throw new Sampler\Exception("Unexpected type of format");
            Severity: Major
            Found in src/Sampler.php - About 3 hrs to fix

              The class Sampler has an overall complexity of 128 which is very high. The configured complexity threshold is 50.
              Open

              class Sampler
              {
                  /**
                   * @throws ImagickException
                   */
              Severity: Minor
              Found in src/Sampler.php by phpmd

              The class Storage has an overall complexity of 183 which is very high. The configured complexity threshold is 50.
              Open

              class Storage implements StorageInterface
              {
                  private const EXTENSION_DEFAULT = 'jpg';
              
                  private const INSERT_MAX_ATTEMPTS = 15;
              Severity: Minor
              Found in src/Storage.php by phpmd

              Function cropImage has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
                  {
                      $cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
                      if (! $cropSet) {
                          throw new Sampler\Exception('Crop parameters not properly set');
              Severity: Minor
              Found in src/Sampler.php - About 3 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function doFormatImage has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function doFormatImage(int $imageId, string $formatName): int
                  {
                      // find source image
                      /** @var ResultSet $resultSet */
                      $resultSet = $this->imageTable->select([
              Severity: Minor
              Found in src/Storage.php - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method cropImage has 67 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function cropImage(Imagick $imagick, array $crop, Sampler\Format $format): Imagick
                  {
                      $cropSet = isset($crop['width'], $crop['height'], $crop['left'], $crop['top']);
                      if (! $cropSet) {
                          throw new Sampler\Exception('Crop parameters not properly set');
              Severity: Major
              Found in src/Sampler.php - About 2 hrs to fix

                Method addImageFromFile has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function addImageFromFile(string $file, string $dirName, array $options = []): int
                    {
                        $imageInfo = getimagesize($file);
                
                        $width  = (int) $imageInfo[0];
                Severity: Major
                Found in src/Storage.php - About 2 hrs to fix

                  Method addImageFromImagick has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function addImageFromImagick(Imagick $imagick, string $dirName, array $options = []): int
                      {
                          $width  = $imagick->getImageWidth();
                          $height = $imagick->getImageHeight();
                  
                  
                  Severity: Major
                  Found in src/Storage.php - About 2 hrs to fix

                    Method extendHorizontal has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function extendHorizontal(Imagick $imagick, Sampler\Format $format): void
                        {
                            $fRatio = (int) $format->getWidth() / (int) $format->getHeight();
                    
                            $srcWidth  = $imagick->getImageWidth();
                    Severity: Minor
                    Found in src/Sampler.php - About 2 hrs to fix

                      Method extendVertical has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function extendVertical(Imagick $imagick, Sampler\Format $format): void
                          {
                              $fRatio = (int) $format->getWidth() / (int) $format->getHeight();
                      
                              $srcWidth  = $imagick->getImageWidth();
                      Severity: Minor
                      Found in src/Sampler.php - About 2 hrs to fix
                        Severity
                        Category
                        Status
                        Source
                        Language