weserv/images

View on GitHub

Showing 34 of 38 total issues

Function getQuality has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function getQuality(array $params, string $extension): int
    {
        $quality = 0;

        if ($extension === 'jpg' || $extension === 'webp' || $extension === 'tiff') {
Severity: Minor
Found in src/Server.php - About 45 mins 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 run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function run(Image $image): Image
    {
        $shape = $this->getShape();

        if ($shape !== null) {
Severity: Minor
Found in src/Manipulators/Shape.php - About 45 mins 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

Consider simplifying this complex logical expression.
Open

        if (isset($params['output']) && $this->isExtensionAllowed($params['output'])) {
            $extension = $params['output'];
        } elseif (($hasAlpha && ($extension !== 'png' && $extension !== 'webp' && $extension !== 'gif'))
            || !$this->isExtensionAllowed($extension)) {
            // We force the extension to PNG if:
Severity: Major
Found in src/Server.php - About 40 mins to fix

    Consider simplifying this complex logical expression.
    Open

            if ($this->t === 'fit' ||
                $this->t === 'fitup' ||
                $this->t === 'square' ||
                $this->t === 'squaredown' ||
                $this->t === 'absolute' ||
    Severity: Major
    Found in src/Manipulators/Thumbnail.php - About 40 mins to fix

      Function checkImageSize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function checkImageSize(Image $image, int $width, int $height): void
          {
              if ($width === 0 && $height === 0) {
                  $width = $image->width;
                  $height = $image->height;
      Severity: Minor
      Found in src/Manipulators/Thumbnail.php - About 35 mins 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 run has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function run(Image $image): Image
          {
              if ($this->blur === null) {
                  return $image;
              }
      Severity: Minor
      Found in src/Manipulators/Blur.php - About 35 mins 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 getSVGMask has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getSVGMask(float $midX, float $midY, array $parameters): array
          {
              /**
               * @var int $points Number of points (or number of sides for polygons)
               * @var float $outerRadius 'outer' radius of the star
      Severity: Minor
      Found in src/Manipulators/Shape.php - About 35 mins 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 calculateCrop has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function calculateCrop(array $inCoordinates, array $outCoordinates, array $offsets): array
          {
              // Default values
              $left = 0;
              $top = 0;
      Severity: Minor
      Found in src/Manipulators/Crop.php - About 35 mins 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

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

              if ($offsets[1] >= 0 && $offsets[1] < ($inCoordinates[1] - $outCoordinates[1])) {
                  $top = $offsets[1];
              } elseif ($offsets[1] >= ($inCoordinates[1] - $outCoordinates[1])) {
                  $top = $inCoordinates[1] - $outCoordinates[1];
              }
      Severity: Minor
      Found in src/Manipulators/Crop.php and 1 other location - About 30 mins to fix
      src/Manipulators/Crop.php on lines 184..188

      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 91.

      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

              if ($offsets[0] >= 0 && $offsets[0] < ($inCoordinates[0] - $outCoordinates[0])) {
                  $left = $offsets[0];
              } elseif ($offsets[0] >= ($inCoordinates[0] - $outCoordinates[0])) {
                  $left = $inCoordinates[0] - $outCoordinates[0];
              }
      Severity: Minor
      Found in src/Manipulators/Crop.php and 1 other location - About 30 mins to fix
      src/Manipulators/Crop.php on lines 190..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 91.

      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

      Function determineImageExtension has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function determineImageExtension(string $loader): string
          {
              $extension = 'unknown';
      
              switch ($loader) {
      Severity: Minor
      Found in src/Manipulators/Helpers/Utils.php - About 25 mins 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 initClient has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          private function initClient(array $guzzleOptions): void
          {
              $defaultConfig = [
                  'connect_timeout' => $this->options['connect_timeout'],
                  'decode_content' => true,
      Severity: Minor
      Found in src/Client.php - About 25 mins 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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function parse(?string $color): array
          {
              // Default to transparent
              $default = [0, 0, 0, 0];
      
      
      Severity: Minor
      Found in src/Manipulators/Helpers/Color.php - About 25 mins 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 getAllParams has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getAllParams(array $params): array
          {
              $all = $this->defaults;
      
              if (isset($params['p'])) {
      Severity: Minor
      Found in src/Server.php - About 25 mins 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

      Severity
      Category
      Status
      Source
      Language