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 |
||
28 | abstract class ExplicitGetter |
||
29 | { |
||
30 | |||
31 | |||
32 | // <editor-fold desc="// = = = = P R O T E C T E D F I E L D S = = = = = = = = = = = = = = = = = = = = = = ="> |
||
33 | |||
34 | /** |
||
35 | * The names of all get* methods (without the leading get) that should not be mapped as dynamic properties |
||
36 | * |
||
37 | * @type array |
||
38 | * @since v0.2.0 |
||
39 | */ |
||
40 | protected $ignoreGetProperties = []; |
||
41 | |||
42 | // </editor-fold> |
||
43 | |||
44 | |||
45 | // <editor-fold desc="// = = = = P U B L I C M E T H O D S = = = = = = = = = = = = = = = = = = = = = = = = ="> |
||
46 | |||
47 | /** |
||
48 | * The magic get method to let you access all getter methods by dynamic properties. |
||
49 | * |
||
50 | * @param string $name The name of the required dynamic property. |
||
51 | * @return mixed |
||
52 | * @throws \LogicException If the property is unknown |
||
53 | */ |
||
54 | 14 | public function __get( string $name ) |
|
60 | |||
61 | /** |
||
62 | * Magic isset implementation. |
||
63 | * |
||
64 | * @param string $name The name of the required property. |
||
65 | * @return boolean |
||
66 | */ |
||
67 | 6 | public function __isset( string $name ) |
|
73 | |||
74 | /** |
||
75 | * Returns, if a property with the defined name exists for read access. |
||
76 | * |
||
77 | * @param string $name The name of the property. |
||
78 | * @param string $getterName Returns the name of the associated get method, if method returns TRUE. |
||
79 | * @return boolean |
||
80 | */ |
||
81 | 7 | View Code Duplication | public function hasReadableProperty( string $name, &$getterName ) : bool |
94 | |||
95 | // </editor-fold> |
||
96 | |||
97 | |||
98 | // <editor-fold desc="// = = = = P R O T E C T E D M E T H O D S = = = = = = = = = = = = = = = = = = = = = ="> |
||
99 | |||
100 | /** |
||
101 | * @param string $name |
||
102 | * @return mixed |
||
103 | */ |
||
104 | 14 | protected function __internalGet( string $name ) |
|
116 | |||
117 | // </editor-fold> |
||
118 | |||
119 | |||
120 | } |
||
121 | |||
122 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.