Complex classes like Registry 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 Registry, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Registry implements \Countable, \IteratorAggregate |
||
20 | { |
||
21 | const ACTION_SAVE = 'save'; |
||
22 | const ACTION_DELETE = 'delete'; |
||
23 | |||
24 | /** |
||
25 | * Storage handler |
||
26 | * |
||
27 | * @var SplObjectStorage |
||
28 | */ |
||
29 | protected $store; |
||
30 | |||
31 | /** |
||
32 | * Table name |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $tableName; |
||
37 | |||
38 | /** |
||
39 | * @var integer |
||
40 | */ |
||
41 | protected $_priority = \PHP_INT_MAX; |
||
|
|||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param string $tableName |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | public function __construct($tableName) |
||
55 | |||
56 | /** |
||
57 | * Stores an object into registry |
||
58 | * |
||
59 | * @param mixed $object |
||
60 | * |
||
61 | * @return Entry |
||
62 | */ |
||
63 | public function store($object, array $identifiers = array(), $state = RegistryState::UNKNOWN, array $data = array()) |
||
102 | |||
103 | /** |
||
104 | * Fetches an object |
||
105 | * |
||
106 | * @param array $identifiers |
||
107 | * |
||
108 | * @return object|null |
||
109 | */ |
||
110 | public function get(array $identifiers, $entityClass = null) |
||
120 | |||
121 | /** |
||
122 | * Returns the table name |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function getTableName() |
||
130 | |||
131 | |||
132 | /** |
||
133 | * |
||
134 | * @param mixed $object |
||
135 | * |
||
136 | * @return Entry |
||
137 | */ |
||
138 | public function getEntry($object) |
||
148 | |||
149 | /** |
||
150 | * |
||
151 | * @return Entry |
||
152 | */ |
||
153 | protected function getEntryByIdentifiers(array $identifiers, $className = null) |
||
163 | |||
164 | /** |
||
165 | * Returns an Event Dispatcher attached to a stored object |
||
166 | * |
||
167 | * @return Dispatcher |
||
168 | * @throws UnregisteredEntityException if the $object is not registered |
||
169 | */ |
||
170 | public function getEventDispatcher($object) |
||
179 | |||
180 | /** |
||
181 | * |
||
182 | * @param mixed $object |
||
183 | * @param \Fwk\Events\Event $event |
||
184 | * |
||
185 | * @return void |
||
186 | */ |
||
187 | public function fireEvent($object, Event $event) |
||
191 | |||
192 | /** |
||
193 | * Listener to fetch last insert ID on auto-increment columns |
||
194 | * |
||
195 | * @param AbstractEntityEvent $event |
||
196 | * |
||
197 | * @return void |
||
198 | */ |
||
199 | public function getLastInsertId(AbstractEntityEvent $event) |
||
230 | |||
231 | /** |
||
232 | * Removes an object from the registry |
||
233 | * |
||
234 | * @param mixed $object |
||
235 | * |
||
236 | * @return Registry |
||
237 | * @throws UnregisteredEntityException if the $object is not registered |
||
238 | */ |
||
239 | public function remove($object) |
||
251 | |||
252 | /** |
||
253 | * Removes an object from its identifiers |
||
254 | * |
||
255 | * @param array $identifiers |
||
256 | * @param string $className |
||
257 | * |
||
258 | * @return Registry |
||
259 | */ |
||
260 | public function removeByIdentifiers(array $identifiers, $className = null) |
||
270 | |||
271 | /** |
||
272 | * Tells if the registry contains an instance of the object |
||
273 | * |
||
274 | * @param mixed $object |
||
275 | * |
||
276 | * @return boolean |
||
277 | */ |
||
278 | public function contains($object) |
||
282 | |||
283 | /** |
||
284 | * |
||
285 | * @param object $object |
||
286 | * |
||
287 | * @return integer |
||
288 | * @throws UnregisteredEntityException |
||
289 | */ |
||
290 | public function getState($object) |
||
299 | |||
300 | /** |
||
301 | * |
||
302 | * @return array |
||
303 | */ |
||
304 | public function toArray() |
||
313 | |||
314 | /** |
||
315 | * |
||
316 | * @return integer |
||
317 | */ |
||
318 | public function count() |
||
322 | |||
323 | /** |
||
324 | * |
||
325 | * @return \ArrayIterator |
||
326 | */ |
||
327 | public function getIterator() |
||
331 | |||
332 | |||
333 | public function markForAction($object, $action, array $listeners = array()) |
||
343 | |||
344 | /** |
||
345 | * |
||
346 | * @return \SplPriorityQueue |
||
347 | */ |
||
348 | public function getWorkersQueue() |
||
385 | |||
386 | /** |
||
387 | * Mark current object values (Accessor) as initial values |
||
388 | * |
||
389 | * @param mixed $object |
||
390 | * |
||
391 | * @return void |
||
392 | */ |
||
393 | public function defineInitialValues($object, Connection $connection = null, Table $table = null) |
||
406 | |||
407 | /** |
||
408 | * |
||
409 | * @param mixed $object |
||
410 | * |
||
411 | * @return array |
||
412 | */ |
||
413 | public function getChangedValues($object) |
||
422 | |||
423 | /** |
||
424 | * |
||
425 | */ |
||
426 | public function clear() |
||
434 | |||
435 | /** |
||
436 | * @return SplObjectStorage |
||
437 | */ |
||
438 | public function getStore() |
||
442 | } |
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.