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 |
||
14 | class SitemapObserver implements ParsedContentObserverInterface |
||
15 | { |
||
16 | /** |
||
17 | * Config writer |
||
18 | * |
||
19 | * @var XmlXmlWriter |
||
20 | */ |
||
21 | private $xmlWriter; |
||
22 | |||
23 | /** |
||
24 | * Sitemap path |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $sitemapPath; |
||
29 | |||
30 | /** |
||
31 | * Base url |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $baseUrl; |
||
36 | |||
37 | /** |
||
38 | * Constructor |
||
39 | * |
||
40 | * @param XmlWriter $xmlWriter |
||
41 | * @param string $sitemapPath |
||
42 | * @param string $baseUrl |
||
43 | */ |
||
44 | public function __construct(XmlWriter $xmlWriter, string $sitemapPath, string $baseUrl) |
||
50 | |||
51 | /** |
||
52 | * Handle parsed config |
||
53 | * @param array $config |
||
54 | */ |
||
55 | public function __invoke(array $config) |
||
83 | |||
84 | /** |
||
85 | * Get xml config writer |
||
86 | * |
||
87 | * @return XmlXmlWriter |
||
88 | */ |
||
89 | public function getXmlWriter() : XmlWriter |
||
93 | |||
94 | /** |
||
95 | * Get sitemap path |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getSitemapPath() : string |
||
103 | |||
104 | /** |
||
105 | * Get base url |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public function getBaseUrl() : string |
||
113 | |||
114 | } |
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..