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 |
||
35 | class ExtendedJsonParser extends JsonParser |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The key for the configuration snippet that contains the extension libary configuration. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | const EXTENSION_LIBRARIES = 'extension-libraries'; |
||
44 | |||
45 | /** |
||
46 | * The absolute path to the vendor directory |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $vendorDir; |
||
51 | |||
52 | /** |
||
53 | * Initializes the parser with the array utility instance. |
||
54 | * |
||
55 | * @param \TechDivision\Import\Configuration\Jms\Utils\ArrayUtilInterface $arrayUtil The utility instance |
||
56 | * @param \TechDivision\Import\Loaders\LoaderInterface $vendorDirLoader The loader for the absolute vendor directory |
||
57 | */ |
||
58 | public function __construct(ArrayUtilInterface $arrayUtil, LoaderInterface $vendorDirLoader) |
||
67 | |||
68 | /** |
||
69 | * Parsing the configuration and merge it recursively. |
||
70 | * |
||
71 | * @param string $installationDir The assumed Magento installation directory |
||
72 | * @param string $defaultConfigurationDir The default configuration directory |
||
73 | * @param array $directories An array with diretories to parse |
||
74 | * |
||
75 | * @return string The parsed configuration as string |
||
76 | */ |
||
77 | View Code Duplication | public function parse(string $installationDir, string $defaultConfigurationDir, array $directories) : string |
|
97 | |||
98 | /** |
||
99 | * Process the configuration files found in the extension libary directories |
||
100 | * and merge/replace its content in the also passed main configuration file. |
||
101 | * |
||
102 | * @param array $main The main configuration to merge/replace the extension libary files to |
||
103 | * @param string $defaultConfigurationDir The default configuration directory |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | protected function processExtensionLibraries(array &$main, string $defaultConfigurationDir) : void |
||
126 | } |
||
127 |
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..