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 declare(strict_types=1); |
||
30 | abstract class BaseSchema implements SchemaInterface |
||
31 | { |
||
32 | /** |
||
33 | * @var FactoryInterface |
||
34 | */ |
||
35 | private $factory; |
||
36 | |||
37 | /** |
||
38 | * @var null|string |
||
39 | */ |
||
40 | private $subUrl = null; |
||
41 | |||
42 | /** |
||
43 | * @param FactoryInterface $factory |
||
44 | */ |
||
45 | 70 | public function __construct(FactoryInterface $factory) |
|
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 60 | public function getSelfLink($resource): LinkInterface |
|
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | 60 | public function getLinks($resource): iterable |
|
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | 42 | View Code Duplication | public function getRelationshipSelfLink($resource, string $name): LinkInterface |
81 | |||
82 | /** |
||
83 | * @inheritdoc |
||
84 | */ |
||
85 | 16 | View Code Duplication | public function getRelationshipRelatedLink($resource, string $name): LinkInterface |
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | 35 | public function hasIdentifierMeta($resource): bool |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | 1 | public function getIdentifierMeta($resource) |
|
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | 62 | public function hasResourceMeta($resource): bool |
|
118 | |||
119 | /** |
||
120 | * @inheritdoc |
||
121 | */ |
||
122 | 1 | public function getResourceMeta($resource) |
|
127 | |||
128 | /** |
||
129 | * @inheritdoc |
||
130 | */ |
||
131 | 23 | public function isAddSelfLinkInRelationshipByDefault(string $relationshipName): bool |
|
132 | { |
||
133 | 23 | return true; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | 19 | public function isAddRelatedLinkInRelationshipByDefault(string $relationshipName): bool |
|
140 | { |
||
141 | 19 | return true; |
|
142 | } |
||
143 | |||
144 | /** |
||
145 | * @return FactoryInterface |
||
146 | */ |
||
147 | 35 | protected function getFactory(): FactoryInterface |
|
151 | |||
152 | /** |
||
153 | * Get resources sub-URL. |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | 67 | protected function getResourcesSubUrl(): string |
|
165 | |||
166 | /** |
||
167 | * @param mixed $resource |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 67 | protected function getSelfSubUrl($resource): string |
|
175 | } |
||
176 |