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 |
||
12 | class ResponsiveFactory { |
||
13 | |||
14 | /** |
||
15 | * The compile directory to store images. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $compileDir; |
||
20 | |||
21 | /** |
||
22 | * @var float |
||
23 | */ |
||
24 | protected $stepModified = 0.1; |
||
25 | |||
26 | /** |
||
27 | * @var integer |
||
28 | */ |
||
29 | protected $minsize = 300; |
||
30 | |||
31 | /** |
||
32 | * @var ImageManager |
||
33 | */ |
||
34 | protected $engine; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $enableCache; |
||
40 | |||
41 | /** |
||
42 | * ResponsiveFactory constructor. |
||
43 | * |
||
44 | * @param string $compileDir |
||
45 | * @param string $driver |
||
46 | * @param float $stepModifier |
||
47 | * @param int $minsize |
||
48 | * @param bool $enableCache |
||
49 | */ |
||
50 | public function __construct($compileDir, $driver = 'gd', $stepModifier = 0.1, $minsize = 300, $enableCache = false) { |
||
66 | |||
67 | /** |
||
68 | * @param string $path |
||
69 | * |
||
70 | * @return ResponsiveImage |
||
71 | * @throws FileNotFoundException |
||
72 | */ |
||
73 | public function create($path) { |
||
122 | |||
123 | /** |
||
124 | * @param int $minsize |
||
125 | * |
||
126 | * @return ResponsiveFactory |
||
127 | */ |
||
128 | public function setMinsize($minsize) { |
||
133 | |||
134 | /** |
||
135 | * @param float $stepModified |
||
136 | * |
||
137 | * @return ResponsiveFactory |
||
138 | */ |
||
139 | public function setStepModified($stepModified) { |
||
144 | |||
145 | /** |
||
146 | * @param $src |
||
147 | * |
||
148 | * @return SplFileInfo |
||
149 | * @throws FileNotFoundException |
||
150 | */ |
||
151 | View Code Duplication | private function getImageFile($src) { |
|
160 | |||
161 | } |
||
162 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.