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 | 141 | public function setNavigator(GraphNavigator $navigator) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @return GraphNavigator |
||
| 43 | */ |
||
| 44 | public function getNavigator() |
||
| 48 | |||
| 49 | 26 | public function visitNull($data, array $type, Context $context) |
|
| 53 | |||
| 54 | 86 | 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 | 69 | public function visitArray($data, array $type, Context $context) |
|
| 128 | |||
| 129 | 78 | public function startVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context) |
|
| 138 | |||
| 139 | 77 | public function endVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context) |
|
| 155 | |||
| 156 | 74 | public function visitProperty(PropertyMetadata $metadata, $data, Context $context) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Allows you to add additional data to the current object/root element. |
||
| 178 | * @deprecated use setData instead |
||
| 179 | * @param string $key |
||
| 180 | * @param integer|float|boolean|string|array|null $value This value must either be a regular scalar, or an array. |
||
| 181 | * It must not contain any objects anymore. |
||
| 182 | */ |
||
| 183 | 1 | public function addData($key, $value) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * Checks if some data key exists. |
||
| 194 | * |
||
| 195 | * @param string $key |
||
| 196 | * @return boolean |
||
| 197 | */ |
||
| 198 | 1 | public function hasData($key) |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Allows you to replace existing data on the current object/root element. |
||
| 205 | * |
||
| 206 | * @param string $key |
||
| 207 | * @param integer|float|boolean|string|array|null $value This value must either be a regular scalar, or an array. |
||
| 208 | * It must not contain any objects anymore. |
||
| 209 | */ |
||
| 210 | 1 | public function setData($key, $value) |
|
| 214 | |||
| 215 | 141 | public function getRoot() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * @param array|\ArrayObject $data the passed data must be understood by whatever encoding function is applied later. |
||
| 222 | */ |
||
| 223 | 7 | public function setRoot($data) |
|
| 227 | |||
| 228 | |||
| 229 | 130 | public function getResult() |
|
| 244 | |||
| 245 | public function getOptions() |
||
| 249 | |||
| 250 | public function setOptions($options) |
||
| 254 | } |
||
| 255 |
This class, trait or interface has been deprecated.