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 | 80 | public function __construct( |
|
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | 24 | public function denormalize($data, $class, $format = null, array $context = []) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | 24 | public function supportsDenormalization($data, $type, $format = null) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | 24 | public function hasCacheableSupportsMethod(): bool |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @param object $object Access by reference. |
||
| 96 | * @param string $method |
||
| 97 | * @param array $data |
||
| 98 | */ |
||
| 99 | 24 | protected function updateObject(&$object, $method, $data) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * @param object $object Access by reference. |
||
| 116 | * @param string $method |
||
| 117 | * @param PropertyMetadata $propertyMetadata |
||
| 118 | * @param mixed $value |
||
| 119 | */ |
||
| 120 | 22 | protected function updateProperty(&$object, string $method, PropertyMetadata $propertyMetadata, $value) |
|
| 132 | |||
| 133 | 4 | private function updateByReference(&$object, PropertyMetadata $propertyMetadata, $value) |
|
| 149 | |||
| 150 | 2 | protected function updatePropertyObject(&$object, string $method, PropertyMetadata $propertyMetadata, $value) |
|
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $method |
||
| 164 | * @param object $object |
||
| 165 | * @param PropertyMetadata $propertyMetadata |
||
| 166 | * |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | 22 | protected function isUpdateable($object, string $method, PropertyMetadata $propertyMetadata): bool |
|
| 181 | |||
| 182 | 22 | private function isGranted($object, ?Right $right): bool |
|
| 202 | |||
| 203 | private function resolveSubject($entity, $propertyPath) |
||
| 211 | |||
| 212 | 18 | private function convert(?string $type, $value) |
|
| 227 | |||
| 228 | 22 | private function isUpdateableByReference(PropertyMetadata $propertyMetadata, string $method) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
| 249 | */ |
||
| 250 | 76 | public function setAuthorizationChecker(AuthorizationCheckerInterface $authorizationChecker) |
|
| 254 | } |
||
| 255 |