Complex classes like InMemoryDiscovery 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 InMemoryDiscovery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class InMemoryDiscovery extends AbstractEditableDiscovery |
||
30 | { |
||
31 | /** |
||
32 | * @var BindingType[] |
||
33 | */ |
||
34 | private $types = array(); |
||
35 | |||
36 | /** |
||
37 | * @var Binding[][] |
||
38 | */ |
||
39 | private $bindingsByTypeName = array(); |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | 27 | public function addBindingType(BindingType $type) |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 4 | public function removeBindingType($typeName) |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 2 | public function removeBindingTypes() |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 5 | public function hasBindingType($typeName) |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 21 | public function getBindingType($typeName) |
|
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function hasBindingTypes() |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | 3 | public function getBindingTypes() |
|
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | 16 | public function addBinding(Binding $binding) |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 10 | public function findBindings($typeName, Expression $expr = null) |
|
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | 15 | public function getBindings() |
|
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | 2 | protected function removeAllBindings() |
|
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | 1 | protected function removeBindingsThatMatch(Expression $expr) |
|
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | 6 | protected function removeBindingsWithTypeName($typeName) |
|
207 | |||
208 | /** |
||
209 | * {@inheritdoc} |
||
210 | */ |
||
211 | 3 | protected function removeBindingsWithTypeNameThatMatch($typeName, Expression $expr) |
|
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | 2 | protected function hasAnyBinding() |
|
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | protected function hasBindingsThatMatch(Expression $expr) |
||
251 | |||
252 | /** |
||
253 | * {@inheritdoc} |
||
254 | */ |
||
255 | 2 | protected function hasBindingsWithTypeName($typeName) |
|
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | 2 | protected function hasBindingsWithTypeNameThatMatch($typeName, Expression $expr) |
|
277 | } |
||
278 |