| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 38 |
| 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 |
||
| 13 | public function buildFrom(ConnectionPDOInterface $db): array |
||
| 14 | { |
||
| 15 | return [ |
||
| 16 | [ |
||
| 17 | 'table1', |
||
| 18 | DbHelper::replaceQuotes( |
||
| 19 | <<<SQL |
||
| 20 | SELECT * FROM [[table1]] |
||
| 21 | SQL, |
||
| 22 | $db->getname(), |
||
| 23 | ), |
||
| 24 | ], |
||
| 25 | [ |
||
| 26 | ['table1'], |
||
| 27 | DbHelper::replaceQuotes( |
||
| 28 | <<<SQL |
||
| 29 | SELECT * FROM [[table1]] |
||
| 30 | SQL, |
||
| 31 | $db->getname(), |
||
| 32 | ), |
||
| 33 | ], |
||
| 34 | [ |
||
| 35 | new Expression('table2'), |
||
| 36 | <<<SQL |
||
| 37 | SELECT * FROM table2 |
||
| 38 | SQL, |
||
| 39 | ], |
||
| 40 | [ |
||
| 41 | [new Expression('table2')], |
||
| 42 | <<<SQL |
||
| 43 | SELECT * FROM table2 |
||
| 44 | SQL, |
||
| 45 | ], |
||
| 46 | [ |
||
| 47 | ['alias' => 'table3'], |
||
| 48 | DbHelper::replaceQuotes( |
||
| 49 | <<<SQL |
||
| 50 | SELECT * FROM [[table3]] [[alias]] |
||
| 51 | SQL, |
||
| 52 | $db->getname(), |
||
| 53 | ), |
||
| 54 | ], |
||
| 55 | [ |
||
| 56 | ['alias' => new Expression('table4')], |
||
| 57 | <<<SQL |
||
| 58 | SELECT * FROM table4 [alias] |
||
| 59 | SQL, |
||
| 60 | ], |
||
| 61 | [ |
||
| 62 | ['alias' => new Expression('func(:param1, :param2)', ['param1' => 'A', 'param2' => 'B'])], |
||
| 63 | DbHelper::replaceQuotes( |
||
| 64 | <<<SQL |
||
| 65 | SELECT * FROM func(:param1, :param2) [[alias]] |
||
| 66 | SQL, |
||
| 67 | $db->getname(), |
||
| 68 | ), |
||
| 69 | ['param1' => 'A', 'param2' => 'B'], |
||
| 70 | ], |
||
| 74 |