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 |
||
| 15 | class RecordSchema implements SchemaInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var ReflectionEntity |
||
| 19 | */ |
||
| 20 | private $reflection; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @invisible |
||
| 24 | * @var MutatorsConfig |
||
| 25 | */ |
||
| 26 | private $mutatorsConfig; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param ReflectionEntity $reflection |
||
| 30 | * @param MutatorsConfig $mutators |
||
| 31 | */ |
||
| 32 | public function __construct(ReflectionEntity $reflection, MutatorsConfig $mutators) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * {@inheritdoc} |
||
| 40 | */ |
||
| 41 | public function getClass(): string |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return ReflectionEntity |
||
| 48 | */ |
||
| 49 | public function getReflection(): ReflectionEntity |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | public function getInstantiator(): string |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | public function getDatabase() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | public function getTable(): string |
||
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritdoc} |
||
| 93 | * |
||
| 94 | * //todo: do we need it? |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function getFields(): array |
|
| 108 | |||
| 109 | /** |
||
| 110 | * {@inheritdoc} |
||
| 111 | */ |
||
| 112 | public function getRelations(): array |
||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | public function defineTable(AbstractTable $table): AbstractTable |
||
| 124 | |||
| 125 | /** |
||
| 126 | * {@inheritdoc} |
||
| 127 | */ |
||
| 128 | public function packSchema(SchemaBuilder $builder, AbstractTable $table = null): array |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Check if field schema/type defines relation. |
||
| 135 | * |
||
| 136 | * @param mixed $type |
||
| 137 | * |
||
| 138 | * @return bool |
||
| 139 | */ |
||
| 140 | protected function isRelation($type): bool |
||
| 148 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.