Complex classes like Gd often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Gd, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class Gd extends AbstractLib implements LibInterface |
||
12 | { |
||
13 | public static $fallbackCropMethods = [ |
||
14 | 'Entropy' => ['center', 'middle'], |
||
15 | 'Balanced' => ['center', 'middle'], |
||
16 | ]; |
||
17 | |||
18 | protected $image; |
||
19 | protected $type; |
||
20 | |||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | public static function checkCompatibility() |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public static function createFromFile($filename) |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | public static function createFromString($string) |
||
58 | |||
59 | /** |
||
60 | * Constructor of the class. |
||
61 | * |
||
62 | * @param resource $image The Gd resource. |
||
63 | */ |
||
64 | public function __construct($image, $type = null) |
||
73 | |||
74 | /** |
||
75 | * Destroy the image. |
||
76 | */ |
||
77 | public function __destruct() |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function flip() |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function flop() |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function save($filename) |
||
110 | |||
111 | /** |
||
112 | * Gets the original image object. |
||
113 | * |
||
114 | * @return resource |
||
115 | */ |
||
116 | public function getImage() |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function getString() |
||
143 | |||
144 | /** |
||
145 | * {@inheritdoc} |
||
146 | */ |
||
147 | public function getMimeType() |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function getWidth() |
||
159 | |||
160 | /** |
||
161 | * {@inheritdoc} |
||
162 | */ |
||
163 | public function getHeight() |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | public function format($format) |
||
215 | |||
216 | /** |
||
217 | * {@inheritdoc} |
||
218 | */ |
||
219 | public function resize($width, $height) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | public function getCropOffsets($width, $height, $method) |
||
239 | |||
240 | /** |
||
241 | * {@inheritdoc} |
||
242 | */ |
||
243 | public function crop($width, $height, $x, $y) |
||
258 | |||
259 | /** |
||
260 | * {@inheritdoc} |
||
261 | */ |
||
262 | public function rotate($angle) |
||
272 | |||
273 | /** |
||
274 | * @param resource $watermark Watermark image resource |
||
275 | * @param array $x Position x |
||
276 | * @param array $y Position y |
||
277 | */ |
||
278 | public function watermark($watermark, $x, $y) |
||
282 | |||
283 | /** |
||
284 | * {@inheritdoc} |
||
285 | */ |
||
286 | public function opacity($opacity) |
||
314 | } |
||
315 |