| Conditions | 11 |
| Paths | 11 |
| Total Lines | 43 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 80 | protected function compare($data, UniqueObject $uniqueObject) |
||
| 81 | { |
||
| 82 | static $alreadyTested = []; |
||
| 83 | if (in_array($uniqueObject->getUniqid(), $alreadyTested)) { |
||
| 84 | return; |
||
| 85 | } |
||
| 86 | |||
| 87 | $dataHash = spl_object_hash($data); |
||
| 88 | $dataValues = $this->traversablesValues[$dataHash]; |
||
| 89 | foreach ($this->traversablesValues as $objectHash => $values) { |
||
| 90 | if ( |
||
| 91 | $objectHash === $dataHash |
||
| 92 | || ( |
||
| 93 | count($values['properties']) !== count($dataValues['properties']) |
||
| 94 | || count($values['getters']) !== count($dataValues['getters']) |
||
| 95 | ) |
||
| 96 | ) { |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | |||
| 100 | $compare = true; |
||
| 101 | foreach (['properties', 'getters'] as $type) { |
||
| 102 | foreach ($dataValues[$type] as $name => $value) { |
||
| 103 | if ( |
||
| 104 | array_key_exists($name, $dataValues[$type]) |
||
| 105 | && $this->compareValues($dataValues[$type][$name], $value, $uniqueObject->getStrict()) === false |
||
| 106 | ) { |
||
| 107 | $compare = false; |
||
| 108 | break 2; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | if ($compare) { |
||
| 113 | $this |
||
| 114 | ->context |
||
| 115 | ->buildViolation($uniqueObject->getMessage()) |
||
| 116 | ->atPath($this->context->getPropertyName()) |
||
| 117 | ->addViolation(); |
||
| 118 | $alreadyTested[] = $uniqueObject->getUniqid(); |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 135 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.