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 |
||
| 29 | abstract class StrictArrayCollection extends ArrayCollection |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * {@inheritdoc} |
||
| 33 | */ |
||
| 34 | 37 | public function __construct(array $array = array()) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * @param mixed $element |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | abstract public function checkValue($element); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | * @throws \InvalidArgumentException |
||
| 52 | */ |
||
| 53 | 32 | View Code Duplication | final public function set($key, $value) |
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | * @throws \InvalidArgumentException |
||
| 65 | */ |
||
| 66 | 4 | View Code Duplication | final public function add($value) |
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | * @throws \InvalidArgumentException |
||
| 78 | */ |
||
| 79 | final public function map(Closure $func) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * 型を保証しないmap |
||
| 99 | * |
||
| 100 | * @param Closure $func |
||
| 101 | * @return ArrayCollection |
||
| 102 | */ |
||
| 103 | final public function looseMap(Closure $func) |
||
| 107 | } |