| Conditions | 11 |
| Paths | 19 |
| Total Lines | 42 |
| Code Lines | 26 |
| 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 |
||
| 27 | public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata |
||
| 28 | { |
||
| 29 | $classMetadata = $this->delegate->loadMetadataForClass($class); |
||
| 30 | \assert($classMetadata instanceof SerializerClassMetadata); |
||
| 31 | |||
| 32 | if (null === $classMetadata) { |
||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | foreach ($classMetadata->propertyMetadata as $key => $propertyMetadata) { |
||
| 37 | \assert($propertyMetadata instanceof PropertyMetadata); |
||
| 38 | if (null !== $propertyMetadata->hasDefault) { |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | |||
| 42 | try { |
||
| 43 | $propertyReflection = $this->getPropertyReflection($propertyMetadata); |
||
| 44 | $propertyMetadata->hasDefault = false; |
||
| 45 | if ($propertyReflection->hasDefaultValue() && $propertyReflection->hasType()) { |
||
| 46 | $propertyMetadata->hasDefault = true; |
||
| 47 | $propertyMetadata->defaultValue = $propertyReflection->getDefaultValue(); |
||
| 48 | } elseif ($propertyReflection->isPromoted()) { |
||
| 49 | // need to get the parameter in the constructor to check for default values |
||
| 50 | $classReflection = $this->getClassReflection($propertyMetadata); |
||
| 51 | $params = $classReflection->getConstructor()->getParameters(); |
||
| 52 | foreach ($params as $parameter) { |
||
| 53 | if ($parameter->getName() === $propertyMetadata->name) { |
||
| 54 | if ($parameter->isDefaultValueAvailable()) { |
||
| 55 | $propertyMetadata->hasDefault = true; |
||
| 56 | $propertyMetadata->defaultValue = $parameter->getDefaultValue(); |
||
| 57 | } |
||
| 58 | |||
| 59 | break; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } catch (ReflectionException $e) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | return $classMetadata; |
||
| 69 | } |
||
| 81 |