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 |
||
| 8 | class Visibility |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @return array |
||
| 12 | */ |
||
| 13 | 86 | public static function getMapping() |
|
| 14 | { |
||
| 15 | return [ |
||
| 16 | 86 | Class_::MODIFIER_PUBLIC => 0, |
|
| 17 | Class_::MODIFIER_PROTECTED => 1, |
||
| 18 | Class_::MODIFIER_PRIVATE => 2, |
||
| 19 | ]; |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param int $visibility |
||
| 24 | * @return int |
||
| 25 | */ |
||
| 26 | 86 | public static function get($visibility) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * @param \PhpParser\Node\Stmt $context |
||
| 34 | * @return int |
||
| 35 | */ |
||
| 36 | 86 | public static function getForContext(Stmt $context) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @param string $visibility |
||
| 49 | * @return int |
||
| 50 | */ |
||
| 51 | 103 | View Code Duplication | public static function getModifier($visibility) |
| 61 | |||
| 62 | /** |
||
| 63 | * @param int $visibility |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | 86 | View Code Duplication | public static function toString($visibility) |
| 76 | } |
||
| 77 |