Complex classes like JsonSerializationVisitor 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 JsonSerializationVisitor, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class JsonSerializationVisitor extends GenericSerializationVisitor |
||
|
|
|||
| 26 | { |
||
| 27 | private $options = 0; |
||
| 28 | |||
| 29 | private $navigator; |
||
| 30 | private $root; |
||
| 31 | private $dataStack; |
||
| 32 | private $data; |
||
| 33 | |||
| 34 | 146 | public function setNavigator(GraphNavigator $navigator) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @return GraphNavigator |
||
| 43 | */ |
||
| 44 | public function getNavigator() |
||
| 48 | |||
| 49 | 28 | public function visitNull($data, array $type, Context $context) |
|
| 53 | |||
| 54 | 90 | public function visitString($data, array $type, Context $context) |
|
| 62 | |||
| 63 | 9 | public function visitBoolean($data, array $type, Context $context) |
|
| 71 | |||
| 72 | 26 | public function visitInteger($data, array $type, Context $context) |
|
| 80 | |||
| 81 | 13 | public function visitDouble($data, array $type, Context $context) |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @param array $data |
||
| 92 | * @param array $type |
||
| 93 | * @param Context $context |
||
| 94 | * @return mixed |
||
| 95 | */ |
||
| 96 | 71 | public function visitArray($data, array $type, Context $context) |
|
| 128 | |||
| 129 | 83 | public function startVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context) |
|
| 138 | |||
| 139 | 82 | public function endVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context) |
|
| 155 | |||
| 156 | 79 | public function visitProperty(PropertyMetadata $metadata, $data, Context $context) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Allows you to add additional data to the current object/root element. |
||
| 183 | * @deprecated use setData instead |
||
| 184 | * @param string $key |
||
| 185 | * @param integer|float|boolean|string|array|null $value This value must either be a regular scalar, or an array. |
||
| 186 | * It must not contain any objects anymore. |
||
| 187 | */ |
||
| 188 | 1 | public function addData($key, $value) |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Checks if some data key exists. |
||
| 199 | * |
||
| 200 | * @param string $key |
||
| 201 | * @return boolean |
||
| 202 | */ |
||
| 203 | 1 | public function hasData($key) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * Allows you to replace existing data on the current object/root element. |
||
| 210 | * |
||
| 211 | * @param string $key |
||
| 212 | * @param integer|float|boolean|string|array|null $value This value must either be a regular scalar, or an array. |
||
| 213 | * It must not contain any objects anymore. |
||
| 214 | */ |
||
| 215 | 1 | public function setData($key, $value) |
|
| 219 | |||
| 220 | 147 | public function getRoot() |
|
| 224 | |||
| 225 | /** |
||
| 226 | * @param array|\ArrayObject $data the passed data must be understood by whatever encoding function is applied later. |
||
| 227 | */ |
||
| 228 | 8 | public function setRoot($data) |
|
| 232 | |||
| 233 | |||
| 234 | 135 | public function getResult() |
|
| 249 | |||
| 250 | public function getOptions() |
||
| 254 | |||
| 255 | public function setOptions($options) |
||
| 259 | } |
||
| 260 |
This class, trait or interface has been deprecated.