| Conditions | 1 |
| Paths | 1 |
| Total Lines | 28 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | public function build(SchemaConfig $config) |
||
| 21 | { |
||
| 22 | $config->getQuery()->addFields([ |
||
| 23 | 'me' => [ |
||
| 24 | 'type' => new TestObjectType(), |
||
| 25 | 'resolve' => function ($value, $args, ResolveInfo $info) { |
||
| 26 | return $info->getReturnType()->getData(); |
||
|
|
|||
| 27 | } |
||
| 28 | ], |
||
| 29 | 'status' => [ |
||
| 30 | 'type' => new TestEnumType(), |
||
| 31 | 'resolve' => function () { |
||
| 32 | return $this->testStatusValue; |
||
| 33 | } |
||
| 34 | ], |
||
| 35 | ]); |
||
| 36 | $config->getMutation()->addFields([ |
||
| 37 | 'updateStatus' => [ |
||
| 38 | 'type' => new TestEnumType(), |
||
| 39 | 'resolve' => function () { |
||
| 40 | return $this->testStatusValue; |
||
| 41 | }, |
||
| 42 | 'args' => [ |
||
| 43 | 'newStatus' => new TestEnumType() |
||
| 44 | ] |
||
| 45 | ] |
||
| 46 | ]); |
||
| 47 | } |
||
| 48 | |||
| 51 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: