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 |
||
21 | class AssetPackage extends Object |
||
|
|||
22 | { |
||
23 | protected $_type; |
||
24 | protected $_name; |
||
25 | protected $_hash; |
||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $_releases = []; |
||
30 | protected $_saved; |
||
31 | |||
32 | /** |
||
33 | * @var integer UNIX Epoch timestamp of the latest package update |
||
34 | */ |
||
35 | protected $_updateTime; |
||
36 | |||
37 | public static function normalizeName($name) |
||
41 | |||
42 | public static function normalizeScopedName($name) |
||
46 | |||
47 | /** |
||
48 | * AssetPackage constructor. |
||
49 | * @param string $type |
||
50 | * @param string $name |
||
51 | * @param array $config |
||
52 | * @throws Exception |
||
53 | */ |
||
54 | 1 | public function __construct($type, $name, $config = []) |
|
67 | |||
68 | /** |
||
69 | * @return RegistryFactory |
||
70 | */ |
||
71 | public function getRegistry() |
||
75 | |||
76 | 1 | public function checkType($type) |
|
80 | |||
81 | 1 | public function checkName($name) |
|
85 | |||
86 | 1 | public function getFullName() |
|
90 | |||
91 | public static function buildNormalName($type, $name) |
||
95 | |||
96 | 1 | public static function buildFullName($type, $name) |
|
100 | |||
101 | public static function splitFullName($full) |
||
108 | |||
109 | /** |
||
110 | * @param string $full package name |
||
111 | * @return static |
||
112 | */ |
||
113 | public static function fromFullName($full) |
||
118 | |||
119 | public function getType() |
||
123 | |||
124 | public function getNormalName() |
||
128 | |||
129 | public function getName() |
||
133 | |||
134 | public function getHash() |
||
138 | |||
139 | /** |
||
140 | * findOne. |
||
141 | * |
||
142 | * @param string $type |
||
143 | * @param string $name |
||
144 | * @return static|null |
||
145 | */ |
||
146 | public static function findOne($type, $name) |
||
153 | |||
154 | public function load() |
||
163 | |||
164 | public function update() |
||
171 | |||
172 | /** |
||
173 | * @param \Composer\DependencyResolver\Pool $pool |
||
174 | * @return array |
||
175 | */ |
||
176 | public function prepareReleases($pool) |
||
224 | |||
225 | protected function prepareVersion($version) |
||
233 | |||
234 | protected function convertPatchToRC($version) |
||
238 | |||
239 | /** |
||
240 | * Prepares array of requires: name => constraint. |
||
241 | * @param Link[] array of package requires |
||
242 | * @return array |
||
243 | */ |
||
244 | public function prepareRequire(array $links) |
||
254 | |||
255 | public function prepareUid($version) |
||
261 | |||
262 | /** |
||
263 | * @return array |
||
264 | */ |
||
265 | public function getReleases() |
||
269 | |||
270 | /** |
||
271 | * @param $version |
||
272 | * @return array |
||
273 | */ |
||
274 | public function getRelease($version) |
||
278 | |||
279 | public function getSaved() |
||
287 | |||
288 | /** |
||
289 | * @return Storage |
||
290 | */ |
||
291 | public function getStorage() |
||
295 | |||
296 | /** |
||
297 | * Returns the latest update time (UNIX Epoch). |
||
298 | * @return int|null |
||
299 | */ |
||
300 | public function getUpdateTime() |
||
304 | |||
305 | /** |
||
306 | * Package can be updated not more often than once in 10 min. |
||
307 | * @return bool |
||
308 | */ |
||
309 | public function canBeUpdated() |
||
313 | |||
314 | /** |
||
315 | * Whether tha package should be auth-updated (if it is older than 1 day). |
||
316 | * @return bool |
||
317 | */ |
||
318 | public function canAutoUpdate() |
||
322 | |||
323 | public function isAvailable() |
||
329 | |||
330 | /** |
||
331 | * @return array |
||
332 | */ |
||
333 | public function __sleep() |
||
337 | } |
||
338 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.