|  | @@ -45,9 +45,9 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 45 | 45 |              'webp', | 
                                                                                                            
                                                            | 46 | 46 |          ], | 
                                                                                                            
                                                            | 47 | 47 |          'path' => 'files', | 
                                                                                                            
                                                            | 48 |  | -        'background' => [255, 255, 255, 127], | 
                                                                                                            
                                                            |  | 48 | +        'background' => [ 255, 255, 255, 127 ], | 
                                                                                                            
                                                            | 49 | 49 |          'watermark' => '', | 
                                                                                                            
                                                            | 50 |  | -        'thumbs' => [], | 
                                                                                                            
                                                            |  | 50 | +        'thumbs' => [ ], | 
                                                                                                            
                                                            | 51 | 51 |      ]; | 
                                                                                                            
                                                            | 52 | 52 |   | 
                                                                                                            
                                                            | 53 | 53 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -55,7 +55,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 55 | 55 |       * | 
                                                                                                            
                                                            | 56 | 56 |       * @var array | 
                                                                                                            
                                                            | 57 | 57 |       */ | 
                                                                                                            
                                                            | 58 |  | -    protected $files = []; | 
                                                                                                            
                                                            |  | 58 | +    protected $files = [ ]; | 
                                                                                                            
                                                            | 59 | 59 |   | 
                                                                                                            
                                                            | 60 | 60 |      /** | 
                                                                                                            
                                                            | 61 | 61 |       * {@inheritdoc} | 
                                                                                                                                                        
                                                        |  | @@ -72,7 +72,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 72 | 72 |   | 
                                                                                                            
                                                            | 73 | 73 |                  $this->setConfig($file, $this->defaultConfig); | 
                                                                                                            
                                                            | 74 | 74 |              } else { | 
                                                                                                            
                                                            | 75 |  | -                $this->setConfig($file, $config[$file] += $this->defaultConfig); | 
                                                                                                            
                                                            |  | 75 | +                $this->setConfig($file, $config[ $file ] += $this->defaultConfig); | 
                                                                                                            
                                                            | 76 | 76 |              } | 
                                                                                                            
                                                            | 77 | 77 |          } | 
                                                                                                            
                                                            | 78 | 78 |      } | 
                                                                                                                                                        
                                                        |  | @@ -86,12 +86,12 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 86 | 86 |   | 
                                                                                                            
                                                            | 87 | 87 |          if (!empty($config)) { | 
                                                                                                            
                                                            | 88 | 88 |              foreach (array_keys($config) as $file) { | 
                                                                                                            
                                                            | 89 |  | -                if (isset($data[$file]) && !empty($data[$file]->getClientFilename())) { | 
                                                                                                            
                                                            | 90 |  | -                    $this->setFile($file, $data[$file]); | 
                                                                                                            
                                                            |  | 89 | +                if (isset($data[ $file ]) && !empty($data[ $file ]->getClientFilename())) { | 
                                                                                                            
                                                            |  | 90 | +                    $this->setFile($file, $data[ $file ]); | 
                                                                                                            
                                                            | 91 | 91 |   | 
                                                                                                            
                                                            | 92 |  | -                    $data[$file] = $this->createName($data[$file]->getClientFilename()); | 
                                                                                                            
                                                            |  | 92 | +                    $data[ $file ] = $this->createName($data[ $file ]->getClientFilename()); | 
                                                                                                            
                                                            | 93 | 93 |                  } else { | 
                                                                                                            
                                                            | 94 |  | -                    unset($data[$file]); | 
                                                                                                            
                                                            |  | 94 | +                    unset($data[ $file ]); | 
                                                                                                            
                                                            | 95 | 95 |                  } | 
                                                                                                            
                                                            | 96 | 96 |              } | 
                                                                                                            
                                                            | 97 | 97 |          } | 
                                                                                                                                                        
                                                        |  | @@ -111,10 +111,10 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 111 | 111 |                          $fileConfig = $this->getConfig($file); | 
                                                                                                            
                                                            | 112 | 112 |   | 
                                                                                                            
                                                            | 113 | 113 |                          // Move original file | 
                                                                                                            
                                                            | 114 |  | -                        $fileObject->moveTo($this->getPath($fileConfig['path']) . DS . $entity->{$file}); | 
                                                                                                            
                                                            |  | 114 | +                        $fileObject->moveTo($this->getPath($fileConfig[ 'path' ]).DS.$entity->{$file}); | 
                                                                                                            
                                                            | 115 | 115 |   | 
                                                                                                            
                                                            | 116 | 116 |                          // Prepare thumb files | 
                                                                                                            
                                                            | 117 |  | -                        if (!empty($fileConfig['thumbs'])) { | 
                                                                                                            
                                                            |  | 117 | +                        if (!empty($fileConfig[ 'thumbs' ])) { | 
                                                                                                            
                                                            | 118 | 118 |                              $this->createThumbs($entity->{$file}, $fileConfig); | 
                                                                                                            
                                                            | 119 | 119 |                          } | 
                                                                                                            
                                                            | 120 | 120 |                      } | 
                                                                                                                                                        
                                                        |  | @@ -132,11 +132,11 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 132 | 132 |      { | 
                                                                                                            
                                                            | 133 | 133 |          $entity = $this->getTable()->find()->select( | 
                                                                                                            
                                                            | 134 | 134 |              array_merge( | 
                                                                                                            
                                                            | 135 |  | -                [$this->getTable()->getPrimaryKey()], | 
                                                                                                            
                                                            |  | 135 | +                [ $this->getTable()->getPrimaryKey() ], | 
                                                                                                            
                                                            | 136 | 136 |                  array_keys($this->getConfig()) | 
                                                                                                            
                                                            | 137 | 137 |              ) | 
                                                                                                            
                                                            | 138 | 138 |          )->where([ | 
                                                                                                            
                                                            | 139 |  | -            $this->getTable()->getAlias() . '.' . $this->getTable()->getPrimaryKey() => $entity->{$this->getTable()->getPrimaryKey()}, | 
                                                                                                            
                                                            |  | 139 | +            $this->getTable()->getAlias().'.'.$this->getTable()->getPrimaryKey() => $entity->{$this->getTable()->getPrimaryKey()}, | 
                                                                                                            
                                                            | 140 | 140 |          ])->first(); | 
                                                                                                            
                                                            | 141 | 141 |   | 
                                                                                                            
                                                            | 142 | 142 |          return $this->deleteFiles($entity); | 
                                                                                                                                                        
                                                        |  | @@ -158,20 +158,20 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 158 | 158 |       */ | 
                                                                                                            
                                                            | 159 | 159 |      protected function createThumbs(string $file, array $fileConfig): void | 
                                                                                                            
                                                            | 160 | 160 |      { | 
                                                                                                            
                                                            | 161 |  | -        $filePath = $fileConfig['path'] . DS . $file; | 
                                                                                                            
                                                            |  | 161 | +        $filePath = $fileConfig[ 'path' ].DS.$file; | 
                                                                                                            
                                                            | 162 | 162 |   | 
                                                                                                            
                                                            | 163 | 163 |          if (is_file($filePath)) { | 
                                                                                                            
                                                            | 164 | 164 |              // Check installed image library | 
                                                                                                            
                                                            | 165 |  | -            if (!extension_loaded($fileConfig['library'])) { | 
                                                                                                            
                                                            | 166 |  | -                throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $fileConfig['library'])); | 
                                                                                                            
                                                            |  | 165 | +            if (!extension_loaded($fileConfig[ 'library' ])) { | 
                                                                                                            
                                                            |  | 166 | +                throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $fileConfig[ 'library' ])); | 
                                                                                                            
                                                            | 167 | 167 |              } | 
                                                                                                            
                                                            | 168 | 168 |   | 
                                                                                                            
                                                            | 169 | 169 |              // Get extension from original file | 
                                                                                                            
                                                            | 170 | 170 |              $fileExtension = $this->getExtension($file); | 
                                                                                                            
                                                            | 171 | 171 |   | 
                                                                                                            
                                                            | 172 |  | -            $fileConfig['library'] = mb_strtolower($fileConfig['library']); | 
                                                                                                            
                                                            |  | 172 | +            $fileConfig[ 'library' ] = mb_strtolower($fileConfig[ 'library' ]); | 
                                                                                                            
                                                            | 173 | 173 |   | 
                                                                                                            
                                                            | 174 |  | -            switch ($fileConfig['library']) { | 
                                                                                                            
                                                            |  | 174 | +            switch ($fileConfig[ 'library' ]) { | 
                                                                                                            
                                                            | 175 | 175 |                  // Get image resource | 
                                                                                                            
                                                            | 176 | 176 |                  case 'gd': | 
                                                                                                            
                                                            | 177 | 177 |                      switch ($fileExtension) { | 
                                                                                                                                                        
                                                        |  | @@ -213,7 +213,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 213 | 213 |   | 
                                                                                                            
                                                            | 214 | 214 |                      break; | 
                                                                                                            
                                                            | 215 | 215 |                  default: | 
                                                                                                            
                                                            | 216 |  | -                    throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $fileConfig['library'])); | 
                                                                                                            
                                                            |  | 216 | +                    throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $fileConfig[ 'library' ])); | 
                                                                                                            
                                                            | 217 | 217 |              } | 
                                                                                                            
                                                            | 218 | 218 |   | 
                                                                                                            
                                                            | 219 | 219 |              $offsetX = 0; | 
                                                                                                                                                        
                                                        |  | @@ -222,47 +222,47 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 222 | 222 |              $cropX = 0; | 
                                                                                                            
                                                            | 223 | 223 |              $cropY = 0; | 
                                                                                                            
                                                            | 224 | 224 |   | 
                                                                                                            
                                                            | 225 |  | -            foreach ($fileConfig['thumbs'] as $thumbName => $thumbConfig) { | 
                                                                                                            
                                                            | 226 |  | -                if (isset($thumbConfig['width'])) { | 
                                                                                                            
                                                            | 227 |  | -                    list($newWidth, $newHeight) = $this->getDimensionsByNewWidth($originalWidth, $originalHeight, $thumbConfig['width']); | 
                                                                                                            
                                                            | 228 |  | -                } elseif (isset($thumbConfig['height'])) { | 
                                                                                                            
                                                            | 229 |  | -                    list($newWidth, $newHeight) = $this->getDimensionsByNewHeight($originalWidth, $originalHeight, $thumbConfig['height']); | 
                                                                                                            
                                                            | 230 |  | -                } elseif (isset($thumbConfig['shorter']) && is_array($thumbConfig['shorter']) && count($thumbConfig['shorter']) === 2) { | 
                                                                                                            
                                                            | 231 |  | -                    list($newWidth, $newHeight) = $this->getDimensionsByShorterSide($originalWidth, $originalHeight, $thumbConfig['shorter'][0], $thumbConfig['shorter'][1]); | 
                                                                                                            
                                                            | 232 |  | -                } elseif (isset($thumbConfig['longer']) && is_array($thumbConfig['longer']) && count($thumbConfig['longer']) === 2) { | 
                                                                                                            
                                                            | 233 |  | -                    list($newWidth, $newHeight) = $this->getDimensionsByLongerSide($originalWidth, $originalHeight, $thumbConfig['longer'][0], $thumbConfig['longer'][1]); | 
                                                                                                            
                                                            | 234 |  | -                } elseif (isset($thumbConfig['fit']) && is_array($thumbConfig['fit']) && count($thumbConfig['fit']) === 2) { | 
                                                                                                            
                                                            | 235 |  | -                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFit($originalWidth, $originalHeight, $thumbConfig['fit'][0], $thumbConfig['fit'][1]); | 
                                                                                                            
                                                            | 236 |  | -                } elseif (isset($thumbConfig['fit']) && is_array($thumbConfig['fit']) && count($thumbConfig['fit']) === 3) { | 
                                                                                                            
                                                            | 237 |  | -                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFit($originalWidth, $originalHeight, $thumbConfig['fit'][0], $thumbConfig['fit'][1], $thumbConfig['fit'][2]); | 
                                                                                                            
                                                            | 238 |  | -                } elseif (isset($thumbConfig['square']) && is_array($thumbConfig['square']) && count($thumbConfig['square']) === 1) { | 
                                                                                                            
                                                            | 239 |  | -                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFitToSquare($originalWidth, $originalHeight, $thumbConfig['square'][0]); | 
                                                                                                            
                                                            | 240 |  | -                } elseif (isset($thumbConfig['square']) && is_array($thumbConfig['square']) && count($thumbConfig['square']) === 2) { | 
                                                                                                            
                                                            | 241 |  | -                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFitToSquare($originalWidth, $originalHeight, $thumbConfig['square'][0], $thumbConfig['square'][1]); | 
                                                                                                            
                                                            |  | 225 | +            foreach ($fileConfig[ 'thumbs' ] as $thumbName => $thumbConfig) { | 
                                                                                                            
                                                            |  | 226 | +                if (isset($thumbConfig[ 'width' ])) { | 
                                                                                                            
                                                            |  | 227 | +                    list($newWidth, $newHeight) = $this->getDimensionsByNewWidth($originalWidth, $originalHeight, $thumbConfig[ 'width' ]); | 
                                                                                                            
                                                            |  | 228 | +                } elseif (isset($thumbConfig[ 'height' ])) { | 
                                                                                                            
                                                            |  | 229 | +                    list($newWidth, $newHeight) = $this->getDimensionsByNewHeight($originalWidth, $originalHeight, $thumbConfig[ 'height' ]); | 
                                                                                                            
                                                            |  | 230 | +                } elseif (isset($thumbConfig[ 'shorter' ]) && is_array($thumbConfig[ 'shorter' ]) && count($thumbConfig[ 'shorter' ]) === 2) { | 
                                                                                                            
                                                            |  | 231 | +                    list($newWidth, $newHeight) = $this->getDimensionsByShorterSide($originalWidth, $originalHeight, $thumbConfig[ 'shorter' ][ 0 ], $thumbConfig[ 'shorter' ][ 1 ]); | 
                                                                                                            
                                                            |  | 232 | +                } elseif (isset($thumbConfig[ 'longer' ]) && is_array($thumbConfig[ 'longer' ]) && count($thumbConfig[ 'longer' ]) === 2) { | 
                                                                                                            
                                                            |  | 233 | +                    list($newWidth, $newHeight) = $this->getDimensionsByLongerSide($originalWidth, $originalHeight, $thumbConfig[ 'longer' ][ 0 ], $thumbConfig[ 'longer' ][ 1 ]); | 
                                                                                                            
                                                            |  | 234 | +                } elseif (isset($thumbConfig[ 'fit' ]) && is_array($thumbConfig[ 'fit' ]) && count($thumbConfig[ 'fit' ]) === 2) { | 
                                                                                                            
                                                            |  | 235 | +                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFit($originalWidth, $originalHeight, $thumbConfig[ 'fit' ][ 0 ], $thumbConfig[ 'fit' ][ 1 ]); | 
                                                                                                            
                                                            |  | 236 | +                } elseif (isset($thumbConfig[ 'fit' ]) && is_array($thumbConfig[ 'fit' ]) && count($thumbConfig[ 'fit' ]) === 3) { | 
                                                                                                            
                                                            |  | 237 | +                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFit($originalWidth, $originalHeight, $thumbConfig[ 'fit' ][ 0 ], $thumbConfig[ 'fit' ][ 1 ], $thumbConfig[ 'fit' ][ 2 ]); | 
                                                                                                            
                                                            |  | 238 | +                } elseif (isset($thumbConfig[ 'square' ]) && is_array($thumbConfig[ 'square' ]) && count($thumbConfig[ 'square' ]) === 1) { | 
                                                                                                            
                                                            |  | 239 | +                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFitToSquare($originalWidth, $originalHeight, $thumbConfig[ 'square' ][ 0 ]); | 
                                                                                                            
                                                            |  | 240 | +                } elseif (isset($thumbConfig[ 'square' ]) && is_array($thumbConfig[ 'square' ]) && count($thumbConfig[ 'square' ]) === 2) { | 
                                                                                                            
                                                            |  | 241 | +                    list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->getDimensionsByFitToSquare($originalWidth, $originalHeight, $thumbConfig[ 'square' ][ 0 ], $thumbConfig[ 'square' ][ 1 ]); | 
                                                                                                            
                                                            | 242 | 242 |                  } else { | 
                                                                                                            
                                                            | 243 | 243 |                      throw new ThumbsException(__d('file', 'Unknown type or incorrect parameters of creating thumbnails!')); | 
                                                                                                            
                                                            | 244 | 244 |                  } | 
                                                                                                            
                                                            | 245 | 245 |   | 
                                                                                                            
                                                            | 246 | 246 |                  $thumbFile = str_replace('default', $thumbName, $filePath); | 
                                                                                                            
                                                            | 247 | 247 |   | 
                                                                                                            
                                                            | 248 |  | -                switch ($fileConfig['library']) { | 
                                                                                                            
                                                            |  | 248 | +                switch ($fileConfig[ 'library' ]) { | 
                                                                                                            
                                                            | 249 | 249 |                      // Get image resource | 
                                                                                                            
                                                            | 250 | 250 |                      case 'gd': | 
                                                                                                            
                                                            | 251 | 251 |                          $newImage = imagecreatetruecolor($newWidth, $newHeight); | 
                                                                                                            
                                                            | 252 | 252 |   | 
                                                                                                            
                                                            | 253 |  | -                        if (is_array($fileConfig['background'])) { | 
                                                                                                            
                                                            |  | 253 | +                        if (is_array($fileConfig[ 'background' ])) { | 
                                                                                                            
                                                            | 254 | 254 |                              // Set background color and transparent indicates | 
                                                                                                            
                                                            | 255 |  | -                            imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $fileConfig['background'][0], $fileConfig['background'][1], $fileConfig['background'][2], $fileConfig['background'][3])); | 
                                                                                                            
                                                            |  | 255 | +                            imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $fileConfig[ 'background' ][ 0 ], $fileConfig[ 'background' ][ 1 ], $fileConfig[ 'background' ][ 2 ], $fileConfig[ 'background' ][ 3 ])); | 
                                                                                                            
                                                            | 256 | 256 |                          } | 
                                                                                                            
                                                            | 257 | 257 |   | 
                                                                                                            
                                                            | 258 | 258 |                          imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); | 
                                                                                                            
                                                            | 259 | 259 |   | 
                                                                                                            
                                                            | 260 |  | -                        if ((isset($thumbConfig['square']) && is_array($thumbConfig['square'])) || (isset($thumbConfig['fit']) && is_array($thumbConfig['fit']))) { | 
                                                                                                            
                                                            |  | 260 | +                        if ((isset($thumbConfig[ 'square' ]) && is_array($thumbConfig[ 'square' ])) || (isset($thumbConfig[ 'fit' ]) && is_array($thumbConfig[ 'fit' ]))) { | 
                                                                                                            
                                                            | 261 | 261 |                              $fitImage = imagecreatetruecolor($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY)); | 
                                                                                                            
                                                            | 262 | 262 |   | 
                                                                                                            
                                                            | 263 |  | -                            if (is_array($fileConfig['background'])) { | 
                                                                                                            
                                                            |  | 263 | +                            if (is_array($fileConfig[ 'background' ])) { | 
                                                                                                            
                                                            | 264 | 264 |                                  // Set background color and transparent indicates | 
                                                                                                            
                                                            | 265 |  | -                                imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $fileConfig['background'][0], $fileConfig['background'][1], $fileConfig['background'][2], $fileConfig['background'][3])); | 
                                                                                                            
                                                            |  | 265 | +                                imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $fileConfig[ 'background' ][ 0 ], $fileConfig[ 'background' ][ 1 ], $fileConfig[ 'background' ][ 2 ], $fileConfig[ 'background' ][ 3 ])); | 
                                                                                                            
                                                            | 266 | 266 |                              } | 
                                                                                                            
                                                            | 267 | 267 |   | 
                                                                                                            
                                                            | 268 | 268 |                              imagecopyresampled($fitImage, $newImage, $offsetX, $offsetY, $cropX, $cropY, $newWidth, $newHeight, $newWidth, $newHeight); | 
                                                                                                                                                        
                                                        |  | @@ -274,10 +274,10 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 274 | 274 |                          imagesavealpha($newImage, true); | 
                                                                                                            
                                                            | 275 | 275 |   | 
                                                                                                            
                                                            | 276 | 276 |                          // Watermark | 
                                                                                                            
                                                            | 277 |  | -                        if (isset($thumbConfig['watermark']) && ($watermarkSource = file_get_contents($fileConfig['watermark'])) !== false) { | 
                                                                                                            
                                                            |  | 277 | +                        if (isset($thumbConfig[ 'watermark' ]) && ($watermarkSource = file_get_contents($fileConfig[ 'watermark' ])) !== false) { | 
                                                                                                            
                                                            | 278 | 278 |                              $watermarkImage = imagecreatefromstring($watermarkSource); | 
                                                                                                            
                                                            | 279 | 279 |   | 
                                                                                                            
                                                            | 280 |  | -                            list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbConfig['watermark']); | 
                                                                                                            
                                                            |  | 280 | +                            list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbConfig[ 'watermark' ]); | 
                                                                                                            
                                                            | 281 | 281 |   | 
                                                                                                            
                                                            | 282 | 282 |                              // Set transparent | 
                                                                                                            
                                                            | 283 | 283 |                              imagealphablending($newImage, true); | 
                                                                                                                                                        
                                                        |  | @@ -316,16 +316,16 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 316 | 316 |                          $newImage->setimagebackgroundcolor('transparent'); | 
                                                                                                            
                                                            | 317 | 317 |                          $newImage->extentimage($newWidth + (2 * $offsetX), $newHeight + (2 * $offsetY), -$offsetX, -$offsetY); | 
                                                                                                            
                                                            | 318 | 318 |   | 
                                                                                                            
                                                            | 319 |  | -                        if ((isset($thumbConfig['square']) && is_array($thumbConfig['square'])) || (isset($thumbConfig['fit']) && is_array($thumbConfig['fit']))) { | 
                                                                                                            
                                                            |  | 319 | +                        if ((isset($thumbConfig[ 'square' ]) && is_array($thumbConfig[ 'square' ])) || (isset($thumbConfig[ 'fit' ]) && is_array($thumbConfig[ 'fit' ]))) { | 
                                                                                                            
                                                            | 320 | 320 |                              $newImage->cropimage($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY), $cropX, $cropY); | 
                                                                                                            
                                                            | 321 | 321 |                          } | 
                                                                                                            
                                                            | 322 | 322 |   | 
                                                                                                            
                                                            | 323 | 323 |                          // Watermark | 
                                                                                                            
                                                            | 324 |  | -                        if (isset($thumbConfig['watermark']) && ($watermarkSource = file_get_contents($fileConfig['watermark'])) !== false) { | 
                                                                                                            
                                                            |  | 324 | +                        if (isset($thumbConfig[ 'watermark' ]) && ($watermarkSource = file_get_contents($fileConfig[ 'watermark' ])) !== false) { | 
                                                                                                            
                                                            | 325 | 325 |                              $watermarkImage = new \Imagick(); | 
                                                                                                            
                                                            | 326 | 326 |                              $watermarkImage->readimageblob($watermarkSource); | 
                                                                                                            
                                                            | 327 | 327 |   | 
                                                                                                            
                                                            | 328 |  | -                            list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbConfig['watermark']); | 
                                                                                                            
                                                            |  | 328 | +                            list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbConfig[ 'watermark' ]); | 
                                                                                                            
                                                            | 329 | 329 |   | 
                                                                                                            
                                                            | 330 | 330 |                              $newImage->compositeimage($watermarkImage, \Imagick::COMPOSITE_OVER, $watermarkPositionX, $watermarkPositionY); | 
                                                                                                            
                                                            | 331 | 331 |                          } | 
                                                                                                                                                        
                                                        |  | @@ -354,10 +354,10 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 354 | 354 |   | 
                                                                                                            
                                                            | 355 | 355 |          if (!empty($config)) { | 
                                                                                                            
                                                            | 356 | 356 |              foreach ($config as $file => $fileConfig) { | 
                                                                                                            
                                                            | 357 |  | -                if (isset($entity[$file])) { | 
                                                                                                            
                                                            | 358 |  | -                    $path = $fileConfig['path'] . DS . substr($entity[$file], 0, 37); | 
                                                                                                            
                                                            |  | 357 | +                if (isset($entity[ $file ])) { | 
                                                                                                            
                                                            |  | 358 | +                    $path = $fileConfig[ 'path' ].DS.substr($entity[ $file ], 0, 37); | 
                                                                                                            
                                                            | 359 | 359 |   | 
                                                                                                            
                                                            | 360 |  | -                    foreach (glob($path . '*') as $file) { | 
                                                                                                            
                                                            |  | 360 | +                    foreach (glob($path.'*') as $file) { | 
                                                                                                            
                                                            | 361 | 361 |                          if (file_exists($file)) { | 
                                                                                                            
                                                            | 362 | 362 |                              unlink($file); | 
                                                                                                            
                                                            | 363 | 363 |                          } | 
                                                                                                                                                        
                                                        |  | @@ -387,7 +387,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 387 | 387 |       */ | 
                                                                                                            
                                                            | 388 | 388 |      protected function setFile(string $file, UploadedFile $data): void | 
                                                                                                            
                                                            | 389 | 389 |      { | 
                                                                                                            
                                                            | 390 |  | -        $this->files[$file] = $data; | 
                                                                                                            
                                                            |  | 390 | +        $this->files[ $file ] = $data; | 
                                                                                                            
                                                            | 391 | 391 |      } | 
                                                                                                            
                                                            | 392 | 392 |   | 
                                                                                                            
                                                            | 393 | 393 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -428,7 +428,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 428 | 428 |       */ | 
                                                                                                            
                                                            | 429 | 429 |      protected function createName(string $name): string | 
                                                                                                            
                                                            | 430 | 430 |      { | 
                                                                                                            
                                                            | 431 |  | -        return Text::uuid() . '_default.' . $this->getExtension($name); | 
                                                                                                            
                                                            |  | 431 | +        return Text::uuid().'_default.'.$this->getExtension($name); | 
                                                                                                            
                                                            | 432 | 432 |      } | 
                                                                                                            
                                                            | 433 | 433 |   | 
                                                                                                            
                                                            | 434 | 434 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -473,43 +473,43 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 473 | 473 |      { | 
                                                                                                            
                                                            | 474 | 474 |          switch ($positionValue) { | 
                                                                                                            
                                                            | 475 | 475 |              case 1: // Top left | 
                                                                                                            
                                                            | 476 |  | -                return [$offsetX, $offsetY]; | 
                                                                                                            
                                                            |  | 476 | +                return [ $offsetX, $offsetY ]; | 
                                                                                                            
                                                            | 477 | 477 |   | 
                                                                                                            
                                                            | 478 | 478 |                  break; | 
                                                                                                            
                                                            | 479 | 479 |              case 2: // Top center | 
                                                                                                            
                                                            | 480 |  | -                return [($newWidth / 2) - ($watermarkWidth / 2), $offsetY]; | 
                                                                                                            
                                                            |  | 480 | +                return [ ($newWidth / 2) - ($watermarkWidth / 2), $offsetY ]; | 
                                                                                                            
                                                            | 481 | 481 |   | 
                                                                                                            
                                                            | 482 | 482 |                  break; | 
                                                                                                            
                                                            | 483 | 483 |              case 3: // Top right | 
                                                                                                            
                                                            | 484 |  | -                return [($newWidth - $watermarkWidth - $offsetX), $offsetY]; | 
                                                                                                            
                                                            |  | 484 | +                return [ ($newWidth - $watermarkWidth - $offsetX), $offsetY ]; | 
                                                                                                            
                                                            | 485 | 485 |   | 
                                                                                                            
                                                            | 486 | 486 |                  break; | 
                                                                                                            
                                                            | 487 | 487 |              case 4: // Middle left | 
                                                                                                            
                                                            | 488 |  | -                return [$offsetX, intval(($newHeight / 2) - ($watermarkHeight / 2))]; | 
                                                                                                            
                                                            |  | 488 | +                return [ $offsetX, intval(($newHeight / 2) - ($watermarkHeight / 2)) ]; | 
                                                                                                            
                                                            | 489 | 489 |   | 
                                                                                                            
                                                            | 490 | 490 |                  break; | 
                                                                                                            
                                                            | 491 | 491 |              case 5: // Middle center | 
                                                                                                            
                                                            | 492 |  | -                return [intval(($newWidth / 2) - ($watermarkWidth / 2)), intval(($newHeight / 2) - ($watermarkHeight / 2))]; | 
                                                                                                            
                                                            |  | 492 | +                return [ intval(($newWidth / 2) - ($watermarkWidth / 2)), intval(($newHeight / 2) - ($watermarkHeight / 2)) ]; | 
                                                                                                            
                                                            | 493 | 493 |   | 
                                                                                                            
                                                            | 494 | 494 |                  break; | 
                                                                                                            
                                                            | 495 | 495 |              case 6: // Middle right | 
                                                                                                            
                                                            | 496 |  | -                return [($newWidth - $watermarkWidth) - $offsetX, intval(($newHeight / 2) - ($watermarkHeight / 2))]; | 
                                                                                                            
                                                            |  | 496 | +                return [ ($newWidth - $watermarkWidth) - $offsetX, intval(($newHeight / 2) - ($watermarkHeight / 2)) ]; | 
                                                                                                            
                                                            | 497 | 497 |   | 
                                                                                                            
                                                            | 498 | 498 |                  break; | 
                                                                                                            
                                                            | 499 | 499 |              case 7: // Bottom left | 
                                                                                                            
                                                            | 500 |  | -                return [$offsetX, ($newHeight - $watermarkHeight) - $offsetY]; | 
                                                                                                            
                                                            |  | 500 | +                return [ $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; | 
                                                                                                            
                                                            | 501 | 501 |   | 
                                                                                                            
                                                            | 502 | 502 |                  break; | 
                                                                                                            
                                                            | 503 | 503 |              case 8: // Bottom center | 
                                                                                                            
                                                            | 504 |  | -                return [intval(($newWidth / 2) - ($watermarkWidth / 2)), ($newHeight - $watermarkHeight) - $offsetY]; | 
                                                                                                            
                                                            |  | 504 | +                return [ intval(($newWidth / 2) - ($watermarkWidth / 2)), ($newHeight - $watermarkHeight) - $offsetY ]; | 
                                                                                                            
                                                            | 505 | 505 |   | 
                                                                                                            
                                                            | 506 | 506 |                  break; | 
                                                                                                            
                                                            | 507 | 507 |              case 9: // Bottom right | 
                                                                                                            
                                                            | 508 |  | -                return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY]; | 
                                                                                                            
                                                            |  | 508 | +                return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; | 
                                                                                                            
                                                            | 509 | 509 |   | 
                                                                                                            
                                                            | 510 | 510 |                  break; | 
                                                                                                            
                                                            | 511 | 511 |              default: | 
                                                                                                            
                                                            | 512 |  | -                return [$offsetX, $offsetY]; | 
                                                                                                            
                                                            |  | 512 | +                return [ $offsetX, $offsetY ]; | 
                                                                                                            
                                                            | 513 | 513 |   | 
                                                                                                            
                                                            | 514 | 514 |                  break; | 
                                                                                                            
                                                            | 515 | 515 |          } | 
                                                                                                                                                        
                                                        |  | @@ -532,7 +532,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 532 | 532 |              $newHeight = intval($newWidth * ($originalHeight / $originalWidth)); | 
                                                                                                            
                                                            | 533 | 533 |          } | 
                                                                                                            
                                                            | 534 | 534 |   | 
                                                                                                            
                                                            | 535 |  | -        return [$newWidth, $newHeight]; | 
                                                                                                            
                                                            |  | 535 | +        return [ $newWidth, $newHeight ]; | 
                                                                                                            
                                                            | 536 | 536 |      } | 
                                                                                                            
                                                            | 537 | 537 |   | 
                                                                                                            
                                                            | 538 | 538 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -552,7 +552,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 552 | 552 |              $newWidth = intval($newHeight * ($originalWidth / $originalHeight)); | 
                                                                                                            
                                                            | 553 | 553 |          } | 
                                                                                                            
                                                            | 554 | 554 |   | 
                                                                                                            
                                                            | 555 |  | -        return [$newWidth, $newHeight]; | 
                                                                                                            
                                                            |  | 555 | +        return [ $newWidth, $newHeight ]; | 
                                                                                                            
                                                            | 556 | 556 |      } | 
                                                                                                            
                                                            | 557 | 557 |   | 
                                                                                                            
                                                            | 558 | 558 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -572,7 +572,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 572 | 572 |              list($newWidth, $newHeight) = self::getDimensionsByNewHeight($originalWidth, $originalHeight, $newHeight); | 
                                                                                                            
                                                            | 573 | 573 |          } | 
                                                                                                            
                                                            | 574 | 574 |   | 
                                                                                                            
                                                            | 575 |  | -        return [$newWidth, $newHeight]; | 
                                                                                                            
                                                            |  | 575 | +        return [ $newWidth, $newHeight ]; | 
                                                                                                            
                                                            | 576 | 576 |      } | 
                                                                                                            
                                                            | 577 | 577 |   | 
                                                                                                            
                                                            | 578 | 578 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -592,7 +592,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 592 | 592 |              list($newWidth, $newHeight) = self::getDimensionsByNewHeight($originalWidth, $originalHeight, $newHeight); | 
                                                                                                            
                                                            | 593 | 593 |          } | 
                                                                                                            
                                                            | 594 | 594 |   | 
                                                                                                            
                                                            | 595 |  | -        return [$newWidth, $newHeight]; | 
                                                                                                            
                                                            |  | 595 | +        return [ $newWidth, $newHeight ]; | 
                                                                                                            
                                                            | 596 | 596 |      } | 
                                                                                                            
                                                            | 597 | 597 |   | 
                                                                                                            
                                                            | 598 | 598 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -618,7 +618,7 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 618 | 618 |              } else { | 
                                                                                                            
                                                            | 619 | 619 |                  $newSizes = self::getDimensionsByLongerSide($originalWidth, $originalHeight, $newWidth, $newHeight); | 
                                                                                                            
                                                            | 620 | 620 |   | 
                                                                                                            
                                                            | 621 |  | -                if ($newWidth < $newSizes[0] || $newHeight < $newSizes[1]) { | 
                                                                                                            
                                                            |  | 621 | +                if ($newWidth < $newSizes[ 0 ] || $newHeight < $newSizes[ 1 ]) { | 
                                                                                                            
                                                            | 622 | 622 |                      $newSizes = self::getDimensionsByShorterSide($originalWidth, $originalHeight, $newWidth, $newHeight); | 
                                                                                                            
                                                            | 623 | 623 |                  } | 
                                                                                                            
                                                            | 624 | 624 |              } | 
                                                                                                                                                        
                                                        |  | @@ -628,25 +628,25 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 628 | 628 |              } else { | 
                                                                                                            
                                                            | 629 | 629 |                  $newSizes = self::getDimensionsByShorterSide($originalWidth, $originalHeight, $newWidth, $newHeight); | 
                                                                                                            
                                                            | 630 | 630 |   | 
                                                                                                            
                                                            | 631 |  | -                if ($newWidth > $newSizes[0] || $newHeight > $newSizes[1]) { | 
                                                                                                            
                                                            |  | 631 | +                if ($newWidth > $newSizes[ 0 ] || $newHeight > $newSizes[ 1 ]) { | 
                                                                                                            
                                                            | 632 | 632 |                      $newSizes = self::getDimensionsByLongerSide($originalWidth, $originalHeight, $newWidth, $newHeight); | 
                                                                                                            
                                                            | 633 | 633 |                  } | 
                                                                                                            
                                                            | 634 | 634 |              } | 
                                                                                                            
                                                            | 635 | 635 |          } | 
                                                                                                            
                                                            | 636 | 636 |   | 
                                                                                                            
                                                            | 637 |  | -        if ($newWidth < $newSizes[0]) { | 
                                                                                                            
                                                            | 638 |  | -            $cropX = ($newSizes[0] - $newWidth) / 2; | 
                                                                                                            
                                                            |  | 637 | +        if ($newWidth < $newSizes[ 0 ]) { | 
                                                                                                            
                                                            |  | 638 | +            $cropX = ($newSizes[ 0 ] - $newWidth) / 2; | 
                                                                                                            
                                                            | 639 | 639 |          } else { | 
                                                                                                            
                                                            | 640 |  | -            $offsetX = ($newWidth - $newSizes[0]) / 2; | 
                                                                                                            
                                                            |  | 640 | +            $offsetX = ($newWidth - $newSizes[ 0 ]) / 2; | 
                                                                                                            
                                                            | 641 | 641 |          } | 
                                                                                                            
                                                            | 642 | 642 |   | 
                                                                                                            
                                                            | 643 |  | -        if ($newHeight < $newSizes[1]) { | 
                                                                                                            
                                                            | 644 |  | -            $cropY = ($newSizes[1] - $newHeight) / 2; | 
                                                                                                            
                                                            |  | 643 | +        if ($newHeight < $newSizes[ 1 ]) { | 
                                                                                                            
                                                            |  | 644 | +            $cropY = ($newSizes[ 1 ] - $newHeight) / 2; | 
                                                                                                            
                                                            | 645 | 645 |          } else { | 
                                                                                                            
                                                            | 646 |  | -            $offsetY = ($newHeight - $newSizes[1]) / 2; | 
                                                                                                            
                                                            |  | 646 | +            $offsetY = ($newHeight - $newSizes[ 1 ]) / 2; | 
                                                                                                            
                                                            | 647 | 647 |          } | 
                                                                                                            
                                                            | 648 | 648 |   | 
                                                                                                            
                                                            | 649 |  | -        return [$newSizes[0], $newSizes[1], intval($offsetX), intval($offsetY), intval($cropX), intval($cropY)]; | 
                                                                                                            
                                                            |  | 649 | +        return [ $newSizes[ 0 ], $newSizes[ 1 ], intval($offsetX), intval($offsetY), intval($cropX), intval($cropY) ]; | 
                                                                                                            
                                                            | 650 | 650 |      } | 
                                                                                                            
                                                            | 651 | 651 |   | 
                                                                                                            
                                                            | 652 | 652 |      /** | 
                                                                                                                                                        
                                                        |  | @@ -691,6 +691,6 @@  discard block | 
                                                    
                                                        |  |  |  block discarded – undo | 
                                                                                                                                                                                                                    
                                                            | 691 | 691 |              } | 
                                                                                                            
                                                            | 692 | 692 |          } | 
                                                                                                            
                                                            | 693 | 693 |   | 
                                                                                                            
                                                            | 694 |  | -        return [$newWidth, $newHeight, intval($offsetX), intval($offsetY), intval($cropX), intval($cropY)]; | 
                                                                                                            
                                                            |  | 694 | +        return [ $newWidth, $newHeight, intval($offsetX), intval($offsetY), intval($cropX), intval($cropY) ]; | 
                                                                                                            
                                                            | 695 | 695 |      } | 
                                                                                                            
                                                            | 696 | 696 |  } | 
                                                                                                            
                                                            | 697 | 697 | \ No newline at end of file |