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 | abstract class AbstractRelation implements Relation |
||
26 | { |
||
27 | use Queueable { |
||
28 | build as buildQueued; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $relation; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $entity; |
||
40 | |||
41 | /** |
||
42 | * @var NamingStrategy |
||
43 | */ |
||
44 | protected $namingStrategy; |
||
45 | |||
46 | /** |
||
47 | * @var ClassMetadataBuilder |
||
48 | */ |
||
49 | protected $builder; |
||
50 | |||
51 | /** |
||
52 | * @var AssociationBuilder |
||
53 | */ |
||
54 | protected $association; |
||
55 | |||
56 | /** |
||
57 | * @param ClassMetadataBuilder $builder |
||
58 | * @param NamingStrategy $namingStrategy |
||
59 | * @param string $relation |
||
60 | * @param string $entity |
||
61 | */ |
||
62 | 125 | public function __construct(ClassMetadataBuilder $builder, NamingStrategy $namingStrategy, $relation, $entity) |
|
70 | |||
71 | /** |
||
72 | * @param ClassMetadataBuilder $builder |
||
73 | * @param string $relation |
||
74 | * @param string $entity |
||
75 | * |
||
76 | * @return AssociationBuilder |
||
77 | */ |
||
78 | abstract protected function createAssociation(ClassMetadataBuilder $builder, $relation, $entity); |
||
79 | |||
80 | /** |
||
81 | * @param string[] $cascade one of "persist", "remove", "merge", "detach", "refresh" or "ALL" |
||
82 | * |
||
83 | * @return $this |
||
84 | */ |
||
85 | 12 | View Code Duplication | public function cascade(array $cascade) |
99 | |||
100 | /** |
||
101 | * @param string $strategy one of "LAZY", "EAGER", "EXTRA_LAZY" |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | 8 | View Code Duplication | public function fetch($strategy) |
117 | |||
118 | /** |
||
119 | * @return ClassMetadataBuilder |
||
120 | */ |
||
121 | 63 | public function getBuilder() |
|
125 | |||
126 | /** |
||
127 | * @return \Doctrine\ORM\Mapping\ClassMetadata|ExtensibleClassMetadata |
||
128 | */ |
||
129 | 3 | public function getClassMetadata() |
|
133 | |||
134 | /** |
||
135 | * @return AssociationBuilder |
||
136 | */ |
||
137 | 91 | public function getAssociation() |
|
141 | |||
142 | /** |
||
143 | * @param string $usage |
||
144 | * @param string|null $region |
||
145 | * |
||
146 | * @return $this |
||
147 | */ |
||
148 | 16 | public function cache($usage = 'READ_ONLY', $region = null) |
|
161 | |||
162 | /** |
||
163 | * Execute the build process for all queued buildables |
||
164 | */ |
||
165 | 86 | public function build() |
|
171 | |||
172 | /** |
||
173 | * Magic call method works as a proxy for the Doctrine associationBuilder |
||
174 | * |
||
175 | * @param string $method |
||
176 | * @param array $args |
||
177 | * |
||
178 | * @throws BadMethodCallException |
||
179 | * @return $this |
||
180 | */ |
||
181 | 50 | public function __call($method, $args) |
|
191 | |||
192 | /** |
||
193 | * @return NamingStrategy |
||
194 | */ |
||
195 | 61 | public function getNamingStrategy() |
|
199 | |||
200 | /** |
||
201 | * @return string |
||
202 | */ |
||
203 | 3 | public function getRelation() |
|
207 | } |
||
208 |