Complex classes like RestDenormalizer 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 RestDenormalizer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class RestDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface |
||
22 | { |
||
23 | const DDR_REST_METHOD = 'ddrRestMethod'; |
||
24 | const DDR_REST_ENTITY = 'ddrRestEntity'; |
||
25 | |||
26 | /** |
||
27 | * @var RestMetadataFactory |
||
28 | */ |
||
29 | private $metadataFactory; |
||
30 | |||
31 | /** |
||
32 | * @var PropertyAccessorInterface |
||
33 | */ |
||
34 | private $propertyAccessor; |
||
35 | |||
36 | /** |
||
37 | * @var AuthorizationCheckerInterface|null |
||
38 | */ |
||
39 | private $authorizationChecker; |
||
40 | |||
41 | /** |
||
42 | * @var EntityManagerInterface |
||
43 | */ |
||
44 | private $entityManager; |
||
45 | |||
46 | 82 | public function __construct( |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 26 | public function denormalize($data, $class, $format = null, array $context = []) |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 26 | public function supportsDenormalization($data, $type, $format = null) |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 26 | public function hasCacheableSupportsMethod(): bool |
|
96 | |||
97 | /** |
||
98 | * @param object $object Access by reference. |
||
99 | * @param string $method |
||
100 | * @param array $data |
||
101 | */ |
||
102 | 26 | protected function updateObject(&$object, $method, $data) |
|
116 | |||
117 | /** |
||
118 | * @param object $object Access by reference. |
||
119 | * @param string $method |
||
120 | * @param PropertyMetadata $propertyMetadata |
||
121 | * @param mixed $value |
||
122 | */ |
||
123 | 26 | protected function updateProperty(&$object, string $method, PropertyMetadata $propertyMetadata, $value) |
|
135 | |||
136 | 4 | private function updateByReference(&$object, PropertyMetadata $propertyMetadata, $value) |
|
152 | |||
153 | 2 | protected function updatePropertyObject(&$object, string $method, PropertyMetadata $propertyMetadata, $value) |
|
164 | |||
165 | /** |
||
166 | * @param string $method |
||
167 | * @param object $object |
||
168 | * @param PropertyMetadata $propertyMetadata |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | 26 | protected function isUpdateable($object, string $method, PropertyMetadata $propertyMetadata): bool |
|
184 | |||
185 | 26 | private function isGranted($object, ?Right $right): bool |
|
205 | |||
206 | private function resolveSubject($entity, $propertyPath) |
||
214 | |||
215 | 22 | private function convert(?string $type, $value) |
|
230 | |||
231 | 26 | private function isUpdateableByReference(PropertyMetadata $propertyMetadata, string $method) |
|
249 | |||
250 | /** |
||
251 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
252 | */ |
||
253 | 78 | public function setAuthorizationChecker(AuthorizationCheckerInterface $authorizationChecker) |
|
257 | } |
||
258 |