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 |
||
22 | class DirectiveLocation extends AbstractDependentTypeDefinition implements DirectiveLocationInterface, Verifiable |
||
23 | { |
||
24 | /** |
||
25 | * @throws \Railt\Io\Exception\ExternalFileException |
||
26 | */ |
||
27 | View Code Duplication | public function verify(): void |
|
|
|||
28 | { |
||
29 | $locations = \array_merge(static::EXECUTABLE_LOCATIONS, static::SDL_LOCATIONS); |
||
30 | |||
31 | if (! \in_array($this->name, $locations, true)) { |
||
32 | throw $this->error(new TypeConflictException(\sprintf('Invalid name of %s', $this))); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return bool |
||
38 | */ |
||
39 | public function isExecutable(): bool |
||
43 | |||
44 | /** |
||
45 | * @return bool |
||
46 | */ |
||
47 | public function isPrivate(): bool |
||
51 | |||
52 | /** |
||
53 | * @param TypeInterface $type |
||
54 | * @return bool |
||
55 | * @throws \Railt\Io\Exception\ExternalFileException |
||
56 | */ |
||
57 | public function isAllowedFor(TypeInterface $type): bool |
||
63 | |||
64 | /** |
||
65 | * @return TypeInterface |
||
66 | * @throws \Railt\Io\Exception\ExternalFileException |
||
67 | */ |
||
68 | public static function getType(): TypeInterface |
||
72 | } |
||
73 |
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.