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