AbstractMagisController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderPhpView() 0 12 2
A getSubscribedServices() 0 6 1
1
<?php
2
3
namespace pjpawel\Magis\MagisBundle\Controller;
4
5
use pjpawel\Magis\ViewDispatcherService;
6
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * @codeCoverageIgnore
11
 *
12
 * @author Paweł Podgórski <[email protected]>
13
 */
14
class AbstractMagisController extends AbstractController
15
{
16
17
    /**
18
     * @param string $view
19
     * @param array<string,mixed> $parameters
20
     * @param Response|null $response
21
     * @return Response
22
     * @throws \Psr\Container\ContainerExceptionInterface
23
     * @throws \Psr\Container\NotFoundExceptionInterface
24
     */
25
    protected function renderPhpView(string $view, array $parameters = [], Response $response = null): Response
26
    {
27
        /** @var ViewDispatcherService $magis */
28
        $magis = $this->container->get('magis');
29
        $content = $magis->render($view, $parameters);
30
31
        if (null === $response) {
32
            $response = new Response();
33
        }
34
35
        $response->setContent($content);
36
        return $response;
37
    }
38
39
    public static function getSubscribedServices(): array
40
    {
41
        return array_merge(
42
            parent::getSubscribedServices(),
43
            [
44
                'magis' => ViewDispatcherService::class
45
            ]
46
        );
47
    }
48
49
50
}