Passed
Pull Request — master (#346)
by Mirko
08:32
created

AbstractController::addErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Legacy\Traits\LegacyTemplateTrait;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
9
class AbstractController extends Controller
10
{
11
    use LegacyTemplateTrait;
12
13
    /**
14
     * Sets the container.
15
     *
16
     * There is no container available in the constructor of a controller, so we override setContainer() and use this
17
     *
18
     * @param \Symfony\Component\DependencyInjection\ContainerInterface|null $container A ContainerInterface instance or null.
19
     *
20
     * @return void
21
     */
22
    public function setContainer(ContainerInterface $container = null)
23
    {
24
        parent::setContainer($container);
25
26
        $requestStack = $container->get('request_stack');
0 ignored issues
show
Bug introduced by
It seems like $container is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
27
        /** @var \Symfony\Component\HttpFoundation\Request $masterRequest */
28
        $masterRequest = $requestStack->getMasterRequest();
29
        if ($masterRequest) {
30
            $this->setTarget($masterRequest->getUri());
31
        }
32
    }
33
34
    /**
35
     * @param string $message
36
     *
37
     * @return void
38
     */
39
    protected function addErrorMessage($message)
40
    {
41
        $this->addFlash('error', $message);
42
    }
43
44
    /**
45
     * @param string $message
46
     *
47
     * @return void
48
     */
49
    protected function addSuccessMessage($message)
50
    {
51
        $this->addFlash('success', $message);
52
    }
53
54
    /**
55
     * @param string $message
56
     *
57
     * @return void
58
     */
59
    protected function addInfoMessage($message)
60
    {
61
        $this->addFlash('info', $message);
62
    }
63
}
64