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 |
||
| 17 | class InputValueType extends AbstractObjectType |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param AbstractSchema|Field $value |
||
| 21 | * |
||
| 22 | * @return TypeInterface |
||
| 23 | */ |
||
| 24 | 2 | public function resolveType($value) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @param AbstractSchema|Field $value |
||
| 31 | * |
||
| 32 | * @return string|null |
||
| 33 | */ |
||
| 34 | 3 | public function resolveDefaultValue($value) |
|
| 40 | |||
| 41 | 5 | View Code Duplication | public function build($config) |
| 56 | |||
| 57 | /** |
||
| 58 | * @return string type name |
||
| 59 | */ |
||
| 60 | 7 | public function getName() |
|
| 64 | } |
||
| 65 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: