Complex classes like MethodDescriptor 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 MethodDescriptor, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class MethodDescriptor extends DescriptorAbstract implements Interfaces\MethodInterface, Interfaces\VisibilityInterface |
||
18 | { |
||
19 | /** @var ClassDescriptor|InterfaceDescriptor|TraitDescriptor $parent */ |
||
20 | protected $parent; |
||
21 | |||
22 | /** @var bool $abstract */ |
||
23 | protected $abstract = false; |
||
24 | |||
25 | /** @var bool $final */ |
||
26 | protected $final = false; |
||
27 | |||
28 | /** @var bool $static */ |
||
29 | protected $static = false; |
||
30 | |||
31 | /** @var string $visibility */ |
||
32 | protected $visibility = 'public'; |
||
33 | |||
34 | /** @var Collection */ |
||
35 | protected $arguments; |
||
36 | |||
37 | /** |
||
38 | * Initializes the all properties representing a collection with a new Collection object. |
||
39 | */ |
||
40 | public function __construct() |
||
46 | |||
47 | /** |
||
48 | * @param ClassDescriptor|InterfaceDescriptor|TraitDescriptor $parent |
||
49 | */ |
||
50 | public function setParent($parent) |
||
61 | |||
62 | /** |
||
63 | * @return ClassDescriptor|InterfaceDescriptor|TraitDescriptor |
||
64 | */ |
||
65 | public function getParent() |
||
69 | |||
70 | /** |
||
71 | * {@inheritDoc} |
||
72 | */ |
||
73 | public function setAbstract($abstract) |
||
77 | |||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | */ |
||
81 | public function isAbstract() |
||
85 | |||
86 | /** |
||
87 | * {@inheritDoc} |
||
88 | */ |
||
89 | public function setFinal($final) |
||
93 | |||
94 | /** |
||
95 | * {@inheritDoc} |
||
96 | */ |
||
97 | public function isFinal() |
||
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | */ |
||
105 | public function setStatic($static) |
||
109 | |||
110 | /** |
||
111 | * {@inheritDoc} |
||
112 | */ |
||
113 | public function isStatic() |
||
117 | |||
118 | /** |
||
119 | * {@inheritDoc} |
||
120 | */ |
||
121 | public function setVisibility($visibility) |
||
125 | |||
126 | /** |
||
127 | * {@inheritDoc} |
||
128 | */ |
||
129 | public function getVisibility() |
||
133 | |||
134 | /** |
||
135 | * {@inheritDoc} |
||
136 | */ |
||
137 | public function setArguments(Collection $arguments) |
||
144 | |||
145 | /** |
||
146 | * @param string $name |
||
147 | * @param ArgumentDescriptor $argument |
||
148 | */ |
||
149 | public function addArgument($name, ArgumentDescriptor $argument) |
||
154 | |||
155 | /** |
||
156 | * {@inheritDoc} |
||
157 | */ |
||
158 | public function getArguments() |
||
162 | |||
163 | /** |
||
164 | * {@inheritDoc} |
||
165 | */ |
||
166 | public function getResponse() |
||
175 | |||
176 | /** |
||
177 | * Returns the file associated with the parent class, interface or trait. |
||
178 | * |
||
179 | * @return FileDescriptor |
||
180 | */ |
||
181 | public function getFile() |
||
185 | |||
186 | /** |
||
187 | * @return Collection |
||
188 | */ |
||
189 | public function getReturn() |
||
204 | |||
205 | /** |
||
206 | * @return Collection |
||
207 | */ |
||
208 | public function getParam() |
||
223 | |||
224 | /** |
||
225 | * Returns the Method from which this method should inherit its information, if any. |
||
226 | * |
||
227 | * The inheritance scheme for a method is more complicated than for most elements; the following business rules |
||
228 | * apply: |
||
229 | * |
||
230 | * 1. if the parent class/interface extends another class or other interfaces (interfaces have multiple |
||
231 | * inheritance!) then: |
||
232 | * 1. Check each parent class/interface's parent if they have a method with the exact same name |
||
233 | * 2. if a method is found with the same name; return the first one encountered. |
||
234 | * 2. if the parent is a class and implements interfaces, check each interface for a method with the exact same |
||
235 | * name. If such a method is found, return the first hit. |
||
236 | * |
||
237 | * @return MethodDescriptor|null |
||
238 | */ |
||
239 | public function getInheritedElement() |
||
287 | } |
||
288 |