Complex classes like AssetPackage 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 AssetPackage, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class AssetPackage extends Object |
||
28 | { |
||
29 | protected $_type; |
||
30 | protected $_name; |
||
31 | protected $_hash; |
||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $_releases = []; |
||
36 | protected $_saved; |
||
37 | /** |
||
38 | * @var AssetVcsRepository|BowerRegistry|NpmRegistry |
||
39 | */ |
||
40 | protected $_registry; |
||
41 | |||
42 | /** |
||
43 | * @var integer UNIX Epoch timestamp of the latest package update |
||
44 | */ |
||
45 | protected $_updateTime; |
||
46 | |||
47 | /** |
||
48 | * @var NullIO |
||
49 | */ |
||
50 | protected $_io; |
||
51 | /** |
||
52 | * @var Composer |
||
53 | */ |
||
54 | protected $_composer; |
||
55 | /** |
||
56 | * @var Composer |
||
57 | */ |
||
58 | protected static $_commonComposer; |
||
59 | |||
60 | public static function normalizeName($name) |
||
64 | 1 | ||
65 | public function __construct($type, $name, $config = []) |
||
78 | |||
79 | public function getRegistry() |
||
87 | 1 | ||
88 | public function checkType($type) |
||
92 | 1 | ||
93 | public function checkName($name) |
||
97 | 1 | ||
98 | public function getFullName() |
||
102 | 1 | ||
103 | public static function buildFullName($type, $name) |
||
107 | |||
108 | public static function splitFullName($full) |
||
115 | |||
116 | /** |
||
117 | * @param string $full package name |
||
118 | * @return static |
||
119 | */ |
||
120 | public static function fromFullName($full) |
||
125 | |||
126 | public function getType() |
||
130 | |||
131 | public function getNormalName() |
||
135 | |||
136 | public function getName() |
||
140 | |||
141 | public function getHash() |
||
145 | |||
146 | /** |
||
147 | * @return Composer |
||
148 | */ |
||
149 | public static function getCommonComposer() |
||
162 | |||
163 | public function setComposer($value) |
||
167 | |||
168 | /** |
||
169 | * @return Composer |
||
170 | */ |
||
171 | public function getComposer() |
||
179 | |||
180 | public function getIO() |
||
188 | |||
189 | /** |
||
190 | * findOne. |
||
191 | * |
||
192 | * @param string $type |
||
193 | * @param string $name |
||
194 | * @return static|null |
||
195 | */ |
||
196 | public static function findOne($type, $name) |
||
203 | |||
204 | public function load() |
||
213 | |||
214 | public function update() |
||
220 | |||
221 | /** |
||
222 | * @param AssetVcsRepository $repository |
||
223 | * @return array |
||
224 | */ |
||
225 | public function prepareReleases($repository) |
||
261 | |||
262 | /** |
||
263 | * Prepares array of requires: name => constraint. |
||
264 | * @param Link[] array of package requires. |
||
265 | * @return array |
||
266 | */ |
||
267 | public function prepareRequire(array $links) |
||
277 | |||
278 | public function prepareUid($version) |
||
284 | |||
285 | /** |
||
286 | * @return array |
||
287 | */ |
||
288 | public function getReleases() |
||
292 | |||
293 | /** |
||
294 | * @param $version |
||
295 | * @return array |
||
296 | */ |
||
297 | public function getRelease($version) |
||
301 | |||
302 | public function getSaved() |
||
310 | |||
311 | /** |
||
312 | * @return Storage |
||
313 | */ |
||
314 | public function getStorage() |
||
318 | |||
319 | /** |
||
320 | * Returns the latest update time (UNIX Epoch). |
||
321 | * @return int|null |
||
322 | */ |
||
323 | public function getUpdateTime() |
||
327 | |||
328 | /** |
||
329 | * Package can be updated not more often than once in 10 min. |
||
330 | * @return bool |
||
331 | */ |
||
332 | public function canBeUpdated() |
||
336 | |||
337 | /** |
||
338 | * Whether tha package should be auth-updated (if it is older than 1 day). |
||
339 | * @return bool |
||
340 | */ |
||
341 | public function canAutoUpdate() |
||
345 | |||
346 | /** |
||
347 | * @return array |
||
348 | */ |
||
349 | public function __sleep() |
||
353 | } |
||
354 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..