ControllerUtilsTrait::flashMessage()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 2
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace AppBundle\Controller;
4
5
trait ControllerUtilsTrait
6
{
7
    public static $flashSuccess = 'success';
8
    public static $flashInfo = 'info';
9
    public static $flashWarning = 'warning';
10
    public static $flashDanger = 'danger';
11
12
    protected function flashMessage($type, $message = null)
13
    {
14
        $supportedTypes = [self::$flashSuccess, self::$flashInfo, self::$flashWarning, self::$flashDanger];
15
        if (!in_array($type, $supportedTypes)) {
16
            throw new \LogicException(sprintf('""%s" type is not supported'));
17
        }
18
        if (!$this->container->has('session')) {
19
            throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
20
        }
21
        if (!$message) {
22
            $message = $this->get('translator')->trans('flash.'.$type.'.message', [], 'common');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

22
            $message = $this->/** @scrutinizer ignore-call */ get('translator')->trans('flash.'.$type.'.message', [], 'common');
Loading history...
23
        }
24
25
        $this->container->get('session')->getFlashBag()->add($type, $message);
26
    }
27
}
28