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 |
||
| 17 | class Preparation |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param Study $study |
||
| 21 | * @param mixed $control |
||
| 22 | * @param mixed[] $trials |
||
| 23 | * @param string[] $interfaces that blind should satisfy |
||
| 24 | * @return Blind |
||
| 25 | */ |
||
| 26 | 10 | public function prepare(Study $study, $control, array $trials, array $interfaces = []) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * @param $study |
||
| 34 | * @param mixed $control |
||
| 35 | * @param Experiment[] $experiments |
||
| 36 | * @param string[] $interfaces |
||
| 37 | * @return Blind |
||
| 38 | */ |
||
| 39 | 10 | private function createBlind($study, $control, array $experiments, array $interfaces = []) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @param $study |
||
| 66 | * @param $control |
||
| 67 | * @param array $trials |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | 10 | private function createExperiments(Study $study, $control, array $trials) |
|
| 71 | { |
||
| 72 | 10 | $experiments = []; |
|
| 73 | 10 | $reflection = new ReflectionClass($control); |
|
| 74 | 10 | foreach ($reflection->getMethods() as $method) { |
|
| 75 | 10 | $experiments[] = $this->createMethodExperiment($method->getName(), $study, $control, $trials); |
|
| 76 | 10 | } |
|
| 77 | 10 | foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
| 78 | 10 | $experiments[] = $this->createPropertyExperiment($property->getName(), $study, $control, $trials); |
|
| 79 | 10 | } |
|
| 80 | 10 | return $experiments; |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param string $name |
||
| 85 | * @param Study $study |
||
| 86 | * @param mixed $control |
||
| 87 | * @param mixed[] $trials |
||
| 88 | * @return Experiment |
||
| 89 | */ |
||
| 90 | 10 | private function createMethodExperiment($name, Study $study, $control, array $trials) |
|
| 112 | |||
| 113 | 10 | private function createPropertyExperiment($name, Study $study, $control, array $trials) |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @param mixed $instance |
||
| 138 | * @param string $name |
||
| 139 | * @return callable |
||
| 140 | */ |
||
| 141 | 10 | private function createPropertyCallable($instance, $name) |
|
| 155 | |||
| 156 | 3 | private function createMissingPropertyCallable($instance, $name) |
|
| 162 | |||
| 163 | private function createMissingMethodCallable($instance, $name) |
||
| 169 | |||
| 170 | 10 | private function addInterfaceMethods(Classgenerator $classGenerator, array $interfaces) |
|
| 188 | } |
||
| 189 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.