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 |
||
27 | class Doubler |
||
28 | { |
||
29 | private $mirror; |
||
30 | private $creator; |
||
31 | private $namer; |
||
32 | |||
33 | /** |
||
34 | * @var ClassPatchInterface[] |
||
35 | */ |
||
36 | private $patches = array(); |
||
37 | |||
38 | /** |
||
39 | * @var \Doctrine\Instantiator\Instantiator |
||
40 | */ |
||
41 | private $instantiator; |
||
42 | |||
43 | /** |
||
44 | * Initializes doubler. |
||
45 | * |
||
46 | * @param ClassMirror $mirror |
||
47 | * @param ClassCreator $creator |
||
48 | * @param NameGenerator $namer |
||
49 | */ |
||
50 | public function __construct(ClassMirror $mirror = null, ClassCreator $creator = null, |
||
57 | |||
58 | /** |
||
59 | * Returns list of registered class patches. |
||
60 | * |
||
61 | * @return ClassPatchInterface[] |
||
62 | */ |
||
63 | public function getClassPatches() |
||
67 | |||
68 | /** |
||
69 | * Registers new class patch. |
||
70 | * |
||
71 | * @param ClassPatchInterface $patch |
||
72 | */ |
||
73 | public function registerClassPatch(ClassPatchInterface $patch) |
||
81 | |||
82 | /** |
||
83 | * Creates double from specific class or/and list of interfaces. |
||
84 | * |
||
85 | * @param ReflectionClass $class |
||
86 | * @param ReflectionClass[] $interfaces Array of ReflectionClass instances |
||
87 | * @param array $args Constructor arguments |
||
88 | * |
||
89 | * @return DoubleInterface |
||
90 | * |
||
91 | * @throws \Prophecy\Exception\InvalidArgumentException |
||
92 | */ |
||
93 | public function double(ReflectionClass $class = null, array $interfaces, array $args = null) |
||
122 | |||
123 | /** |
||
124 | * Creates double class and returns its FQN. |
||
125 | * |
||
126 | * @param ReflectionClass $class |
||
127 | * @param ReflectionClass[] $interfaces |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | protected function createDoubleClass(ReflectionClass $class = null, array $interfaces) |
||
146 | } |
||
147 |
If you suppress an error, we recommend checking for the error condition explicitly: