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 |
||
23 | class ShortcodeFacade |
||
24 | { |
||
25 | /** @var ProcessorInterface */ |
||
26 | private $processor; |
||
27 | /** @var ParserInterface */ |
||
28 | private $parser; |
||
29 | /** @var SyntaxInterface */ |
||
30 | private $syntax; |
||
31 | |||
32 | /** @var HandlerContainer */ |
||
33 | private $handlers; |
||
34 | /** @var EventContainer */ |
||
35 | private $events; |
||
36 | |||
37 | /** @var SerializerInterface */ |
||
38 | private $textSerializer; |
||
39 | /** @var SerializerInterface */ |
||
40 | private $jsonSerializer; |
||
41 | /** @var SerializerInterface */ |
||
42 | private $xmlSerializer; |
||
43 | /** @var SerializerInterface */ |
||
44 | private $yamlSerializer; |
||
45 | |||
46 | 5 | public function __construct() |
|
60 | |||
61 | /** @deprecated use constructor and customize using exposed methods */ |
||
62 | 1 | public static function create(HandlerContainerInterface $handlers, SyntaxInterface $syntax) |
|
72 | |||
73 | 5 | private function rebuildProcessor() |
|
78 | |||
79 | 2 | public function process($text) |
|
83 | |||
84 | 1 | public function parse($text) |
|
88 | |||
89 | 1 | public function setParser(ParserInterface $parser) |
|
96 | |||
97 | 2 | public function addHandler($name, $handler) |
|
103 | |||
104 | 1 | public function addHandlerAlias($alias, $name) |
|
110 | |||
111 | 1 | public function addEventHandler($name, $handler) |
|
117 | |||
118 | /* --- SERIALIZATION --------------------------------------------------- */ |
||
119 | |||
120 | 2 | View Code Duplication | public function serialize(ShortcodeInterface $shortcode, $format) |
130 | |||
131 | 2 | View Code Duplication | public function unserialize($text, $format) |
141 | |||
142 | /** @deprecated use serialize($shortcode, $format) */ |
||
143 | public function serializeToText(ShortcodeInterface $s) { return $this->serialize($s, 'text'); } |
||
144 | /** @deprecated use serialize($shortcode, $format) */ |
||
145 | public function serializeToJson(ShortcodeInterface $s) { return $this->serialize($s, 'json'); } |
||
146 | /** @deprecated use unserialize($shortcode, $format) */ |
||
147 | public function unserializeFromText($text) { return $this->unserialize($text, 'text'); } |
||
148 | /** @deprecated use unserialize($shortcode, $format) */ |
||
149 | public function unserializeFromJson($text) { return $this->unserialize($text, 'json'); } |
||
150 | } |
||
151 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.