1 | <?php |
||
15 | class Controller extends ServiceDefinition |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @param ReflectionClass $reflectionClass |
||
20 | * @param ControllerAnnotation|Service $annotation |
||
21 | * @param Definition $definition |
||
22 | * @return array |
||
23 | */ |
||
24 | 1 | public function build(ReflectionClass $reflectionClass, Service $annotation, Definition $definition) |
|
25 | { |
||
26 | /** @var Definition $definition */ |
||
27 | 1 | [, $definition] = parent::build( |
|
28 | $reflectionClass, |
||
29 | $annotation, |
||
30 | 1 | $definition |
|
31 | ); |
||
32 | 1 | $serviceId = $reflectionClass->getName(); |
|
33 | |||
34 | 1 | $definition->addTag(ControllerCompilerPass::CONTROLLER_TAG); |
|
35 | 1 | $definition->setPublic(false); |
|
36 | 1 | $definition->setShared(false); |
|
37 | |||
38 | 1 | foreach ($reflectionClass->getMethods() as $method) { |
|
39 | /** @var Route $routeAnnotation */ |
||
40 | 1 | $routeAnnotation = $this->reader->getMethodAnnotation( |
|
41 | $method, |
||
42 | 1 | Route::class |
|
43 | ); |
||
44 | |||
45 | 1 | if ($routeAnnotation) { |
|
46 | 1 | $this->handleRouteAnnotation( |
|
47 | 1 | $annotation, |
|
|
|||
48 | 1 | $method, |
|
49 | 1 | $routeAnnotation, |
|
50 | 1 | $serviceId, |
|
51 | 1 | $definition |
|
52 | ); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | 1 | return [$serviceId, $definition]; |
|
57 | } |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @param Route $routeAnnotation |
||
62 | * @param ReflectionMethod $method |
||
63 | * @param string $serviceId |
||
64 | * @param Guest $guestAnnotation |
||
65 | * @param Role $roleAnnotation |
||
66 | */ |
||
67 | 1 | protected function setDefaults( |
|
90 | |||
91 | /** |
||
92 | * @param ControllerAnnotation $annotation |
||
93 | * @param ReflectionMethod $method |
||
94 | * @param Route $routeAnnotation |
||
95 | * @param string $serviceId |
||
96 | * @param Definition $definition |
||
97 | */ |
||
98 | 1 | private function handleRouteAnnotation( |
|
124 | } |
||
125 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.