Complex classes like RestRequestParser 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 RestRequestParser, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class RestRequestParser implements RestRequestParserInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var MetadataFactory |
||
| 23 | */ |
||
| 24 | private $metadataFactory; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var PropertyAccessor |
||
| 28 | */ |
||
| 29 | private $propertyAccessor; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var AuthorizationCheckerInterface|null |
||
| 33 | */ |
||
| 34 | private $authorizationChecker; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var EntityManagerInterface |
||
| 38 | */ |
||
| 39 | private $entityManager; |
||
| 40 | |||
| 41 | public function __construct( |
||
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | public function parseEntity(Request $request, $entityClass, $entity = null) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public function getRequestContent(Request $request) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param object $object Access by reference. |
||
| 90 | * @param string $method |
||
| 91 | * @param array $data |
||
| 92 | */ |
||
| 93 | protected function updateObject(&$object, $method, $data) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param object $object Access by reference. |
||
| 110 | * @param string $method |
||
| 111 | * @param PropertyMetadata $propertyMetadata |
||
| 112 | * @param mixed $value |
||
| 113 | */ |
||
| 114 | protected function updateProperty(&$object, string $method, PropertyMetadata $propertyMetadata, $value) |
||
| 126 | |||
| 127 | private function updateByReference(&$object, PropertyMetadata $propertyMetadata, $value) |
||
| 143 | |||
| 144 | protected function updatePropertyObject(&$object, string $method, PropertyMetadata $propertyMetadata, $value) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param string $method |
||
| 158 | * @param object $object |
||
| 159 | * @param PropertyMetadata $propertyMetadata |
||
| 160 | * |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | protected function isUpdateable($object, string $method, PropertyMetadata $propertyMetadata): bool |
||
| 175 | |||
| 176 | private function isGranted($object, ?Right $right): bool |
||
| 196 | |||
| 197 | private function resolveSubject($entity, $propertyPath) |
||
| 205 | |||
| 206 | private function convert(?string $type, $value) |
||
| 221 | |||
| 222 | private function isUpdateableByReference(PropertyMetadata $propertyMetadata, string $method) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
| 243 | */ |
||
| 244 | public function setAuthorizationChecker(AuthorizationCheckerInterface $authorizationChecker) |
||
| 248 | } |
||
| 249 |