| Conditions | 5 |
| Paths | 5 |
| Total Lines | 53 |
| Code Lines | 28 |
| 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 |
||
| 48 | protected function matches($other): bool |
||
| 49 | { |
||
| 50 | // Add missing members with false value |
||
| 51 | $cleanExpected = array_merge( |
||
| 52 | array_fill_keys(static::allowedMembers(), false), |
||
| 53 | $this->expected |
||
| 54 | ); |
||
| 55 | asort($cleanExpected); |
||
| 56 | |||
| 57 | // Extract only pagination members from incoming json |
||
| 58 | $cleanJson = array_intersect_key($other, array_flip($this->allowedMembers())); |
||
| 59 | asort($cleanJson); |
||
| 60 | |||
| 61 | // Search for unexpected members |
||
| 62 | $notExpectedMembers = array_keys( |
||
| 63 | array_filter( |
||
| 64 | $cleanExpected, |
||
| 65 | function ($value) { |
||
| 66 | return $value === false; |
||
| 67 | } |
||
| 68 | ) |
||
| 69 | ); |
||
| 70 | if (count(array_intersect_key($cleanJson, array_flip($notExpectedMembers))) !== 0) { |
||
| 71 | return false; |
||
| 72 | } |
||
| 73 | |||
| 74 | // Extracts expected members |
||
| 75 | $expectedMembers = array_filter( |
||
| 76 | $cleanExpected, |
||
| 77 | function ($value) { |
||
| 78 | return $value !== false; |
||
| 79 | } |
||
| 80 | ); |
||
| 81 | if (array_keys($expectedMembers) != array_keys($cleanJson)) { |
||
| 82 | return false; |
||
| 83 | } |
||
| 84 | |||
| 85 | // Extracts members whose value have to be tested |
||
| 86 | $expectedValues = array_filter( |
||
| 87 | $expectedMembers, |
||
| 88 | function ($value) { |
||
| 89 | return $value !== true; |
||
| 90 | } |
||
| 91 | ); |
||
| 92 | |||
| 93 | foreach ($expectedValues as $name => $expectedLink) { |
||
| 94 | $constraint = new LinkEqualsConstraint($expectedLink); |
||
| 95 | if ($constraint->check($cleanJson[$name]) === false) { |
||
| 96 | return false; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | return true; |
||
| 101 | } |
||
| 118 |