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 |
||
11 | class VariableFactory extends DynamicFactory |
||
12 | { |
||
13 | /** @var \Symfony\Component\Yaml\Yaml */ |
||
14 | private $yamlParser; |
||
15 | |||
16 | /** @var \Pageon\Lib\Markdown\MarkdownParser */ |
||
17 | private $markdownParser; |
||
18 | |||
19 | /** @var \Pageon\Html\Image\ImageFactory */ |
||
20 | private $imageParser; |
||
21 | |||
22 | /** @var \Stitcher\Variable\VariableParser */ |
||
23 | private $variableParser; |
||
24 | |||
25 | 3 | public function __construct() |
|
34 | |||
35 | 3 | public static function make(): VariableFactory |
|
39 | |||
40 | public function setYamlParser(Yaml $yamlParser): VariableFactory |
||
41 | { |
||
42 | $this->yamlParser = $yamlParser; |
||
43 | |||
44 | return $this; |
||
45 | } |
||
46 | |||
47 | public function setMarkdownParser(MarkdownParser $markdownParser): VariableFactory |
||
48 | { |
||
49 | $this->markdownParser = $markdownParser; |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | public function setImageParser(ImageFactory $imageParser): VariableFactory |
||
55 | { |
||
56 | $this->imageParser = $imageParser; |
||
57 | |||
58 | return $this; |
||
59 | } |
||
60 | |||
61 | 3 | public function setVariableParser(VariableParser $variableParser): VariableFactory |
|
67 | |||
68 | public function create($value): AbstractVariable |
||
69 | { |
||
70 | foreach ($this->getRules() as $rule) { |
||
84 | |||
85 | View Code Duplication | private function setJsonRule(): DynamicFactory |
|
95 | |||
96 | private function setYamlRule(): void |
||
112 | |||
113 | private function setMarkdownRule(): void |
||
127 | |||
128 | View Code Duplication | private function setHtmlRule(): void |
|
138 | |||
139 | private function setImageRule(): void |
||
157 | |||
158 | private function setDirectoryRule(): void |
||
172 | } |
||
173 |