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 NodeMap implements \Countable, \Iterator |
||
| 6 | { |
||
| 7 | private |
||
| 8 | $map; |
||
|
|
|||
| 9 | |||
| 10 | public function __contruct() |
||
| 14 | |||
| 15 | public function count() |
||
| 19 | |||
| 20 | public function isEmpty() |
||
| 24 | |||
| 25 | public function rewind() |
||
| 29 | |||
| 30 | public function current() |
||
| 34 | |||
| 35 | public function key() |
||
| 39 | |||
| 40 | public function next() |
||
| 44 | |||
| 45 | public function valid() |
||
| 49 | |||
| 50 | View Code Duplication | public function lookup(Node $node) |
|
| 61 | |||
| 62 | public function lookupFrom(Node $node) |
||
| 78 | |||
| 79 | public function delete(Node $node) |
||
| 92 | |||
| 93 | public function exists(Node $node) |
||
| 97 | |||
| 98 | public function insert(Node $node, $value = true) |
||
| 102 | } |
||
| 103 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.