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 | View Code Duplication | class MethodMetadata implements \Serializable |
|
| 30 | { |
||
| 31 | public $class; |
||
| 32 | public $name; |
||
| 33 | public $reflection; |
||
| 34 | |||
| 35 | public function __construct($class, $name) |
||
| 36 | { |
||
| 37 | $this->class = $class; |
||
| 38 | $this->name = $name; |
||
| 39 | |||
| 40 | $this->reflection = new \ReflectionMethod($class, $name); |
||
| 41 | $this->reflection->setAccessible(true); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param object $obj |
||
| 46 | * @param array $args |
||
| 47 | * |
||
| 48 | * @return mixed |
||
| 49 | */ |
||
| 50 | public function invoke($obj, array $args = array()) |
||
| 54 | |||
| 55 | public function serialize() |
||
| 59 | |||
| 60 | public function unserialize($str) |
||
| 67 | } |
||
| 68 |