27
27
class ArgumentsTransformer
28
28
{
29
29
protected PropertyAccessor $ accessor ;
30
- protected ValidatorInterface $ validator ;
30
+ protected ? ValidatorInterface $ validator ;
31
31
protected array $ classesMap ;
32
32
33
- public function __construct (ValidatorInterface $ validator , array $ classesMap = [])
33
+ public function __construct (ValidatorInterface $ validator = null , array $ classesMap = [])
34
34
{
35
35
$ this ->validator = $ validator ;
36
36
$ this ->accessor = PropertyAccess::createPropertyAccessor ();
@@ -67,7 +67,7 @@ private function getType(string $type, ResolveInfo $info): ?Type
67
67
private function populateObject (Type $ type , $ data , bool $ multiple , ResolveInfo $ info )
68
68
{
69
69
if (null === $ data ) {
70
- return $ data ;
70
+ return null ;
71
71
}
72
72
73
73
if ($ type instanceof NonNull) {
@@ -137,7 +137,7 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info
137
137
138
138
$ result = $ this ->populateObject ($ this ->getType ($ type , $ info ), $ data , $ isMultiple , $ info );
139
139
140
- if ($ this ->validator ) {
140
+ if (null !== $ this ->validator ) {
141
141
$ errors = new ConstraintViolationList ();
142
142
if (is_object ($ result )) {
143
143
$ errors = $ this ->validator ->validate ($ result );
@@ -152,7 +152,7 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info
152
152
}
153
153
}
154
154
155
- if (count ( $ errors ) > 0 ) {
155
+ if ($ errors-> count ( ) > 0 ) {
156
156
throw new InvalidArgumentError ($ argName , $ errors );
157
157
}
158
158
}
0 commit comments