| Conditions | 10 |
| Paths | 44 |
| Total Lines | 40 |
| Code Lines | 22 |
| 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 |
||
| 44 | public function loadClassMetadata(ClassMetadataInterface $classMetadata) |
||
| 45 | { |
||
| 46 | $reflectionClass = $classMetadata->getReflectionClass(); |
||
| 47 | $className = $reflectionClass->name; |
||
| 48 | $loaded = false; |
||
| 49 | |||
| 50 | // Load class annotations |
||
| 51 | foreach ($this->reader->getClassAnnotations($reflectionClass) as $classAnnotation) { |
||
| 52 | if ($classAnnotation instanceof ClassAnnotationInterface) { |
||
| 53 | if (null === $classAnnotation->getName()) { |
||
| 54 | $classAnnotation->setName($reflectionClass->getShortName()); |
||
| 55 | } |
||
| 56 | |||
| 57 | $classMetadata->addClassAnnotation($classAnnotation); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | // Load class attributes annotations |
||
| 62 | $attributesMetadata = $classMetadata->getAttributesMetadata(); |
||
| 63 | foreach ($reflectionClass->getProperties() as $property) { |
||
| 64 | if (!isset($attributesMetadata[$property->name])) { |
||
| 65 | $attributesMetadata[$property->name] = new AttributeMetadata($property->name); |
||
| 66 | $classMetadata->addAttributeMetadata($attributesMetadata[$property->name]); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($property->getDeclaringClass()->name === $className) { |
||
| 70 | foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { |
||
| 71 | if ($annotation instanceof Attribute) { |
||
| 72 | $attributesMetadata[$property->name]->setAttribute($annotation); |
||
|
|
|||
| 73 | } elseif ($annotation instanceof Relationship) { |
||
| 74 | $attributesMetadata[$property->name]->setRelationship($annotation); |
||
| 75 | } |
||
| 76 | |||
| 77 | $loaded = true; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return $loaded; |
||
| 83 | } |
||
| 84 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: