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 |
||
| 21 | abstract class AbstractUnionType extends AbstractType implements AbstractInterfaceTypeInterface |
||
| 22 | { |
||
| 23 | |||
| 24 | use ConfigAwareTrait, AutoNameTrait; |
||
| 25 | |||
| 26 | protected $isFinal = false; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * ObjectType constructor. |
||
| 30 | * @param $config |
||
| 31 | */ |
||
| 32 | 7 | View Code Duplication | public function __construct($config = []) |
|
|
|||
| 33 | { |
||
| 34 | 7 | if (empty($config)) { |
|
| 35 | 1 | $config['name'] = $this->getName(); |
|
| 36 | 1 | $config['types'] = $this->getTypes(); |
|
| 37 | 1 | } |
|
| 38 | |||
| 39 | 7 | $this->config = new UnionTypeConfig($config, $this, $this->isFinal); |
|
| 40 | 7 | } |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @return AbstractObjectType[]|AbstractScalarType[] |
||
| 44 | */ |
||
| 45 | abstract public function getTypes(); |
||
| 46 | |||
| 47 | 4 | public function getKind() |
|
| 51 | |||
| 52 | 2 | public function getNamedType() |
|
| 56 | |||
| 57 | 3 | public function isValidValue($value) |
|
| 61 | |||
| 62 | } |
||
| 63 |
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.