Complex classes like ReadOnlyHydrator 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 ReadOnlyHydrator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class ReadOnlyHydrator extends \ComposerOverloadClass\steevanb\DoctrineReadOnlyHydrator\Hydrator\ReadOnlyHydrator |
||
12 | { |
||
13 | use OverloadedHydratorTrait; |
||
14 | |||
15 | /** |
||
16 | * @param ClassMetadata $classMetaData |
||
17 | * @param array $data |
||
18 | * @return mixed |
||
19 | * @throws \Exception |
||
20 | */ |
||
21 | protected function createEntity(ClassMetadata $classMetaData, array $data) |
||
29 | } |
||
30 |