Conditions | 9 |
Paths | 44 |
Total Lines | 66 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
130 | public function createImage($source, $destination, array $style = [], $cropFocusCoords = null) |
||
131 | { |
||
132 | $this->setImage($source, $this->driver); |
||
133 | |||
134 | if (!empty($style)) { |
||
135 | $this->setStyleData($style); |
||
136 | } |
||
137 | |||
138 | if (!empty($cropFocusCoords)) { |
||
139 | $this->setCoordinateGroups($cropFocusCoords); |
||
140 | } |
||
141 | |||
142 | if (!empty($this->styleData)) { |
||
143 | switch ($this->styleData['effect']) { |
||
144 | case 'scale': |
||
145 | // Do the crop rectangle first |
||
146 | // then scale the image |
||
147 | $this->doCropRectangle(); |
||
148 | $this->scaleImage($this->styleData['width'], $this->styleData['height']); |
||
149 | break; |
||
150 | |||
151 | case 'crop': |
||
152 | // If there's no focus rectangle, |
||
153 | // just cut out the crop rectangle. |
||
154 | if (empty($this->getCoordinates('focus'))) { |
||
155 | $this->doCropRectangle(); |
||
156 | } |
||
157 | else { |
||
158 | |||
159 | $focusOffsetFinder = new FocusCropDataCalculator( |
||
160 | $this->getCoordinates('crop'), |
||
161 | $this->getCoordinates('focus'), |
||
162 | $this->styleData['width'], |
||
163 | $this->styleData['height'] |
||
164 | ); |
||
165 | |||
166 | $focusCropData = $focusOffsetFinder->getFocusCropData(); |
||
167 | if (!empty($focusCropData)) { |
||
168 | $this->cropImage( |
||
169 | $focusCropData['width'], |
||
170 | $focusCropData['height'], |
||
171 | $focusCropData['x'], |
||
172 | $focusCropData['y'] |
||
173 | ); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | $this->image->fit( |
||
178 | $this->styleData['width'], |
||
179 | $this->styleData['height'], |
||
180 | function ($constraint) { |
||
181 | $constraint->upsize(); |
||
182 | } |
||
183 | ); |
||
184 | |||
185 | break; |
||
186 | } |
||
187 | |||
188 | // Do greyscale. |
||
189 | if (!empty($this->styleData['greyscale'])) { |
||
190 | $this->image->greyscale(); |
||
191 | } |
||
192 | } |
||
193 | |||
194 | return $this->saveImage($destination); |
||
195 | } |
||
196 | |||
266 | } |