| Conditions | 10 |
| Paths | 24 |
| Total Lines | 30 |
| Code Lines | 15 |
| 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 |
||
| 42 | * @inheritDoc |
||
| 43 | */ |
||
| 44 | public function getName() |
||
| 45 | { |
||
| 46 | return self::NAME; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @inheritDoc |
||
| 51 | */ |
||
| 52 | public function toObjectValue($value, $type, \ReflectionProperty $property, $object) |
||
| 53 | { |
||
| 54 | $className = null; |
||
| 55 | $context = new \ReflectionClass($property->class); |
||
| 56 | |||
| 57 | //use the type as class |
||
| 58 | if (class_exists($type)) { |
||
| 59 | $className = $type; |
||
| 60 | } |
||
| 61 | |||
| 62 | //try to get the class from use statements in the class file |
||
| 63 | if ($className === null) { |
||
| 64 | $classContent = file_get_contents($context->getFileName()); |
||
| 65 | preg_match("/use\s+([\w\\\]+$type);/", $classContent, $matches); |
||
| 66 | if (isset($matches[1]) && class_exists($matches[1])) { |
||
| 67 | $className = $matches[1]; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | //use the same namespace as class container |
||
| 72 | if ($className === null && class_exists($context->getNamespaceName() . "\\" . $type)) { |
||
| 96 | } |