1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * (c) FSi sp. z o.o. <[email protected]> |
||||
5 | * |
||||
6 | * For the full copyright and license information, please view the LICENSE |
||||
7 | * file that was distributed with this source code. |
||||
8 | */ |
||||
9 | |||||
10 | declare(strict_types=1); |
||||
11 | |||||
12 | namespace FSi\Bundle\AdminBundle\Controller; |
||||
13 | |||||
14 | use FSi\Bundle\AdminBundle\Admin\Context\ContextManager; |
||||
15 | use FSi\Bundle\AdminBundle\Admin\Element; |
||||
16 | use FSi\Bundle\AdminBundle\Event\AdminEvent; |
||||
17 | use FSi\Bundle\AdminBundle\Event\AdminEvents; |
||||
18 | use FSi\Bundle\AdminBundle\Exception\ContextException; |
||||
19 | use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
||||
20 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||||
21 | use Symfony\Component\HttpFoundation\Request; |
||||
22 | use Symfony\Component\HttpFoundation\Response; |
||||
23 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||||
24 | |||||
25 | abstract class ControllerAbstract |
||||
26 | { |
||||
27 | /** |
||||
28 | * @var EngineInterface |
||||
29 | */ |
||||
30 | protected $templating; |
||||
31 | |||||
32 | /** |
||||
33 | * @var ContextManager |
||||
34 | */ |
||||
35 | protected $contextManager; |
||||
36 | |||||
37 | /** |
||||
38 | * @var EventDispatcherInterface |
||||
39 | */ |
||||
40 | private $eventDispatcher; |
||||
41 | |||||
42 | public function __construct( |
||||
43 | EngineInterface $templating, |
||||
44 | ContextManager $contextManager, |
||||
45 | EventDispatcherInterface $eventDispatcher |
||||
46 | ) { |
||||
47 | $this->templating = $templating; |
||||
48 | $this->contextManager = $contextManager; |
||||
49 | $this->eventDispatcher = $eventDispatcher; |
||||
50 | } |
||||
51 | |||||
52 | protected function handleRequest(Element $element, Request $request, string $route): Response |
||||
53 | { |
||||
54 | $event = new AdminEvent($element, $request); |
||||
55 | $this->eventDispatcher->dispatch(AdminEvents::CONTEXT_PRE_CREATE, $event); |
||||
0 ignored issues
–
show
FSi\Bundle\AdminBundle\E...nts::CONTEXT_PRE_CREATE of type string is incompatible with the type object expected by parameter $event of Symfony\Contracts\EventD...erInterface::dispatch() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
56 | if ($event->hasResponse()) { |
||||
57 | return $event->getResponse(); |
||||
58 | } |
||||
59 | |||||
60 | $context = $this->contextManager->createContext($route, $element); |
||||
61 | if (null === $context) { |
||||
62 | throw new NotFoundHttpException(sprintf( |
||||
63 | 'Cannot find context builder that supports element with id "%s"', |
||||
64 | $element->getId() |
||||
65 | )); |
||||
66 | } |
||||
67 | |||||
68 | $response = $context->handleRequest($request); |
||||
69 | if ($response instanceof Response) { |
||||
70 | return $response; |
||||
71 | } |
||||
72 | |||||
73 | if (!$context->hasTemplateName()) { |
||||
74 | throw new ContextException(sprintf( |
||||
75 | 'Context %s neither returned a response nor has a template name', |
||||
76 | get_class($context) |
||||
77 | )); |
||||
78 | } |
||||
79 | |||||
80 | return $this->templating->renderResponse( |
||||
81 | $context->getTemplateName(), |
||||
82 | $context->getData() |
||||
83 | ); |
||||
84 | } |
||||
85 | } |
||||
86 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.