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 |
||
| 18 | abstract class AbstractField implements FieldInterface |
||
| 19 | { |
||
| 20 | |||
| 21 | use FieldsArgumentsAwareObjectTrait, AutoNameTrait; |
||
| 22 | |||
| 23 | protected $isFinal = false; |
||
| 24 | |||
| 25 | protected $_resolve_cache = null; |
||
| 26 | |||
| 27 | 64 | View Code Duplication | public function __construct(array $config = []) |
| 41 | |||
| 42 | /** |
||
| 43 | * @return AbstractObjectType |
||
| 44 | */ |
||
| 45 | abstract public function getType(); |
||
| 46 | |||
| 47 | 61 | public function build(FieldConfig $config) |
|
| 50 | |||
| 51 | 1 | public function setType($type) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param $value |
||
| 58 | * @param array $args |
||
| 59 | * @param ResolveInfo $info |
||
| 60 | * @return mixed |
||
| 61 | */ |
||
| 62 | 3 | public function resolve($value, array $args, ResolveInfo $info) |
|
| 66 | |||
| 67 | 19 | public function getResolveFunction() |
|
| 77 | |||
| 78 | 3 | public function isDeprecated() |
|
| 82 | |||
| 83 | 3 | public function getDeprecationReason() |
|
| 87 | } |
||
| 88 |
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.