weserv/images

View on GitHub

Showing 34 of 38 total issues

File index.php has 792 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Source code of wsrv.nl (formerly images.weserv.nl), to be used on your own server(s).
 *
 * PHP version 7.4+
Severity: Major
Found in public/index.php - About 1 day to fix

    Method doThumbnail has 77 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function doThumbnail(Image $image, string $fit, int $width, int $height): Image
        {
            // Default settings
            $thumbnailOptions = [
                'auto_rotate' => false,
    Severity: Major
    Found in src/Manipulators/Thumbnail.php - About 3 hrs to fix

      Method outputImage has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function outputImage(string $uri, array $params): void
          {
              // Throttler can be null
              if ($this->throttler !== null) {
                  // For PHPUnit check if REMOTE_ADDR is set
      Severity: Major
      Found in src/Server.php - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

                if (\count($coordinates) !== 4
                    || (!is_numeric($coordinates[0]))
                    || (!is_numeric($coordinates[1]))
                    || (!is_numeric($coordinates[2]))
                    || (!is_numeric($coordinates[3]))
        Severity: Critical
        Found in src/Manipulators/Crop.php - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                  if ($this->shape === 'circle' ||
                      $this->shape === 'ellipse' ||
                      $this->shape === 'hexagon' ||
                      $this->shape === 'pentagon' ||
                      $this->shape === 'pentagon-180' ||
          Severity: Critical
          Found in src/Manipulators/Shape.php - About 2 hrs to fix

            Method getSVGShape has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function getSVGShape(int $width, int $height, string $shape): array
                {
                    $min = min($width, $height);
                    $outerRadius = $min / 2;
                    $midX = $width / 2;
            Severity: Minor
            Found in src/Manipulators/Shape.php - About 1 hr to fix

              Method run has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function run(Image $image): Image
                  {
                      // Skip this manipulator if:
                      // - There's no bg parameter.
                      // - The image doesn't have an alpha channel.
              Severity: Minor
              Found in src/Manipulators/Background.php - About 1 hr to fix

                Method run has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function run(Image $image): Image
                    {
                        $width = $this->w;
                        $height = $this->h;
                        $imageWidth = $image->width;
                Severity: Minor
                Found in src/Manipulators/Crop.php - About 1 hr to fix

                  Method initClient has 34 lines of code (exceeds 25 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 1 hr to fix

                    Method resolveRotationAndFlip has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public static function resolveRotationAndFlip(Image $image, array $params): array
                        {
                            $rotate = isset($params['or']) ? self::resolveAngleRotation($params['or']) : 0;
                            $flip = isset($params['flip']) || array_key_exists('flip', $params);
                            $flop = isset($params['flop']) || array_key_exists('flop', $params);
                    Severity: Minor
                    Found in src/Manipulators/Helpers/Utils.php - About 1 hr to fix

                      Method getCrop has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function getCrop(): array
                          {
                              $cropMethods = [
                                  'top-left' => [0, 0],
                                  't' => [50, 0], // Deprecated use top instead
                      Severity: Minor
                      Found in src/Manipulators/Crop.php - About 1 hr to fix

                        Method run has 29 lines of code (exceeds 25 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 1 hr to fix

                          Function run has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function run(Image $image): Image
                              {
                                  $width = $this->w;
                                  $height = $this->h;
                                  $imageWidth = $image->width;
                          Severity: Minor
                          Found in src/Manipulators/Crop.php - About 1 hr 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 log has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                                          public function log($level, $message, array $context = []): void
                                          {
                                              // Base64 encode buffers
                                              /*if (($message === 'newFromBuffer' || $message === 'findLoadBuffer') &&
                                                  isset($context['arguments'][0])) {
                          Severity: Minor
                          Found in src/Server.php - About 1 hr 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 getSharpen has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function getSharpen(): array
                              {
                                  $sharpPieces = explode(',', $this->sharp);
                                  $sharpenFlat = 1.0;
                                  $sharpenJagged = 2.0;
                          Severity: Minor
                          Found in src/Manipulators/Sharpen.php - About 1 hr 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 run has 26 lines of code (exceeds 25 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 1 hr to fix

                            Consider simplifying this complex logical expression.
                            Open

                                                if (($message === 'findLoad' || $message === 'findLoadBuffer' ||
                                                        $message === 'writeToFile' || $message === 'newFromFile' ||
                                                        $message === 'newFromBuffer' || $message === 'thumbnail') &&
                                                    isset($context['arguments'][0])
                                                ) {
                            Severity: Major
                            Found in src/Server.php - About 1 hr to fix

                              Consider simplifying this complex logical expression.
                              Open

                                      if (isset($params['page']) && is_numeric($params['page']) &&
                                          $params['page'] >= 0 && $params['page'] <= 100000 &&
                                          ($params['loader'] === 'VipsForeignLoadPdfFile' ||
                                              $params['loader'] === 'VipsForeignLoadTiffFile' ||
                                              $params['loader'] === 'VipsForeignLoadMagickFile')
                              Severity: Major
                              Found in src/Api/Api.php - About 1 hr to fix

                                Function getCrop has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function getCrop(): array
                                    {
                                        $cropMethods = [
                                            'top-left' => [0, 0],
                                            't' => [50, 0], // Deprecated use top instead
                                Severity: Minor
                                Found in src/Manipulators/Crop.php - About 55 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 resolveRotationAndFlip has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public static function resolveRotationAndFlip(Image $image, array $params): array
                                    {
                                        $rotate = isset($params['or']) ? self::resolveAngleRotation($params['or']) : 0;
                                        $flip = isset($params['flip']) || array_key_exists('flip', $params);
                                        $flop = isset($params['flop']) || array_key_exists('flop', $params);
                                Severity: Minor
                                Found in src/Manipulators/Helpers/Utils.php - About 55 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