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 Type implements TypeInterface |
||
| 23 | { |
||
| 24 | use Serializable; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var Type[] |
||
| 28 | */ |
||
| 29 | private static $instances = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array[]|string[][] |
||
| 33 | */ |
||
| 34 | private static $inheritance = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var array|string[] |
||
| 38 | */ |
||
| 39 | private $parent; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $name; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * BaseType constructor. |
||
| 48 | * @param string $name |
||
| 49 | * @throws \Railt\Io\Exception\ExternalFileException |
||
| 50 | */ |
||
| 51 | 9 | private function __construct(string $name) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $name |
||
| 61 | * @throws \Railt\Io\Exception\ExternalFileException |
||
| 62 | */ |
||
| 63 | 9 | View Code Duplication | private function verifyType(string $name): void |
| 71 | |||
| 72 | /** |
||
| 73 | * @return bool |
||
| 74 | */ |
||
| 75 | 9 | public function isInputable(): bool |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | public function isReturnable(): bool |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param string $name |
||
| 90 | * @return array |
||
| 91 | */ |
||
| 92 | 9 | private function getInheritanceSequence(string $name): array |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @param \SplStack $stack |
||
| 103 | * @param array $children |
||
| 104 | */ |
||
| 105 | private function bootInheritance(\SplStack $stack, array $children = []): void |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param string|ProvidesType $type |
||
| 132 | * @return Type|\Railt\Reflection\Contracts\Type |
||
| 133 | * @throws \Railt\Io\Exception\ExternalFileException |
||
| 134 | */ |
||
| 135 | 171 | public static function of($type): Type |
|
| 148 | |||
| 149 | /** |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | public function isDependent(): bool |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param TypeInterface $type |
||
| 159 | * @return bool |
||
| 160 | */ |
||
| 161 | 90 | public function instanceOf(TypeInterface $type): bool |
|
| 167 | |||
| 168 | /** |
||
| 169 | * @param string $type |
||
| 170 | * @return bool |
||
| 171 | */ |
||
| 172 | 171 | public function is(string $type): bool |
|
| 176 | |||
| 177 | /** |
||
| 178 | * @return string |
||
| 179 | */ |
||
| 180 | 171 | public function getName(): string |
|
| 184 | |||
| 185 | /** |
||
| 186 | * @return string |
||
| 187 | */ |
||
| 188 | 146 | public function __toString(): string |
|
| 192 | } |
||
| 193 |
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.