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 |
||
| 5 | class NodePriorityQueueMin implements \Countable |
||
| 6 | { |
||
| 7 | private |
||
| 8 | $map, |
||
| 9 | $queue; |
||
| 10 | |||
| 11 | public function __contruct() |
||
| 16 | |||
| 17 | public function count() |
||
| 21 | |||
| 22 | public function isEmpty() |
||
| 26 | |||
| 27 | View Code Duplication | public function lookup(Node $node) |
|
| 38 | |||
| 39 | public function extract() |
||
| 50 | |||
| 51 | public function insert(Node $node, $priority) |
||
| 57 | } |
||
| 58 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.