| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 44 |
| 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 |
||
| 149 | public function testToStringComplexWithUnionAndExcept() |
||
| 150 | { |
||
| 151 | $columnQuery = $this->getSut('quix') |
||
| 152 | ->columns('b') |
||
| 153 | ->where(new Expr('id = ?', [7])); |
||
| 154 | |||
| 155 | $columnExpr = new Expr('NOW()'); |
||
| 156 | |||
| 157 | $unionQuery = $this->getSut('baz') |
||
| 158 | ->columns('b', 'f'); |
||
| 159 | |||
| 160 | $exceptQuery = $this->getSut('sec') |
||
| 161 | ->columns('v', 'w'); |
||
| 162 | |||
| 163 | $sql = (string)$this->getSut('foo', 'bar') |
||
| 164 | ->modifier('DISTINCT') |
||
| 165 | ->columns('COUNT(DISTINCT baz) AS baz_count', new Column($columnQuery, 'quix_b')) |
||
| 166 | ->columns(new Column($columnExpr, 'now')) |
||
| 167 | ->columns(new Column('bar.id', 'bar_id')) |
||
| 168 | ->innerJoin(new Table('quix', 'q'), 'foo.id = q.foo_id') |
||
| 169 | ->where('foo.bar = "foo-bar"', new Expr('bar.foo = ?', ['bar-foo'])) |
||
| 170 | ->groupBy('q.foo_id', new Expr('q.bar.id')) |
||
| 171 | ->having('baz_count > 0') |
||
| 172 | ->orderBy('baz_count', 'ASC') |
||
| 173 | ->lock(new Lock(Lock::FOR_KEY_SHARE)) |
||
| 174 | ->limit(10) |
||
| 175 | ->offset(20) |
||
| 176 | ->union($unionQuery) |
||
| 177 | ->except($exceptQuery) |
||
| 178 | ->outerLimit(100); |
||
| 179 | |||
| 180 | $parts = []; |
||
| 181 | $parts[] = '(SELECT DISTINCT COUNT(DISTINCT baz) AS baz_count, (SELECT b FROM quix WHERE id = ?) AS quix_b, NOW() AS now, bar.id AS bar_id'; // nolint |
||
| 182 | $parts[] = 'FROM foo, bar'; |
||
| 183 | $parts[] = 'INNER JOIN quix AS q ON foo.id = q.foo_id'; |
||
| 184 | $parts[] = 'WHERE foo.bar = "foo-bar" AND bar.foo = ?'; |
||
| 185 | $parts[] = 'GROUP BY q.foo_id, q.bar.id'; |
||
| 186 | $parts[] = 'HAVING baz_count > 0'; |
||
| 187 | $parts[] = 'ORDER BY baz_count ASC'; |
||
| 188 | $parts[] = 'OFFSET 20 ROWS'; |
||
| 189 | $parts[] = 'FETCH FIRST 10 ROWS ONLY'; |
||
| 190 | $parts[] = 'FOR KEY SHARE'; |
||
| 191 | $parts[] = 'UNION'; |
||
| 192 | $parts[] = 'SELECT b, f'; |
||
| 193 | $parts[] = 'FROM baz'; |
||
| 194 | $parts[] = 'EXCEPT'; |
||
| 195 | $parts[] = 'SELECT v, w'; |
||
| 196 | $parts[] = 'FROM sec)'; |
||
| 197 | $parts[] = 'LIMIT 100'; |
||
| 198 | |||
| 199 | $expectedSql = implode(PHP_EOL, $parts); |
||
| 200 | |||
| 201 | $this->assertSame($expectedSql, $sql); |
||
| 202 | } |
||
| 214 |