| Conditions | 1 |
| Paths | 1 |
| Total Lines | 192 |
| Code Lines | 123 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 119 | public function getUpsert(ConnectionInterface $db): array |
||
| 120 | { |
||
| 121 | return [ |
||
| 122 | 'regular values' => [ |
||
| 123 | [ |
||
| 124 | 'params' => [ |
||
| 125 | 'T_upsert', |
||
| 126 | [ |
||
| 127 | 'email' => '[email protected]', |
||
| 128 | 'address' => 'Earth', |
||
| 129 | 'status' => '3', |
||
| 130 | ], |
||
| 131 | ], |
||
| 132 | ], |
||
| 133 | [ |
||
| 134 | 'params' => [ |
||
| 135 | 'T_upsert', |
||
| 136 | [ |
||
| 137 | 'email' => '[email protected]', |
||
| 138 | 'address' => 'Universe', |
||
| 139 | 'status' => '1', |
||
| 140 | ], |
||
| 141 | ], |
||
| 142 | ], |
||
| 143 | ], |
||
| 144 | 'regular values with update part' => [ |
||
| 145 | [ |
||
| 146 | 'params' => [ |
||
| 147 | 'T_upsert', |
||
| 148 | [ |
||
| 149 | 'email' => '[email protected]', |
||
| 150 | 'address' => 'Earth', |
||
| 151 | 'status' => '3', |
||
| 152 | ], |
||
| 153 | [ |
||
| 154 | 'address' => 'Moon', |
||
| 155 | 'status' => 2, |
||
| 156 | ], |
||
| 157 | ], |
||
| 158 | ], |
||
| 159 | [ |
||
| 160 | 'params' => [ |
||
| 161 | 'T_upsert', |
||
| 162 | [ |
||
| 163 | 'email' => '[email protected]', |
||
| 164 | 'address' => 'Universe', |
||
| 165 | 'status' => 1, |
||
| 166 | ], |
||
| 167 | [ |
||
| 168 | 'address' => 'Moon', |
||
| 169 | 'status' => 2, |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | 'expected' => [ |
||
| 173 | 'email' => '[email protected]', |
||
| 174 | 'address' => 'Moon', |
||
| 175 | 'status' => '2', |
||
| 176 | ], |
||
| 177 | ], |
||
| 178 | ], |
||
| 179 | 'regular values without update part' => [ |
||
| 180 | [ |
||
| 181 | 'params' => [ |
||
| 182 | 'T_upsert', |
||
| 183 | [ |
||
| 184 | 'email' => '[email protected]', |
||
| 185 | 'address' => 'Earth', |
||
| 186 | 'status' => '3', |
||
| 187 | ], |
||
| 188 | false, |
||
| 189 | ], |
||
| 190 | ], |
||
| 191 | [ |
||
| 192 | 'params' => [ |
||
| 193 | 'T_upsert', |
||
| 194 | [ |
||
| 195 | 'email' => '[email protected]', |
||
| 196 | 'address' => 'Universe', |
||
| 197 | 'status' => 1, |
||
| 198 | ], |
||
| 199 | false, |
||
| 200 | ], |
||
| 201 | 'expected' => [ |
||
| 202 | 'email' => '[email protected]', |
||
| 203 | 'address' => 'Earth', |
||
| 204 | 'status' => '3', |
||
| 205 | ], |
||
| 206 | ], |
||
| 207 | ], |
||
| 208 | 'query' => [ |
||
| 209 | [ |
||
| 210 | 'params' => [ |
||
| 211 | 'T_upsert', |
||
| 212 | (new Query($db)) |
||
| 213 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 214 | ->from('customer') |
||
| 215 | ->where(['name' => 'user1']) |
||
| 216 | ->limit(1), |
||
| 217 | ], |
||
| 218 | 'expected' => [ |
||
| 219 | 'email' => '[email protected]', |
||
| 220 | 'address' => 'address1', |
||
| 221 | 'status' => '1', |
||
| 222 | ], |
||
| 223 | ], |
||
| 224 | [ |
||
| 225 | 'params' => [ |
||
| 226 | 'T_upsert', |
||
| 227 | (new Query($db)) |
||
| 228 | ->select(['email', 'address', 'status' => new Expression('2')]) |
||
| 229 | ->from('customer') |
||
| 230 | ->where(['name' => 'user1']) |
||
| 231 | ->limit(1), |
||
| 232 | ], |
||
| 233 | 'expected' => [ |
||
| 234 | 'email' => '[email protected]', |
||
| 235 | 'address' => 'address1', |
||
| 236 | 'status' => '2', |
||
| 237 | ], |
||
| 238 | ], |
||
| 239 | ], |
||
| 240 | 'query with update part' => [ |
||
| 241 | [ |
||
| 242 | 'params' => [ |
||
| 243 | 'T_upsert', |
||
| 244 | (new Query($db)) |
||
| 245 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 246 | ->from('customer') |
||
| 247 | ->where(['name' => 'user1']) |
||
| 248 | ->limit(1), |
||
| 249 | [ |
||
| 250 | 'address' => 'Moon', |
||
| 251 | 'status' => 2, |
||
| 252 | ], |
||
| 253 | ], |
||
| 254 | 'expected' => [ |
||
| 255 | 'email' => '[email protected]', |
||
| 256 | 'address' => 'address1', |
||
| 257 | 'status' => '1', |
||
| 258 | ], |
||
| 259 | ], |
||
| 260 | [ |
||
| 261 | 'params' => [ |
||
| 262 | 'T_upsert', |
||
| 263 | (new Query($db)) |
||
| 264 | ->select(['email', 'address', 'status' => new Expression('3')]) |
||
| 265 | ->from('customer') |
||
| 266 | ->where(['name' => 'user1']) |
||
| 267 | ->limit(1), |
||
| 268 | [ |
||
| 269 | 'address' => 'Moon', |
||
| 270 | 'status' => 2, |
||
| 271 | ], |
||
| 272 | ], |
||
| 273 | 'expected' => [ |
||
| 274 | 'email' => '[email protected]', |
||
| 275 | 'address' => 'Moon', |
||
| 276 | 'status' => '2', |
||
| 277 | ], |
||
| 278 | ], |
||
| 279 | ], |
||
| 280 | 'query without update part' => [ |
||
| 281 | [ |
||
| 282 | 'params' => [ |
||
| 283 | 'T_upsert', |
||
| 284 | (new Query($db)) |
||
| 285 | ->select(['email', 'address','status' => new Expression('1')]) |
||
| 286 | ->from('customer') |
||
| 287 | ->where(['name' => 'user1']) |
||
| 288 | ->limit(1), |
||
| 289 | false, |
||
| 290 | ], |
||
| 291 | 'expected' => [ |
||
| 292 | 'email' => '[email protected]', |
||
| 293 | 'address' => 'address1', |
||
| 294 | 'status' => '1', |
||
| 295 | ], |
||
| 296 | ], |
||
| 297 | [ |
||
| 298 | 'params' => [ |
||
| 299 | 'T_upsert', |
||
| 300 | (new Query($db)) |
||
| 301 | ->select(['email', 'address', 'status' => new Expression('2')]) |
||
| 302 | ->from('customer') |
||
| 303 | ->where(['name' => 'user1']) |
||
| 304 | ->limit(1), |
||
| 305 | false, |
||
| 306 | ], |
||
| 307 | 'expected' => [ |
||
| 308 | 'email' => '[email protected]', |
||
| 309 | 'address' => 'address1', |
||
| 310 | 'status' => '1', |
||
| 311 | ], |
||
| 371 |