| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 91 | public function testArrayIsSubsetOfHelper() |
||
| 92 | { |
||
| 93 | $keyValueArray = [ |
||
| 94 | 'input1' => 5, |
||
| 95 | 'input3' => 4, |
||
| 96 | 'input4' => 3, |
||
| 97 | ]; |
||
| 98 | |||
| 99 | $valueArray = [ |
||
| 100 | 'value1', |
||
| 101 | 'value2', |
||
| 102 | 'value4', |
||
| 103 | ]; |
||
| 104 | |||
| 105 | $keyValueSubset = [ |
||
| 106 | 'input1' => 5, |
||
| 107 | 'input3' => 4, |
||
| 108 | ]; |
||
| 109 | |||
| 110 | $keyValueInvalidSubset = [ |
||
| 111 | 'input1' => 4, |
||
| 112 | 'input3' => 4, |
||
| 113 | ]; |
||
| 114 | |||
| 115 | $keyValueInvalidSubset2 = [ |
||
| 116 | 'input2' => 5, |
||
| 117 | ]; |
||
| 118 | |||
| 119 | $valueSubset = [ |
||
| 120 | 'value2', |
||
| 121 | 'value4', |
||
| 122 | ]; |
||
| 123 | |||
| 124 | $valueSubset2 = [ |
||
| 125 | 'value1', |
||
| 126 | ]; |
||
| 127 | |||
| 128 | $invalidValueSubset = [ |
||
| 129 | 'value5', |
||
| 130 | ]; |
||
| 131 | |||
| 132 | $invalidValueSubset2 = [ |
||
| 133 | 'value1', |
||
| 134 | 'value2', |
||
| 135 | 'value3', |
||
| 136 | 'value4', |
||
| 137 | ]; |
||
| 138 | |||
| 139 | $this->assertTrue(array_is_subset_of($keyValueSubset, $keyValueArray)); |
||
| 140 | $this->assertFalse(array_is_subset_of($keyValueInvalidSubset, $keyValueArray)); |
||
| 141 | $this->assertFalse(array_is_subset_of($keyValueInvalidSubset2, $keyValueArray)); |
||
| 142 | |||
| 143 | $this->assertTrue(array_is_subset_of($valueSubset, $valueArray)); |
||
| 144 | $this->assertTrue(array_is_subset_of($valueSubset2, $valueArray)); |
||
| 145 | $this->assertFalse(array_is_subset_of($invalidValueSubset, $valueArray)); |
||
| 146 | $this->assertFalse(array_is_subset_of($invalidValueSubset2, $valueArray)); |
||
| 147 | } |
||
| 191 |