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