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 |
||
21 | View Code Duplication | class xsGDay extends xsAnySimpleType |
|
22 | { |
||
23 | use MinMaxTrait; |
||
24 | |||
25 | /** |
||
26 | * Construct. |
||
27 | * |
||
28 | * @param string $value |
||
29 | */ |
||
30 | public function __construct($value) |
||
31 | { |
||
32 | parent::__construct($value); |
||
33 | $this->setWhiteSpaceFacet('collapse'); |
||
34 | } |
||
35 | |||
36 | public function fixValue() |
||
37 | { |
||
38 | parent::fixValue(); |
||
39 | $dayObject = CalenderFactory::fromDay($this->value); |
||
|
|||
40 | } |
||
41 | |||
42 | protected function isOK() |
||
46 | } |
||
47 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.