| Conditions | 18 |
| Paths | 31 |
| Total Lines | 63 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 85 | public function read($value, ReaderContext $context) |
||
| 86 | { |
||
| 87 | if ($this->skipDeserialize || $value === null) { |
||
| 88 | return null; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($this->classVirtualProperty !== null) { |
||
| 92 | $value = array_shift($value); |
||
| 93 | } |
||
| 94 | |||
| 95 | $object = $this->objectConstructor->construct(); |
||
| 96 | $usesExisting = $context->usesExistingObject; |
||
| 97 | $enableScalarAdapters = $context->enableScalarAdapters; |
||
| 98 | $typeAdapterProvider = $context->typeAdapterProvider; |
||
| 99 | $excluder = $context->getExcluder(); |
||
| 100 | $payload = $context->getPayload(); |
||
| 101 | |||
| 102 | if ($this->classMetadata->hasExclusions && $excluder->skipClassDeserializeByStrategy($this->classMetadata, $object, $payload)) { |
||
|
|
|||
| 103 | return null; |
||
| 104 | } |
||
| 105 | |||
| 106 | foreach ($value as $name => $item) { |
||
| 107 | $property = $this->properties[$name] ?? null; |
||
| 108 | |||
| 109 | if ($property === null || $property->skipDeserialize) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($property->hasExclusions && $excluder->skipPropertyDeserializeByStrategy($property, $object, $payload)) { |
||
| 114 | continue; |
||
| 115 | } |
||
| 116 | |||
| 117 | $adapter = $property->adapter; |
||
| 118 | |||
| 119 | if ($adapter === null) { |
||
| 120 | // disabled scalar adapters |
||
| 121 | if ($property->isScalar && !$enableScalarAdapters) { |
||
| 122 | $property->setterStrategy->set($object, $item); |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | $adapter = $property->adapter = $typeAdapterProvider->getAdapterFromProperty($property); |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($usesExisting && $adapter instanceof ObjectConstructorAware) { |
||
| 130 | try { |
||
| 131 | $nestedObject = $property->getterStrategy->get($object); |
||
| 132 | } /** @noinspection BadExceptionsProcessingInspection */ catch (TypeError $error) { |
||
| 133 | // this may occur when attempting to get a nested object that doesn't exist and |
||
| 134 | // the method return is not nullable. The type error only occurs because we are |
||
| 135 | // may be calling the getter before data exists. |
||
| 136 | $nestedObject = null; |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($nestedObject !== null) { |
||
| 140 | $adapter->setObjectConstructor(new CreateFromInstance($nestedObject)); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | $property->setterStrategy->set($object, $adapter->read($item, $context)); |
||
| 145 | } |
||
| 146 | |||
| 147 | return $object; |
||
| 148 | } |
||
| 216 |