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 |
||
18 | class MarkupValidator extends Module |
||
19 | { |
||
20 | |||
21 | const COMPONENT_CLASS_CONFIG_KEY = 'class'; |
||
22 | |||
23 | const COMPONENT_CONFIG_CONFIG_KEY = 'config'; |
||
24 | |||
25 | const PROVIDER_CONFIG_KEY = 'provider'; |
||
26 | |||
27 | const VALIDATOR_CONFIG_KEY = 'validator'; |
||
28 | |||
29 | const FILTER_CONFIG_KEY = 'filter'; |
||
30 | |||
31 | const PRINTER_CONFIG_KEY = 'printer'; |
||
32 | |||
33 | /** |
||
34 | * {@inheritDoc} |
||
35 | */ |
||
36 | protected $config = array( |
||
37 | self::PROVIDER_CONFIG_KEY => array( |
||
38 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMarkupProvider', |
||
39 | self::COMPONENT_CONFIG_CONFIG_KEY => array(), |
||
40 | ), |
||
41 | self::VALIDATOR_CONFIG_KEY => array( |
||
42 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\W3CMarkupValidator', |
||
43 | self::COMPONENT_CONFIG_CONFIG_KEY => array(), |
||
44 | ), |
||
45 | self::FILTER_CONFIG_KEY => array( |
||
46 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessageFilter', |
||
47 | self::COMPONENT_CONFIG_CONFIG_KEY => array(), |
||
48 | ), |
||
49 | self::PRINTER_CONFIG_KEY => array( |
||
50 | self::COMPONENT_CLASS_CONFIG_KEY => 'Kolyunya\Codeception\Lib\MarkupValidator\DefaultMessagePrinter', |
||
51 | self::COMPONENT_CONFIG_CONFIG_KEY => array(), |
||
52 | ), |
||
53 | ); |
||
54 | |||
55 | /** |
||
56 | * Markup provider. |
||
57 | * |
||
58 | * @var MarkupProviderInterface |
||
59 | */ |
||
60 | private $markupProvider; |
||
61 | |||
62 | /** |
||
63 | * Markup validator. |
||
64 | * |
||
65 | * @var MarkupValidatorInterface |
||
66 | */ |
||
67 | private $markupValidator; |
||
68 | |||
69 | /** |
||
70 | * Message filter. |
||
71 | * |
||
72 | * @var MessageFilterInterface |
||
73 | */ |
||
74 | private $messageFilter; |
||
75 | |||
76 | /** |
||
77 | * Message printer. |
||
78 | * |
||
79 | * @var MessagePrinterInterface |
||
80 | */ |
||
81 | private $messagePrinter; |
||
82 | |||
83 | /** |
||
84 | * {@inheritDoc} |
||
85 | */ |
||
86 | public function __construct(ModuleContainer $moduleContainer, $config = null) |
||
95 | |||
96 | /** |
||
97 | * Validates page markup via a markup validator. |
||
98 | * Allows to recongigure message filter component. |
||
99 | * |
||
100 | * @param array $messageFilterConfiguration Message filter configuration. |
||
101 | */ |
||
102 | public function validateMarkup(array $messageFilterConfiguration = array()) |
||
118 | |||
119 | /** |
||
120 | * Initializes markup provider. |
||
121 | */ |
||
122 | private function initializeMarkupProvider() |
||
129 | |||
130 | /** |
||
131 | * Initializes markup validator. |
||
132 | */ |
||
133 | private function initializeMarkupValidator() |
||
138 | |||
139 | /** |
||
140 | * Initializes message filter. |
||
141 | */ |
||
142 | private function initializeMessageFilter() |
||
147 | |||
148 | /** |
||
149 | * Initializes message printer. |
||
150 | */ |
||
151 | private function initializeMessagePrinter() |
||
156 | |||
157 | /** |
||
158 | * Instantiates and returns a module component. |
||
159 | * |
||
160 | * @param string $componentName Component name. |
||
161 | * @param string $interface An interface component must implement. |
||
162 | * @param array $arguments Component's constructor arguments. |
||
163 | * |
||
164 | * @throws Exception When component does not implement expected interface. |
||
165 | * |
||
166 | * @return object Instance of a module component. |
||
167 | */ |
||
168 | private function instantiateComponent($componentName, $interface, array $arguments = array()) |
||
185 | |||
186 | /** |
||
187 | * Returns component class name. |
||
188 | * |
||
189 | * @param string $componentName Component name. |
||
190 | * |
||
191 | * @return string Component class name. |
||
192 | */ |
||
193 | View Code Duplication | private function getComponentClass($componentName) |
|
207 | |||
208 | /** |
||
209 | * Returns component configuration parameters. |
||
210 | * |
||
211 | * @param string $componentName Component name. |
||
212 | * |
||
213 | * @return array Component configuration parameters. |
||
214 | */ |
||
215 | View Code Duplication | private function getComponentConfiguration($componentName) |
|
229 | } |
||
230 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..