| Conditions | 11 |
| Paths | 13 |
| Total Lines | 45 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 = array(); |
||
| 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 | $isSame = true; |
||
| 101 | foreach (array('properties', 'getters') as $type) { |
||
| 102 | foreach ($dataValues[$type] as $name => $value) { |
||
| 103 | if (array_key_exists($name, $values[$type])) { |
||
| 104 | if ($this->compareValues($values[$type][$name], $value, $uniqueObject->getStrict()) === false) { |
||
| 105 | $isSame = false; |
||
| 106 | break 2; |
||
| 107 | } |
||
| 108 | } else { |
||
| 109 | $isSame = false; |
||
| 110 | break 2; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | if ($isSame) { |
||
| 115 | $this |
||
| 116 | ->context |
||
| 117 | ->buildViolation($uniqueObject->getMessage()) |
||
| 118 | ->atPath($this->context->getPropertyName()) |
||
| 119 | ->addViolation(); |
||
| 120 | $alreadyTested[] = $uniqueObject->getUniqid(); |
||
| 121 | break; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 137 |