| Conditions | 1 |
| Paths | 1 |
| Total Lines | 125 |
| Code Lines | 61 |
| 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 declare(strict_types=1); |
||
| 76 | public function filterDataProvider() |
||
| 77 | { |
||
| 78 | return [ |
||
| 79 | // no filters, no sort |
||
| 80 | [ |
||
| 81 | [ |
||
| 82 | ], |
||
| 83 | [ |
||
| 84 | ], |
||
| 85 | 'SELECT', |
||
| 86 | ], |
||
| 87 | |||
| 88 | // no filters, only sort |
||
| 89 | [ |
||
| 90 | [ |
||
| 91 | ], |
||
| 92 | [ |
||
| 93 | 't.id' => 'asc', |
||
| 94 | ], |
||
| 95 | 'SELECT ORDER BY t.id ASC', |
||
| 96 | ], |
||
| 97 | |||
| 98 | // single |
||
| 99 | [ |
||
| 100 | [ |
||
| 101 | (new Filter()) |
||
| 102 | ->setField('t.id') |
||
| 103 | ->setType('eq') |
||
| 104 | ->setX('10'), |
||
| 105 | ], |
||
| 106 | [ |
||
| 107 | 't.id' => 'asc', |
||
| 108 | ], |
||
| 109 | 'SELECT WHERE t.id = ?1 ORDER BY t.id ASC', |
||
| 110 | ], |
||
| 111 | |||
| 112 | // combined |
||
| 113 | [ |
||
| 114 | [ |
||
| 115 | (new Filter()) |
||
| 116 | ->setField('t.id') |
||
| 117 | ->setType('eq') |
||
| 118 | ->setX('100'), |
||
| 119 | (new Filter()) |
||
| 120 | ->setField('t.name') |
||
| 121 | ->setType('like') |
||
| 122 | ->setX('john doe'), |
||
| 123 | ], |
||
| 124 | [ |
||
| 125 | 't.id' => 'asc', |
||
| 126 | ], |
||
| 127 | 'SELECT WHERE t.id = ?1 AND t.name LIKE ?2 ORDER BY t.id ASC', |
||
| 128 | ], |
||
| 129 | |||
| 130 | // with OR connector |
||
| 131 | [ |
||
| 132 | [ |
||
| 133 | (new Filter()) |
||
| 134 | ->setField('t.id') |
||
| 135 | ->setType('eq') |
||
| 136 | ->setX('100'), |
||
| 137 | (new Filter()) |
||
| 138 | ->setField('t.name') |
||
| 139 | ->setType('like') |
||
| 140 | ->setX('john doe') |
||
| 141 | ->setConnector('or'), |
||
| 142 | ], |
||
| 143 | [ |
||
| 144 | 't.id' => 'asc', |
||
| 145 | ], |
||
| 146 | 'SELECT WHERE t.id = ?1 OR t.name LIKE ?2 ORDER BY t.id ASC', |
||
| 147 | ], |
||
| 148 | |||
| 149 | // with OR connector |
||
| 150 | [ |
||
| 151 | [ |
||
| 152 | (new Filter()) |
||
| 153 | ->setField('t.id') |
||
| 154 | ->setType('eq') |
||
| 155 | ->setX('100'), |
||
| 156 | (new Filter()) |
||
| 157 | ->setField('t.name') |
||
| 158 | ->setType('like') |
||
| 159 | ->setX('john doe') |
||
| 160 | ->setConnector('or'), |
||
| 161 | ], |
||
| 162 | [ |
||
| 163 | 't.id' => 'asc', |
||
| 164 | ], |
||
| 165 | 'SELECT WHERE t.id = ?1 OR t.name LIKE ?2 ORDER BY t.id ASC', |
||
| 166 | ], |
||
| 167 | |||
| 168 | // having |
||
| 169 | [ |
||
| 170 | [ |
||
| 171 | (new Filter()) |
||
| 172 | ->setField('t.id') |
||
| 173 | ->setType('eq') |
||
| 174 | ->setX('100') |
||
| 175 | ->setHaving(true), |
||
| 176 | ], |
||
| 177 | [ |
||
| 178 | 't.id' => 'asc', |
||
| 179 | ], |
||
| 180 | 'SELECT HAVING t.id = ?1 ORDER BY t.id ASC', |
||
| 181 | ], |
||
| 182 | |||
| 183 | // where AND having |
||
| 184 | [ |
||
| 185 | [ |
||
| 186 | (new Filter()) |
||
| 187 | ->setField('t.id') |
||
| 188 | ->setType('eq') |
||
| 189 | ->setX('100') |
||
| 190 | ->setHaving(true), |
||
| 191 | (new Filter()) |
||
| 192 | ->setField('t.name') |
||
| 193 | ->setType('like') |
||
| 194 | ->setX('john doe') |
||
| 195 | ->setConnector('or'), |
||
| 196 | ], |
||
| 197 | [ |
||
| 198 | 't.id' => 'asc', |
||
| 199 | ], |
||
| 200 | 'SELECT WHERE t.name LIKE ?2 HAVING t.id = ?1 ORDER BY t.id ASC', |
||
| 201 | ], |
||
| 204 | } |