Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 19 | class CountOutputWalker extends SqlWalker |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var \Doctrine\DBAL\Platforms\AbstractPlatform |
||
| 23 | */ |
||
| 24 | private $platform; |
||
|
|
|||
| 25 | /** |
||
| 26 | * @var \Doctrine\ORM\Query\ResultSetMapping |
||
| 27 | */ |
||
| 28 | private $rsm; |
||
| 29 | /** |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | private $queryComponents; |
||
| 33 | /** |
||
| 34 | * Constructor. |
||
| 35 | * |
||
| 36 | * Stores various parameters that are otherwise unavailable |
||
| 37 | * because Doctrine\ORM\Query\SqlWalker keeps everything private without |
||
| 38 | * accessors. |
||
| 39 | * |
||
| 40 | * @param \Doctrine\ORM\Query $query |
||
| 41 | * @param \Doctrine\ORM\Query\ParserResult $parserResult |
||
| 42 | * @param array $queryComponents |
||
| 43 | */ |
||
| 44 | 8 | public function __construct($query, $parserResult, array $queryComponents) |
|
| 51 | /** |
||
| 52 | * Walks down a SelectStatement AST node, wrapping it in a COUNT (SELECT DISTINCT). |
||
| 53 | * |
||
| 54 | * Note that the ORDER BY clause is not removed. Many SQL implementations (e.g. MySQL) |
||
| 55 | * are able to cache subqueries. By keeping the ORDER BY clause intact, the limitSubQuery |
||
| 56 | * that will most likely be executed next can be read from the native SQL cache. |
||
| 57 | * |
||
| 58 | * @param SelectStatement $AST |
||
| 59 | * |
||
| 60 | * @return string |
||
| 61 | * |
||
| 62 | * @throws \RuntimeException |
||
| 63 | */ |
||
| 64 | 8 | public function walkSelectStatement(SelectStatement $AST) |
|
| 115 | } |