Conditions | 9 |
Paths | 28 |
Total Lines | 63 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
58 | public function resize(string $path, int $size): string |
||
59 | { |
||
60 | // is not a local image? |
||
61 | if (Util::isExternalUrl($path)) { |
||
62 | $this->local = false; |
||
63 | } |
||
64 | |||
65 | $this->path = '/'.ltrim($path, '/'); |
||
66 | if (!$this->local) { |
||
67 | $this->path = $path; |
||
68 | } |
||
69 | $this->size = $size; |
||
70 | $returnPath = '/'.Util::joinPath(self::CACHE_THUMBS_PATH, $this->size.$this->path); |
||
71 | |||
72 | // source file |
||
73 | $this->setSource(); |
||
74 | |||
75 | // images cache path |
||
76 | $this->cachePath = Util::joinFile( |
||
77 | $this->config->getCachePath(), |
||
78 | self::CACHE_ASSETS_DIR, |
||
79 | self::CACHE_THUMBS_PATH |
||
80 | ); |
||
81 | |||
82 | // is size is already OK? |
||
83 | list($width, $height) = getimagesize($this->source); |
||
84 | if ($width <= $this->size && $height <= $this->size) { |
||
85 | return $this->path; |
||
86 | } |
||
87 | |||
88 | // if GD extension is not installed: can't process |
||
89 | if (!extension_loaded('gd')) { |
||
90 | throw new Exception('GD extension is required to use images resize.'); |
||
91 | } |
||
92 | |||
93 | $this->destination = Util::joinFile($this->cachePath, $this->size.$this->path); |
||
94 | |||
95 | if (Util::getFS()->exists($this->destination)) { |
||
96 | return $returnPath; |
||
97 | } |
||
98 | |||
99 | // image object |
||
100 | try { |
||
101 | $img = ImageManager::make($this->source); |
||
102 | $img->resize($this->size, null, function (\Intervention\Image\Constraint $constraint) { |
||
103 | $constraint->aspectRatio(); |
||
104 | $constraint->upsize(); |
||
105 | }); |
||
106 | } catch (NotReadableException $e) { |
||
107 | throw new Exception(sprintf('Cannot get image "%s"', $this->path)); |
||
108 | } |
||
109 | |||
110 | // return data:image for external image |
||
111 | if (!$this->local) { |
||
112 | return (string) $img->encode('data-url'); |
||
113 | } |
||
114 | |||
115 | // save file |
||
116 | Util::getFS()->mkdir(dirname($this->destination)); |
||
117 | $img->save($this->destination); |
||
118 | |||
119 | // return new path |
||
120 | return $returnPath; |
||
121 | } |
||
145 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths