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 PropertyMetadata 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 \ReflectionProperty($class, $name); |
||
| 41 | $this->reflection->setAccessible(true); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param object $obj |
||
| 46 | * |
||
| 47 | * @return mixed |
||
| 48 | */ |
||
| 49 | public function getValue($obj) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param object $obj |
||
| 56 | * @param string $value |
||
| 57 | */ |
||
| 58 | public function setValue($obj, $value) |
||
| 62 | |||
| 63 | public function serialize() |
||
| 70 | |||
| 71 | public function unserialize($str) |
||
| 78 | } |
||
| 79 |