Conditions | 11 |
Paths | 8 |
Total Lines | 39 |
Code Lines | 21 |
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 |
||
60 | public function getMetadataFor($value) |
||
61 | { |
||
62 | if (!is_object($value) && !is_string($value)) { |
||
63 | throw new \InvalidArgumentException(sprintf( |
||
64 | "Cannot create metadata for non-objects. Got: %s", |
||
65 | gettype($value) |
||
66 | )); |
||
67 | } |
||
68 | |||
69 | $class = ltrim(((is_object($value)) ? get_class($value) : $value), '\\'); |
||
70 | |||
71 | if (array_key_exists($value, $this->loadedClasses)) { |
||
72 | return $this->loadedClasses[$class]; |
||
73 | } |
||
74 | |||
75 | if ((null !== $this->cache) && (false !== ($this->loadedClasses[$class] = $this->cache->read($class)))) { |
||
76 | return $this->loadedClasses[$class]; |
||
77 | } |
||
78 | |||
79 | if (class_exists($class)) { |
||
80 | throw new \RuntimeException(sprintf( |
||
81 | "The class or interface '%s' doesn't exist", |
||
82 | $class |
||
83 | )); |
||
84 | } |
||
85 | |||
86 | $reflection = new \ReflectionClass($class); |
||
87 | |||
88 | $metadata = $this->loader->loadClassMetadata($reflection); |
||
89 | if (($metadata instanceof ResourceMetadataInterface) && (null !== ($parent = $reflection->getParentClass()))) { |
||
90 | $metadata->mergeMetadata($this->getMetadataFor($parent->getName())); |
||
91 | } |
||
92 | |||
93 | if (null !== $this->cache) { |
||
94 | $this->cache->write($metadata); |
||
|
|||
95 | } |
||
96 | |||
97 | return $this->loadedClasses[$class] = $metadata; |
||
98 | } |
||
99 | |||
117 | } |
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: