Issues (26)

src/AppBundle/Controller/ControllerUtilsTrait.php (1 issue)

Labels
Severity
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
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