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 |
||
| 20 | class WrapperValidator extends BaseInheritanceValidator |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @param AllowsTypeIndication|TypeDefinition $child |
||
| 24 | * @param AllowsTypeIndication|TypeDefinition $parent |
||
| 25 | * @return bool |
||
| 26 | */ |
||
| 27 | 270 | public function match(TypeDefinition $child, TypeDefinition $parent): bool |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @param AllowsTypeIndication|TypeDefinition $child |
||
| 35 | * @param AllowsTypeIndication|TypeDefinition $parent |
||
| 36 | * @return void |
||
| 37 | * @throws \Railt\SDL\Exceptions\TypeConflictException |
||
| 38 | * @throws \OutOfBoundsException |
||
| 39 | */ |
||
| 40 | 270 | public function validate(TypeDefinition $child, TypeDefinition $parent): void |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param AllowsTypeIndication $child |
||
| 60 | * @param AllowsTypeIndication $parent |
||
| 61 | * @return void |
||
| 62 | * @throws TypeConflictException |
||
| 63 | */ |
||
| 64 | 270 | private function validateListType(AllowsTypeIndication $child, AllowsTypeIndication $parent): void |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Checks the following situations: |
||
| 72 | * <code> |
||
| 73 | * - [Type] overriden by Type |
||
| 74 | * - [Type] overriden by Type! |
||
| 75 | * - [Type]! overriden by Type |
||
| 76 | * - [Type]! overriden by Type! |
||
| 77 | * - [Type!] overriden by Type |
||
| 78 | * - [Type!] overriden by Type! |
||
| 79 | * - [Type!]! overriden by Type |
||
| 80 | * - [Type!]! overriden by Type! |
||
| 81 | * </code> |
||
| 82 | * |
||
| 83 | * @param AllowsTypeIndication $child |
||
| 84 | * @param AllowsTypeIndication $parent |
||
| 85 | * @return void |
||
| 86 | * @throws TypeConflictException |
||
| 87 | */ |
||
| 88 | 270 | View Code Duplication | private function validateListDirectRedefinition(AllowsTypeIndication $child, AllowsTypeIndication $parent): void |
| 97 | |||
| 98 | /** |
||
| 99 | * Checks the following situations: |
||
| 100 | * <code> |
||
| 101 | * - Type overriden by [Type] |
||
| 102 | * - Type! overriden by [Type] |
||
| 103 | * - Type overriden by [Type]! |
||
| 104 | * - Type! overriden by [Type]! |
||
| 105 | * - Type overriden by [Type!] |
||
| 106 | * - Type! overriden by [Type!] |
||
| 107 | * - Type overriden by [Type!]! |
||
| 108 | * - Type! overriden by [Type!]! |
||
| 109 | * </code> |
||
| 110 | * |
||
| 111 | * @param AllowsTypeIndication $child |
||
| 112 | * @param AllowsTypeIndication $parent |
||
| 113 | * @return void |
||
| 114 | * @throws TypeConflictException |
||
| 115 | */ |
||
| 116 | 254 | View Code Duplication | private function validateListInverseRedefinition(AllowsTypeIndication $child, AllowsTypeIndication $parent): void |
| 125 | |||
| 126 | /** |
||
| 127 | * @param AllowsTypeIndication|DependentDefinition $child |
||
| 128 | * @param AllowsTypeIndication|DependentDefinition $parent |
||
| 129 | * @return void |
||
| 130 | * @throws TypeConflictException |
||
| 131 | */ |
||
| 132 | 238 | View Code Duplication | private function validatePostconditionalInheritance(AllowsTypeIndication $child, AllowsTypeIndication $parent): void |
| 146 | |||
| 147 | /** |
||
| 148 | * @param AllowsTypeIndication|DependentDefinition $child |
||
| 149 | * @param AllowsTypeIndication|DependentDefinition $parent |
||
| 150 | * @return void |
||
| 151 | * @throws \Railt\SDL\Exceptions\TypeConflictException |
||
| 152 | */ |
||
| 153 | 56 | View Code Duplication | private function validatePreconditionalInheritance(AllowsTypeIndication $child, AllowsTypeIndication $parent): void |
| 167 | |||
| 168 | /** |
||
| 169 | * @param AllowsTypeIndication $child |
||
| 170 | * @param AllowsTypeIndication $parent |
||
| 171 | * @return bool |
||
| 172 | */ |
||
| 173 | 238 | private function isSameWrapperList(AllowsTypeIndication $child, AllowsTypeIndication $parent): bool |
|
| 177 | } |
||
| 178 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: