File tree Expand file tree Collapse file tree 3 files changed +35
-17
lines changed Expand file tree Collapse file tree 3 files changed +35
-17
lines changed Original file line number Diff line number Diff line change 33namespace PHPStan \Type \Symfony ;
44
55use PHPStan \Testing \TypeInferenceTestCase ;
6+ use ReflectionClass ;
67use ReflectionMethod ;
78use Symfony \Component \HttpFoundation \Request ;
89use function class_exists ;
10+ use function method_exists ;
911use function strpos ;
1012
1113class ExtensionTest extends TypeInferenceTestCase
@@ -46,6 +48,11 @@ public function dataFileAsserts(): iterable
4648
4749 if (class_exists ('Symfony\Bundle\FrameworkBundle\Controller\AbstractController ' )) {
4850 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/ExampleAbstractController.php ' );
51+
52+ $ ref = new ReflectionClass ('Symfony\Bundle\FrameworkBundle\Controller\AbstractController ' );
53+ if ($ ref ->hasMethod ('get ' )) {
54+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/ExampleAbstractControllerServices.php ' );
55+ }
4956 }
5057
5158 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/serializer.php ' );
Original file line number Diff line number Diff line change 1010final class ExampleAbstractController extends AbstractController
1111{
1212
13- public function services (): void
14- {
15- assertType ('Foo ' , $ this ->get ('foo ' ));
16- assertType ('Foo ' , $ this ->get ('parameterised_foo ' ));
17- assertType ('Foo\Bar ' , $ this ->get ('parameterised_bar ' ));
18- assertType ('Synthetic ' , $ this ->get ('synthetic ' ));
19- assertType ('object ' , $ this ->get ('bar ' ));
20- assertType ('object ' , $ this ->get (doFoo ()));
21- assertType ('object ' , $ this ->get ());
22-
23- assertType ('true ' , $ this ->has ('foo ' ));
24- assertType ('true ' , $ this ->has ('synthetic ' ));
25- assertType ('false ' , $ this ->has ('bar ' ));
26- assertType ('bool ' , $ this ->has (doFoo ()));
27- assertType ('bool ' , $ this ->has ());
28- }
29-
3013 public function parameters (ContainerInterface $ container , ParameterBagInterface $ parameterBag ): void
3114 {
3215 assertType ('array|bool|float|int|string|null ' , $ container ->getParameter ('unknown ' ));
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Type \Symfony ;
4+
5+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ final class ExampleAbstractControllerServices extends AbstractController
9+ {
10+
11+ public function services (): void
12+ {
13+ assertType ('Foo ' , $ this ->get ('foo ' ));
14+ assertType ('Foo ' , $ this ->get ('parameterised_foo ' ));
15+ assertType ('Foo\Bar ' , $ this ->get ('parameterised_bar ' ));
16+ assertType ('Synthetic ' , $ this ->get ('synthetic ' ));
17+ assertType ('object ' , $ this ->get ('bar ' ));
18+ assertType ('object ' , $ this ->get (doFoo ()));
19+ assertType ('object ' , $ this ->get ());
20+
21+ assertType ('true ' , $ this ->has ('foo ' ));
22+ assertType ('true ' , $ this ->has ('synthetic ' ));
23+ assertType ('false ' , $ this ->has ('bar ' ));
24+ assertType ('bool ' , $ this ->has (doFoo ()));
25+ assertType ('bool ' , $ this ->has ());
26+ }
27+
28+ }
You can’t perform that action at this time.
0 commit comments