| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 104 | public function testGetRelatedByField(): void |
||
| 105 | { |
||
| 106 | $this->Reports->id = 1; |
||
| 107 | $result = $this->Reports->getRelatedByField('php_version'); |
||
| 108 | $this->assertInstanceOf(Query::class, $result); |
||
| 109 | $result = $result->enableHydration(false)->toArray(); |
||
| 110 | $expected = [ |
||
| 111 | [ |
||
| 112 | 'php_version' => '5.5', |
||
| 113 | 'count' => '1', |
||
| 114 | ], |
||
| 115 | ]; |
||
| 116 | $this->assertEquals($expected, $result); |
||
| 117 | $this->Reports->id = 4; |
||
| 118 | $result = $this->Reports->getRelatedByField('php_version', 1); |
||
| 119 | $this->assertInstanceOf(Query::class, $result); |
||
| 120 | $result = $result->enableHydration(false)->toArray(); |
||
| 121 | $expected = [ |
||
| 122 | [ |
||
| 123 | 'php_version' => '5.3', |
||
| 124 | 'count' => '2', |
||
| 125 | ], |
||
| 126 | ]; |
||
| 127 | $this->assertEquals($expected, $result); |
||
| 128 | $this->Reports->id = 1; |
||
| 129 | $result = $this->Reports->getRelatedByField( |
||
| 130 | 'php_version', |
||
| 131 | 10, |
||
| 132 | false, |
||
| 133 | true, |
||
| 134 | '2013-08-29 18:10:01' |
||
| 135 | ); |
||
| 136 | $this->assertInstanceOf(Query::class, $result); |
||
| 137 | $result = $result->enableHydration(false)->toArray(); |
||
| 138 | $expected = [ |
||
| 139 | [ |
||
| 140 | 'php_version' => '5.5', |
||
| 141 | 'count' => '1', |
||
| 142 | ], |
||
| 143 | ]; |
||
| 144 | $this->assertEquals($expected, $result); |
||
| 145 | |||
| 146 | $result = $this->Reports->getRelatedByField('php_version', 10, false, false); |
||
| 147 | $this->assertInstanceOf(Query::class, $result); |
||
| 148 | $result = $result->enableHydration(false)->toArray(); |
||
| 149 | $expected = [ |
||
| 150 | [ |
||
| 151 | 'php_version' => '5.5', |
||
| 152 | 'count' => '1', |
||
| 153 | ], |
||
| 154 | [ |
||
| 155 | 'php_version' => '5.3', |
||
| 156 | 'count' => '4', |
||
| 157 | ], |
||
| 158 | ]; |
||
| 159 | $this->assertEquals($expected, $result); |
||
| 160 | $result = $this->Reports->getRelatedByField('php_version', 10, true); |
||
| 161 | $this->assertInstanceOf(ResultSet::class, $result[0]); |
||
| 162 | $result[0] = $result[0]->toArray(); |
||
| 163 | $result[0][0] = $result[0][0]->toArray(); |
||
| 164 | $expected = [ |
||
| 165 | [ |
||
| 166 | [ |
||
| 167 | 'php_version' => '5.5', |
||
| 168 | 'count' => '1', |
||
| 169 | ], |
||
| 170 | ], |
||
| 171 | 1, |
||
| 172 | ]; |
||
| 173 | $this->assertEquals($expected, $result); |
||
| 174 | } |
||
| 176 |