Skip to content

Commit 0c748f5

Browse files
committed
Fix inconsistent type-hint declaration
If 1 argument $validator in the constructor is null, it throws an error, which shouldn't be the case
1 parent 0fa04c2 commit 0c748f5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Transformer/ArgumentsTransformer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
class ArgumentsTransformer
2828
{
2929
protected PropertyAccessor $accessor;
30-
protected ValidatorInterface $validator;
30+
protected ?ValidatorInterface $validator;
3131
protected array $classesMap;
3232

33-
public function __construct(ValidatorInterface $validator, array $classesMap = [])
33+
public function __construct(ValidatorInterface $validator = null, array $classesMap = [])
3434
{
3535
$this->validator = $validator;
3636
$this->accessor = PropertyAccess::createPropertyAccessor();
@@ -67,7 +67,7 @@ private function getType(string $type, ResolveInfo $info): ?Type
6767
private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $info)
6868
{
6969
if (null === $data) {
70-
return $data;
70+
return null;
7171
}
7272

7373
if ($type instanceof NonNull) {
@@ -137,7 +137,7 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info
137137

138138
$result = $this->populateObject($this->getType($type, $info), $data, $isMultiple, $info);
139139

140-
if ($this->validator) {
140+
if (null !== $this->validator) {
141141
$errors = new ConstraintViolationList();
142142
if (is_object($result)) {
143143
$errors = $this->validator->validate($result);
@@ -152,7 +152,7 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info
152152
}
153153
}
154154

155-
if (count($errors) > 0) {
155+
if ($errors->count() > 0) {
156156
throw new InvalidArgumentError($argName, $errors);
157157
}
158158
}

0 commit comments

Comments
 (0)