Complex classes like ScalarBeanPropertyDescriptor 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 ScalarBeanPropertyDescriptor, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class ScalarBeanPropertyDescriptor extends AbstractBeanPropertyDescriptor |
||
20 | { |
||
21 | /** |
||
22 | * @var Column |
||
23 | */ |
||
24 | private $column; |
||
25 | |||
26 | /** |
||
27 | * @var Annotations |
||
28 | */ |
||
29 | private $annotations; |
||
30 | |||
31 | /** |
||
32 | * ScalarBeanPropertyDescriptor constructor. |
||
33 | * @param Table $table |
||
34 | * @param Column $column |
||
35 | * @param NamingStrategyInterface $namingStrategy |
||
36 | */ |
||
37 | public function __construct(Table $table, Column $column, NamingStrategyInterface $namingStrategy) |
||
43 | |||
44 | /** |
||
45 | * Returns the foreign-key the column is part of, if any. null otherwise. |
||
46 | * |
||
47 | * @return ForeignKeyConstraint|null |
||
48 | */ |
||
49 | public function getForeignKey() |
||
53 | |||
54 | /** |
||
55 | * Returns the param annotation for this property (useful for constructor). |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getParamAnnotation() |
||
67 | |||
68 | /** |
||
69 | * Returns the name of the class linked to this property or null if this is not a foreign key. |
||
70 | * |
||
71 | * @return null|string |
||
72 | */ |
||
73 | public function getClassName(): ?string |
||
77 | |||
78 | /** |
||
79 | * Returns the PHP type for the property (it can be a scalar like int, bool, or class names, like \DateTimeInterface, App\Bean\User....) |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getPhpType(): string |
||
88 | |||
89 | /** |
||
90 | * Returns true if the property is compulsory (and therefore should be fetched in the constructor). |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function isCompulsory() |
||
98 | |||
99 | private function isAutoincrement() : bool |
||
103 | |||
104 | private function hasUuidAnnotation(): bool |
||
108 | |||
109 | private function getUuidAnnotation(): ?Annotation |
||
113 | |||
114 | private function getAutoincrementAnnotation(): ?Annotation |
||
118 | |||
119 | private function getAnnotations(): Annotations |
||
131 | |||
132 | /** |
||
133 | * Returns true if the property has a default value (or if the @UUID annotation is set for the column) |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | public function hasDefault() |
||
142 | |||
143 | /** |
||
144 | * Returns the code that assigns a value to its default value. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function assignToDefaultCode() |
||
181 | |||
182 | private function getUuidCode(Annotation $uuidAnnotation): string |
||
195 | |||
196 | /** |
||
197 | * Returns true if the property is the primary key. |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function isPrimaryKey() |
||
205 | |||
206 | /** |
||
207 | * Returns the PHP code for getters and setters. |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | public function getGetterSetterCode() |
||
267 | |||
268 | /** |
||
269 | * Returns the part of code useful when doing json serialization. |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | public function getJsonSerializeCode() |
||
283 | |||
284 | /** |
||
285 | * Returns the column name. |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | public function getColumnName() |
||
293 | |||
294 | /** |
||
295 | * The code to past in the __clone method. |
||
296 | * @return null|string |
||
297 | */ |
||
298 | public function getCloneRule(): ?string |
||
306 | } |
||
307 |