| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 98 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 158 | public function read(JsonReadable $reader) |
||
| 159 | { |
||
| 160 | if ($this->skipDeserialize) { |
||
| 161 | $reader->skipValue(); |
||
| 162 | return null; |
||
| 163 | } |
||
| 164 | |||
| 165 | if ($reader->peek() === JsonToken::NULL) { |
||
| 166 | $reader->nextNull(); |
||
| 167 | return null; |
||
| 168 | } |
||
| 169 | |||
| 170 | $object = $this->objectConstructor->construct(); |
||
| 171 | $classExclusionCheck = $this->hasClassDeserializationStrategies |
||
| 172 | && (!$this->requireExclusionCheck || ($this->requireExclusionCheck && $this->classMetadata->getAnnotation(ExclusionCheck::class) !== null)); |
||
| 173 | $propertyExclusionCheck = $this->hasPropertyDeserializationStrategies |
||
| 174 | && (!$this->requireExclusionCheck || ($this->requireExclusionCheck && $this->hasPropertyExclusionCheck)); |
||
| 175 | $exclusionData = $classExclusionCheck || $propertyExclusionCheck |
||
| 176 | ? new DefaultDeserializationExclusionData(clone $object, $reader) |
||
| 177 | : null; |
||
| 178 | |||
| 179 | if ($classExclusionCheck && $exclusionData) { |
||
| 180 | $this->excluder->applyClassDeserializationExclusionData($exclusionData); |
||
| 181 | |||
| 182 | if ($this->excluder->excludeClassByDeserializationStrategy($this->classMetadata)) { |
||
| 183 | $reader->skipValue(); |
||
| 184 | return null; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | if ($propertyExclusionCheck && $exclusionData) { |
||
| 189 | $this->excluder->applyPropertyDeserializationExclusionData($exclusionData); |
||
| 190 | } |
||
| 191 | |||
| 192 | $reader->beginObject(); |
||
| 193 | |||
| 194 | if ($this->classVirtualProperty !== null) { |
||
| 195 | $reader->nextName(); |
||
| 196 | $reader->beginObject(); |
||
| 197 | } |
||
| 198 | |||
| 199 | $usesExisting = $reader->getContext()->usesExistingObject(); |
||
| 200 | |||
| 201 | while ($reader->hasNext()) { |
||
| 202 | $name = $reader->nextName(); |
||
| 203 | $property = $this->propertyCache[$name] ?? $this->propertyCache[$name] = $this->properties->getBySerializedName($name); |
||
| 204 | |||
| 205 | if ($property === null || $property->skipDeserialize()) { |
||
| 206 | $reader->skipValue(); |
||
| 207 | continue; |
||
| 208 | } |
||
| 209 | |||
| 210 | $checkProperty = $this->hasPropertyDeserializationStrategies |
||
| 211 | && (!$this->requireExclusionCheck || ($this->requireExclusionCheck && $property->getAnnotation(ExclusionCheck::class) !== null)); |
||
| 212 | if ($checkProperty && $this->excluder->excludePropertyByDeserializationStrategy($property)) { |
||
| 213 | $reader->skipValue(); |
||
| 214 | continue; |
||
| 215 | } |
||
| 216 | |||
| 217 | $realName = $property->getName(); |
||
| 218 | |||
| 219 | $adapter = $this->adapters[$realName] ?? null; |
||
| 220 | if ($adapter === null) { |
||
| 221 | /** @var JsonAdapter $jsonAdapterAnnotation */ |
||
| 222 | $jsonAdapterAnnotation = $property->getAnnotations()->get(JsonAdapter::class); |
||
| 223 | $adapter = null === $jsonAdapterAnnotation |
||
| 224 | ? $this->typeAdapterProvider->getAdapter($property->getType()) |
||
| 225 | : $this->typeAdapterProvider->getAdapterFromAnnotation( |
||
| 226 | $property->getType(), |
||
| 227 | $jsonAdapterAnnotation |
||
| 228 | ); |
||
| 229 | $this->adapters[$realName] = $adapter; |
||
| 230 | } |
||
| 231 | |||
| 232 | if ($adapter instanceof ObjectConstructorAware && $usesExisting) { |
||
| 233 | try { |
||
| 234 | $nestedObject = $property->get($object); |
||
|
|
|||
| 235 | } /** @noinspection BadExceptionsProcessingInspection */ catch (TypeError $error) { |
||
| 236 | // this may occur when attempting to get a nested object that doesn't exist and |
||
| 237 | // the method return is not nullable. The type error only occurs because we are |
||
| 238 | // may be calling the getter before data exists. |
||
| 239 | $nestedObject = null; |
||
| 240 | } |
||
| 241 | |||
| 242 | if ($nestedObject !== null) { |
||
| 243 | $adapter->setObjectConstructor(new CreateFromInstance($nestedObject)); |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | $property->set($object, $adapter->read($reader)); |
||
| 248 | } |
||
| 249 | $reader->endObject(); |
||
| 250 | |||
| 251 | if ($this->classVirtualProperty !== null) { |
||
| 252 | $reader->endObject(); |
||
| 253 | } |
||
| 254 | |||
| 255 | return $object; |
||
| 256 | } |
||
| 335 |