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 |
||
25 | class TreeSelectStrategy implements StrategyInterface |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * The selected leafs. |
||
30 | * |
||
31 | * @var AbstractLeafs |
||
32 | */ |
||
33 | private $attachedLeafs; |
||
34 | |||
35 | /** |
||
36 | * The root node. |
||
37 | * |
||
38 | * @var NodeInterface |
||
39 | */ |
||
40 | private $treeRoot; |
||
41 | |||
42 | /** |
||
43 | * Flag wether multiple selections are allowed. |
||
44 | * |
||
45 | * @var bool|callable |
||
46 | */ |
||
47 | private $allowSelectMultipleItems = false; |
||
48 | |||
49 | /** |
||
50 | * Set the selected leafs. |
||
51 | * |
||
52 | * @param AbstractLeafs $attachedLeafs |
||
53 | * |
||
54 | * @return self |
||
55 | */ |
||
56 | public function setAttachedLeafs(AbstractLeafs $attachedLeafs) |
||
62 | |||
63 | /** |
||
64 | * Get the selected leafs. |
||
65 | * |
||
66 | * @return AbstractLeafs |
||
67 | */ |
||
68 | public function getAttachedLeafs() |
||
72 | |||
73 | /** |
||
74 | * Set the root node. |
||
75 | * |
||
76 | * @param NodeInterface $treeRoot |
||
77 | * |
||
78 | * @return self |
||
79 | */ |
||
80 | public function setTreeRoot(NodeInterface $treeRoot) |
||
86 | |||
87 | /** |
||
88 | * Get the root node. |
||
89 | * |
||
90 | * @return NodeInterface |
||
91 | */ |
||
92 | public function getTreeRoot() |
||
96 | |||
97 | /** |
||
98 | * Set the allow multiple selections flag. |
||
99 | * |
||
100 | * @param Callable|bool $flagOrCallback When a Callable is passed, it must return bool. |
||
101 | * |
||
102 | * @return self |
||
103 | */ |
||
104 | public function setAllowSelectMultipleItems($flagOrCallback) |
||
110 | |||
111 | /** |
||
112 | * Are multiple selections allowed? |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function allowSelectMultipleItems() |
||
122 | |||
123 | public function extract($value) |
||
145 | |||
146 | public function hydrate($value) |
||
168 | |||
169 | /** |
||
170 | * Get item value for use in the option tag. |
||
171 | * |
||
172 | * @param NodeInterface $item |
||
173 | * |
||
174 | * @return string item value prepended with all parent values except root node. |
||
175 | */ |
||
176 | View Code Duplication | private function getItemValue(NodeInterface $item) |
|
191 | |||
192 | /** |
||
193 | * Find a leaf with a concrete value in the tree. |
||
194 | * |
||
195 | * @param NodeInterface $leaf |
||
196 | * @param string $value |
||
197 | * |
||
198 | * @return NodeInterface|null |
||
199 | */ |
||
200 | private function findLeaf(NodeInterface $leaf, $value) |
||
218 | } |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.