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