BaseController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 14
c 1
b 0
f 0
dl 0
loc 77
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getTranslator() 0 3 1
A getSubscribedServices() 0 6 1
A displayError() 0 3 1
A displaySuccess() 0 3 1
A displayFlash() 0 6 2
A getIndexBreadcrumbs() 0 3 1
A displayInfo() 0 3 1
A render() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Controller\Base;
13
14
use App\Model\Breadcrumb;
15
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
18
use Symfony\Contracts\Translation\TranslatorInterface;
19
20
class BaseController extends AbstractController
21
{
22
    public static function getSubscribedServices()
23
    {
24
        return parent::getSubscribedServices() +
25
            [
26
                'security.token_storage' => TokenStorageInterface::class,
27
                'translator' => TranslatorInterface::class,
28
            ];
29
    }
30
31
    /**
32
     * @return TranslatorInterface
33
     */
34
    protected function getTranslator()
35
    {
36
        return $this->get('translator');
37
    }
38
39
    /**
40
     * @param string $message the translation message to display
41
     * @param string $link
42
     */
43
    protected function displayError($message, $link = null)
44
    {
45
        $this->displayFlash('danger', $message, $link);
46
    }
47
48
    /**
49
     * @param string $message the translation message to display
50
     * @param string $link
51
     */
52
    protected function displaySuccess($message, $link = null)
53
    {
54
        $this->displayFlash('success', $message, $link);
55
    }
56
57
    /**
58
     * @param string $message the translation message to display
59
     * @param string $link
60
     */
61
    protected function displayInfo($message, $link = null)
62
    {
63
        $this->displayFlash('info', $message, $link);
64
    }
65
66
    /**
67
     * @param $type
68
     * @param $message
69
     * @param string $link
70
     */
71
    private function displayFlash($type, $message, $link = null)
72
    {
73
        if (null !== $link) {
74
            $message = '<a href="' . $link . '">' . $message . '</a>';
75
        }
76
        $this->get('session')->getFlashBag()->set($type, $message);
77
    }
78
79
    /**
80
     * @return Breadcrumb[]|array
81
     */
82
    protected function getIndexBreadcrumbs()
83
    {
84
        return [];
85
    }
86
87
    /**
88
     * Renders a view.
89
     *
90
     * @param Breadcrumb[] $breadcrumbs
91
     */
92
    protected function render(string $view, array $parameters = [], Response $response = null, array $breadcrumbs = []): Response
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

92
    protected function render(string $view, array $parameters = [], /** @scrutinizer ignore-unused */ Response $response = null, array $breadcrumbs = []): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        $parameters['breadcrumbs'] = array_merge($this->getIndexBreadcrumbs(), $breadcrumbs);
95
96
        return parent::render($view, $parameters);
97
    }
98
}
99