1 | <?php |
||
21 | abstract class AbstractInputObjectType extends AbstractType |
||
22 | { |
||
23 | |||
24 | use AutoNameTrait, FieldsAwareObjectTrait; |
||
25 | |||
26 | protected $isBuilt = false; |
||
27 | |||
28 | 7 | public function getConfig() |
|
29 | { |
||
30 | 7 | if (!$this->isBuilt) { |
|
31 | 7 | $this->isBuilt = true; |
|
32 | 7 | $this->build($this->config); |
|
|
|||
33 | } |
||
34 | |||
35 | 7 | return $this->config; |
|
36 | } |
||
37 | |||
38 | 1 | public function __construct($config = []) |
|
39 | { |
||
40 | 1 | if (empty($config)) { |
|
41 | $config = [ |
||
42 | 1 | 'name' => $this->getName() |
|
43 | ]; |
||
44 | } |
||
45 | 1 | $this->config = new InputObjectTypeConfig($config, $this); |
|
46 | 1 | } |
|
47 | |||
48 | /** |
||
49 | * @param InputObjectTypeConfig $config |
||
50 | */ |
||
51 | abstract public function build($config); |
||
52 | |||
53 | 7 | public function isValidValue($value) |
|
54 | { |
||
55 | 7 | if ($value instanceof InputObject) { |
|
56 | $value = $value->getValue(); |
||
57 | } |
||
58 | |||
59 | 7 | if (empty($value)) { |
|
60 | 1 | return true; |
|
61 | } |
||
62 | |||
63 | 6 | if (!is_array($value)) { |
|
64 | 1 | return false; |
|
65 | } |
||
66 | |||
67 | 6 | $typeConfig = $this->getConfig(); |
|
68 | 6 | $requiredFields = array_filter($typeConfig->getFields(), function (FieldInterface $field) { |
|
69 | 6 | return $field->getType()->getKind() == TypeMap::KIND_NON_NULL; |
|
70 | 6 | }); |
|
71 | |||
72 | 6 | foreach ($value as $valueKey => $valueItem) { |
|
73 | 6 | if (!$typeConfig->hasField($valueKey)) { |
|
74 | // Schema validation will generate the error message for us. |
||
75 | return false; |
||
76 | } |
||
77 | |||
78 | 6 | $field = $typeConfig->getField($valueKey); |
|
79 | 6 | if (!$field->getType()->isValidValue($valueItem)) { |
|
80 | 3 | $error = $field->getType()->getLastError() ?: '(no details available)'; |
|
81 | 3 | $this->lastError = sprintf('Not valid type for field "%s" in input type "%s": %s', $field->getName(), $this->getName(), $error); |
|
82 | 3 | return false; |
|
83 | } |
||
84 | |||
85 | 5 | if (array_key_exists($valueKey, $requiredFields)) { |
|
86 | 5 | unset($requiredFields[$valueKey]); |
|
87 | } |
||
88 | } |
||
89 | 5 | if (count($requiredFields)) { |
|
90 | 1 | $this->lastError = sprintf('%s %s required on %s', implode(', ', array_keys($requiredFields)), count($requiredFields) > 1 ? 'are' : 'is', $typeConfig->getName()); |
|
91 | } |
||
92 | |||
93 | 5 | return !(count($requiredFields) > 0); |
|
94 | } |
||
95 | |||
96 | 8 | public function getKind() |
|
100 | |||
101 | 2 | public function isInputType() |
|
105 | |||
106 | 4 | public function parseValue($value) |
|
127 | |||
128 | } |
||
129 |
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: