Complex classes like Container 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.
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 Container, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
59 | class Container extends Dispatcher implements ArrayAccess, ContainerInterface |
||
60 | { |
||
61 | /** |
||
62 | * The objects store |
||
63 | * @var SplObjectStorage |
||
64 | */ |
||
65 | protected $store = array(); |
||
66 | |||
67 | /** |
||
68 | * Shared instances store |
||
69 | * @var SplObjectStorage |
||
70 | */ |
||
71 | private $_sharedInstances; |
||
|
|||
72 | |||
73 | /** |
||
74 | * Container Properties |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $properties = array(); |
||
78 | |||
79 | /** |
||
80 | * Properties Keys (cached) |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $propertiesMap = array(); |
||
84 | |||
85 | /** |
||
86 | * Delegates Containers |
||
87 | * @var SplObjectStorage |
||
88 | */ |
||
89 | protected $delegates; |
||
90 | |||
91 | /** |
||
92 | * Constructor |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | public function __construct() |
||
103 | |||
104 | /** |
||
105 | * Registers a definition |
||
106 | * |
||
107 | * @param string $name Identifier |
||
108 | * @param DefinitionInterface|mixed $definition Definition, callable or value |
||
109 | * |
||
110 | * @return Container |
||
111 | */ |
||
112 | public function set($name, $definition) |
||
141 | |||
142 | /** |
||
143 | * Load and returns a definition |
||
144 | * |
||
145 | * @param string $name Identifier |
||
146 | * |
||
147 | * @throws Exceptions\DefinitionNotFoundException if $name isn't a valid identifier |
||
148 | * @return mixed |
||
149 | */ |
||
150 | public function get($name) |
||
200 | |||
201 | /** |
||
202 | * Loads properties from an INI file as definitions. |
||
203 | * Theses properties can then be referenced like @propName in other |
||
204 | * definitions. |
||
205 | * |
||
206 | * @param string $iniFile Path/to/file.ini |
||
207 | * @param null|string $category The INI category to be parsed |
||
208 | * |
||
209 | * @return Container |
||
210 | * @throws Exception |
||
211 | */ |
||
212 | public function iniProperties($iniFile, $category = null) |
||
234 | |||
235 | /** |
||
236 | * Returns a property (or $default if not defined) |
||
237 | * |
||
238 | * @param string $propName The property name |
||
239 | * @param mixed $default Default value if the property is not defined |
||
240 | * |
||
241 | * @return mixed |
||
242 | */ |
||
243 | public function getProperty($propName, $default = null) |
||
253 | |||
254 | /** |
||
255 | * Defines a property. |
||
256 | * |
||
257 | * If the $value is null, the property will be unset. |
||
258 | * |
||
259 | * It recommended to store only strings as property values. Register a |
||
260 | * new Di definition for any other type. |
||
261 | * |
||
262 | * @param string $propName Property name |
||
263 | * @param null|string $value The prop value |
||
264 | * |
||
265 | * @return Container |
||
266 | */ |
||
267 | public function setProperty($propName, $value = null) |
||
280 | |||
281 | |||
282 | /** |
||
283 | * Transform properties references to their respective value |
||
284 | * |
||
285 | * @param string $str String to be transformed |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | public function propertizeString($str) |
||
297 | |||
298 | /** |
||
299 | * Unregisters a definition |
||
300 | * |
||
301 | * @param string $name Identifier |
||
302 | * |
||
303 | * @throws Exceptions\DefinitionNotFoundException if $name isn't a valid identifier |
||
304 | * @return boolean true on success |
||
305 | */ |
||
306 | public function unregister($name) |
||
322 | |||
323 | /** |
||
324 | * Tells if a definition exists at $offset |
||
325 | * |
||
326 | * @param string $name Identifier |
||
327 | * |
||
328 | * @return boolean |
||
329 | */ |
||
330 | public function has($name) |
||
340 | |||
341 | /** |
||
342 | * Returns a Definition |
||
343 | * |
||
344 | * @param string $name Identifier |
||
345 | * |
||
346 | * @return DefinitionInterface |
||
347 | * @throws Exceptions\DefinitionNotFoundException if $name isn't a valid identifier |
||
348 | */ |
||
349 | public function getDefinition($name) |
||
359 | |||
360 | /** |
||
361 | * Tells if a definition is registered at $offset |
||
362 | * |
||
363 | * @param string $offset Identifier |
||
364 | * |
||
365 | * @return boolean |
||
366 | */ |
||
367 | public function offsetExists($offset) |
||
371 | |||
372 | /** |
||
373 | * Loads and returns a definition |
||
374 | * |
||
375 | * @param string $offset Identifier |
||
376 | * |
||
377 | * @return mixed |
||
378 | */ |
||
379 | public function offsetGet($offset) |
||
383 | |||
384 | /** |
||
385 | * Registers a definition |
||
386 | * |
||
387 | * @param string $offset Identifier |
||
388 | * @param mixed $value Definition |
||
389 | * |
||
390 | * @return Container |
||
391 | */ |
||
392 | public function offsetSet($offset, $value) |
||
396 | |||
397 | /** |
||
398 | * Unregisters a Definition |
||
399 | * |
||
400 | * @param string $offset Identifier |
||
401 | * |
||
402 | * @return boolean |
||
403 | */ |
||
404 | public function offsetUnset($offset) |
||
408 | |||
409 | /** |
||
410 | * Adds a delegate/backup Container. |
||
411 | * |
||
412 | * @param ContainerInterface $container |
||
413 | * |
||
414 | * @return ContainerInterface |
||
415 | */ |
||
416 | public function delegate(ContainerInterface $container) |
||
426 | |||
427 | /** |
||
428 | * Tells if a service is in a delegated Container |
||
429 | * |
||
430 | * @param string $name |
||
431 | * |
||
432 | * @return boolean |
||
433 | */ |
||
434 | public function hasInDelegate($name) |
||
445 | |||
446 | /** |
||
447 | * Loads a definition from the first delegated Container having in (FIFO) |
||
448 | * |
||
449 | * @param string $name Service identifier |
||
450 | * |
||
451 | * @throws Exceptions\DefinitionNotFoundException when the service is not found |
||
452 | * @return mixed |
||
453 | */ |
||
454 | public function getFromDelegate($name) |
||
465 | |||
466 | /** |
||
467 | * Search definitions |
||
468 | * |
||
469 | * @param array $query Search query |
||
470 | * |
||
471 | * @return array<DefinitionInterface> |
||
472 | */ |
||
473 | public function search(array $query) |
||
486 | } |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.