13
13
14
14
use PhpParser \Builder \Class_ ;
15
15
use PhpParser \Builder \Namespace_ ;
16
+ use PhpParser \BuilderFactory ;
17
+ use PhpParser \Node ;
16
18
use PhpParser \Node \Expr ;
17
19
use PhpParser \ParserFactory ;
20
+ use PhpParser \PrettyPrinter ;
18
21
use Symfony \Component \Serializer \Exception \DenormalizingUnionFailedException ;
19
22
use Symfony \Component \Serializer \Normalizer \DenormalizerAwareInterface ;
20
23
use Symfony \Component \Serializer \Normalizer \DenormalizerInterface ;
21
24
use Symfony \Component \Serializer \Normalizer \NormalizerAwareInterface ;
22
25
use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
23
- use PhpParser \BuilderFactory ;
24
- use PhpParser \PrettyPrinter ;
25
- use PhpParser \Node ;
26
26
27
27
/**
28
28
* The main class to create a new Normalizer from a ClassDefinition.
@@ -42,7 +42,7 @@ public function __construct()
42
42
throw new \LogicException (sprintf ('You cannot use "%s" as the "nikic/php-parser" package is not installed. Try running "composer require nikic/php-parser". ' , static ::class));
43
43
}
44
44
45
- $ this ->factory = new BuilderFactory ;
45
+ $ this ->factory = new BuilderFactory () ;
46
46
$ this ->printer = new PrettyPrinter \Standard ();
47
47
}
48
48
@@ -99,7 +99,6 @@ private function generateNormalizeChildMethod(Namespace_ $namespace, Class_ $cla
99
99
)
100
100
);
101
101
102
-
103
102
// private function normalizeChild(mixed $object, ?string $format, array $context, bool $canBeIterable): mixed;
104
103
$ class ->addStmt ($ this ->factory ->method ('normalizeChild ' )
105
104
->makePrivate ()
@@ -151,7 +150,7 @@ private function generateNormalizeChildMethod(Namespace_ $namespace, Class_ $cla
151
150
new Node \Arg (new Node \Expr \Variable ('context ' )),
152
151
new Node \Arg (new Node \Expr \ConstFetch (new Node \Name ('true ' ))),
153
152
]
154
- )
153
+ ),
155
154
])
156
155
),
157
156
new Node \Arg (new Node \Expr \Variable ('object ' )),
@@ -205,7 +204,6 @@ private function generateDenormalizeChildMethod(Namespace_ $namespace, Class_ $c
205
204
)
206
205
);
207
206
208
-
209
207
// private function denormalizeChild(mixed $data, string $type, ?string $format, array $context, bool $canBeIterable): mixed;
210
208
$ class ->addStmt ($ this ->factory ->method ('denormalizeChild ' )
211
209
->makePrivate ()
@@ -259,7 +257,7 @@ private function generateDenormalizeChildMethod(Namespace_ $namespace, Class_ $c
259
257
new Node \Arg (new Node \Expr \Variable ('context ' )),
260
258
new Node \Arg (new Node \Expr \ConstFetch (new Node \Name ('true ' ))),
261
259
]
262
- )
260
+ ),
263
261
])
264
262
),
265
263
new Node \Arg (new Node \Expr \Variable ('data ' )),
@@ -359,7 +357,7 @@ private function addDenormailizeMethod(ClassDefinition $definition, Namespace_ $
359
357
[new Node \Arg (new Node \Expr \ClassConstFetch (new Node \Name ($ definition ->getSourceClassName ()), 'class ' ))]
360
358
),
361
359
'newInstanceWithoutConstructor '
362
- )));
360
+ )));
363
361
} else {
364
362
$ constructorArguments = [];
365
363
@@ -369,10 +367,10 @@ private function addDenormailizeMethod(ClassDefinition $definition, Namespace_ $
369
367
$ canBeIterable = $ propertyDefinition ->isCollection ();
370
368
371
369
$ defaultValue = $ propertyDefinition ->getConstructorDefaultValue ();
372
- if (is_object ($ defaultValue )) {
370
+ if (\ is_object ($ defaultValue )) {
373
371
// public function __construct($foo = new \stdClass());
374
372
// There is no support for parameters to the object.
375
- $ defaultValue = new Expr \New_ (new Node \Name \FullyQualified (get_class ( $ defaultValue) ));
373
+ $ defaultValue = new Expr \New_ (new Node \Name \FullyQualified ($ defaultValue::class ));
376
374
} else {
377
375
$ defaultValue = $ this ->factory ->val ($ defaultValue );
378
376
}
@@ -427,7 +425,7 @@ private function addDenormailizeMethod(ClassDefinition $definition, Namespace_ $
427
425
$ defaultValue
428
426
)),
429
427
],
430
- 'else ' => new Node \Stmt \Else_ ($ variableOutput )
428
+ 'else ' => new Node \Stmt \Else_ ($ variableOutput ),
431
429
]
432
430
)];
433
431
}
@@ -486,11 +484,9 @@ private function addDenormailizeMethod(ClassDefinition $definition, Namespace_ $
486
484
),
487
485
];
488
486
}
489
-
490
-
491
487
}
492
488
493
- $ result = $ tempVariableName === null ? $ variable : new Node \Expr \Variable ($ tempVariableName );
489
+ $ result = null === $ tempVariableName ? $ variable : new Node \Expr \Variable ($ tempVariableName );
494
490
if (null !== $ method = $ propertyDefinition ->getSetterName ()) {
495
491
$ variableOutput [] = new Node \Stmt \Expression (new Node \Expr \MethodCall (
496
492
new Node \Expr \Variable ('output ' ),
@@ -567,7 +563,7 @@ private function addNormailizeMethod(ClassDefinition $definition, Namespace_ $na
567
563
->addParam ($ this ->factory ->param ('format ' )->setType ('string ' )->setDefault (null ))
568
564
->addParam ($ this ->factory ->param ('context ' )->setType ('array ' )->setDefault ([]))
569
565
->setReturnType ('array|string|int|float|bool|\ArrayObject|null ' )
570
- ->setDocComment (sprintf ('/** ' .PHP_EOL .'* @param %s $object ' .PHP_EOL .'*/ ' , $ definition ->getSourceClassName ()))
566
+ ->setDocComment (sprintf ('/** ' .\ PHP_EOL .'* @param %s $object ' .\ PHP_EOL .'*/ ' , $ definition ->getSourceClassName ()))
571
567
->addStmt (new Node \Stmt \Return_ (new Node \Expr \Array_ ($ bodyArrayItems ))));
572
568
573
569
if ($ needsChildNormalizer ) {
@@ -644,7 +640,7 @@ private function generateCodeToDeserializeMultiplePossibleClasses(array $targetC
644
640
new Node \Expr \ArrayDimFetch (new Node \Expr \Variable ('exceptions ' )),
645
641
new Node \Expr \Variable ('e ' )
646
642
)
647
- )
643
+ ),
648
644
]
649
645
),
650
646
],
@@ -666,11 +662,10 @@ private function generateCodeToDeserializeMultiplePossibleClasses(array $targetC
666
662
]
667
663
)
668
664
),
669
- )
665
+ ),
670
666
],
671
667
]
672
668
),
673
669
];
674
-
675
670
}
676
671
}
0 commit comments