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 |
||
10 | class ExampleFactory |
||
11 | { |
||
12 | /** |
||
13 | * @var ExpectationFactory |
||
14 | */ |
||
15 | private $expectationFactory; |
||
16 | |||
17 | public function __construct(ExpectationFactory $expectationFactory = null) |
||
21 | |||
22 | /** |
||
23 | * Create examples from definitions |
||
24 | * |
||
25 | * @param array $defenitions Example definitions as created by Parser |
||
26 | * @return Example[] |
||
27 | */ |
||
28 | public function createExamples(array $defenitions) |
||
74 | |||
75 | /** |
||
76 | * Read name from example annotation |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | View Code Duplication | private function readName(array $annotations) |
|
90 | |||
91 | /** |
||
92 | * Check if this example is marked as ignored |
||
93 | * |
||
94 | * @return boolean |
||
95 | */ |
||
96 | private function shouldIgnoreExample(array $annotations) |
||
106 | |||
107 | /** |
||
108 | * Get name of example this example should extend |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | View Code Duplication | private function shouldExtendExample(array $annotations) |
|
122 | |||
123 | /** |
||
124 | * Create expectation from definition data |
||
125 | * |
||
126 | * @return Expectation\ExpectationInterface[] |
||
127 | */ |
||
128 | private function createExpectations(array $annotations) |
||
138 | } |
||
139 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.