Complex classes like DoctrineORMMapper 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 DoctrineORMMapper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class DoctrineORMMapper implements EventSubscriber |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $associations; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $discriminators; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $discriminatorColumns; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $inheritanceTypes; |
||
40 | |||
41 | /** |
||
42 | * @var ManagerRegistry |
||
43 | */ |
||
44 | protected $doctrine; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $indexes; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $uniques; |
||
55 | |||
56 | /** |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $overrides; |
||
60 | |||
61 | /** |
||
62 | * @param ManagerRegistry $doctrine |
||
63 | * @param array $associations |
||
64 | * @param array $indexes |
||
65 | * @param array $discriminators |
||
66 | * @param array $discriminatorColumns |
||
67 | * @param array $inheritanceTypes |
||
68 | * @param array $uniques |
||
69 | * @param array $overrides |
||
70 | */ |
||
71 | public function __construct(ManagerRegistry $doctrine, array $associations = array(), array $indexes = array(), array $discriminators = array(), array $discriminatorColumns = array(), array $inheritanceTypes = array(), array $uniques = array(), array $overrides = array()) |
||
81 | |||
82 | /** |
||
83 | * @return array |
||
84 | */ |
||
85 | public function getSubscribedEvents() |
||
91 | |||
92 | /** |
||
93 | * @param string $class |
||
94 | * @param string $field |
||
95 | * @param array $options |
||
96 | */ |
||
97 | public function addAssociation($class, $field, array $options) |
||
105 | |||
106 | /** |
||
107 | * Add a discriminator to a class. |
||
108 | * |
||
109 | * @param string $class The Class |
||
110 | * @param string $key Key is the database value and values are the classes |
||
111 | * @param string $discriminatorClass The mapped class |
||
112 | */ |
||
113 | public function addDiscriminator($class, $key, $discriminatorClass) |
||
123 | |||
124 | /** |
||
125 | * @param string $class |
||
126 | * @param array $columnDef |
||
127 | */ |
||
128 | public function addDiscriminatorColumn($class, array $columnDef) |
||
134 | |||
135 | /** |
||
136 | * @param string $class |
||
137 | * @param string $type |
||
138 | */ |
||
139 | public function addInheritanceType($class, $type) |
||
145 | |||
146 | /** |
||
147 | * @param string $class |
||
148 | * @param string $name |
||
149 | * @param array $columns |
||
150 | */ |
||
151 | public function addIndex($class, $name, array $columns) |
||
163 | |||
164 | /** |
||
165 | * @param string $class |
||
166 | * @param string $name |
||
167 | * @param array $columns |
||
168 | */ |
||
169 | public function addUnique($class, $name, array $columns) |
||
181 | |||
182 | /** |
||
183 | * Adds new ORM override. |
||
184 | * |
||
185 | * @param string $class |
||
186 | * @param string $type |
||
187 | * @param array $options |
||
188 | */ |
||
189 | final public function addOverride($class, $type, array $options) |
||
197 | |||
198 | /** |
||
199 | * @param $eventArgs |
||
200 | */ |
||
201 | public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) |
||
214 | |||
215 | /** |
||
216 | * @param ClassMetadataInfo $metadata |
||
217 | * |
||
218 | * @throws \RuntimeException |
||
219 | */ |
||
220 | private function loadAssociations(ClassMetadataInfo $metadata) |
||
242 | |||
243 | /** |
||
244 | * @param ClassMetadataInfo $metadata |
||
245 | * |
||
246 | * @throws \RuntimeException |
||
247 | */ |
||
248 | private function loadDiscriminatorColumns(ClassMetadataInfo $metadata) |
||
266 | |||
267 | /** |
||
268 | * @param ClassMetadataInfo $metadata |
||
269 | * |
||
270 | * @throws \RuntimeException |
||
271 | */ |
||
272 | private function loadInheritanceTypes(ClassMetadataInfo $metadata) |
||
285 | |||
286 | /** |
||
287 | * @param ClassMetadataInfo $metadata |
||
288 | * |
||
289 | * @throws \RuntimeException |
||
290 | */ |
||
291 | private function loadDiscriminators(ClassMetadataInfo $metadata) |
||
308 | |||
309 | /** |
||
310 | * @param ClassMetadataInfo $metadata |
||
311 | */ |
||
312 | private function loadIndexes(ClassMetadataInfo $metadata) |
||
322 | |||
323 | /** |
||
324 | * @param ClassMetadataInfo $metadata |
||
325 | */ |
||
326 | private function loadUniques(ClassMetadataInfo $metadata) |
||
336 | |||
337 | /** |
||
338 | * @param ClassMetadataInfo $metadata |
||
339 | * |
||
340 | * @throws \RuntimeException |
||
341 | */ |
||
342 | private function loadOverrides(ClassMetadataInfo $metadata) |
||
360 | } |
||
361 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.