Test Failed
Pull Request — master (#19)
by Flo
03:56
created

FlashMessage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 2
1
<?php
2
/**
3
 * Class FlashMessage | FlashMessagesage.php
4
 * @package Faulancer\View\Helper
5
 * @author  Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\View\Helper;
8
9
use Faulancer\Service\SessionManagerService;
10
use Faulancer\Translate\Translator;
11
use Faulancer\View\AbstractViewHelper;
12
use Faulancer\View\ViewController;
13
14
/**
15
 * Class FlashMessage
16
 */
17
class FlashMessage extends AbstractViewHelper
18
{
19
20
    /**
21
     * @param ViewController $view
22
     * @param string         $key
23
     * @param string         $type
24
     * @return string
25
     */
26
    public function __invoke(ViewController $view, string $key, $type = 'default')
27
    {
28
        $result = '';
29
30
        /** @var Translator $translator */
31
        $translator = $this->getServiceLocator()->get(Translator::class);
32
33
        /** @var SessionManagerService $sessionManager */
34
        $sessionManager = $this->getServiceLocator()->get(SessionManagerService::class);
35
36
        if ($sessionManager->hasFlashMessage($key)) {
37
            $result = '<span class="flash-message ' . $type . '">' . $translator->translate($sessionManager->getFlashMessage($key)) . '</span>';
0 ignored issues
show
Bug introduced by
It seems like $sessionManager->getFlashMessage($key) targeting Faulancer\Session\Sessio...ager::getFlashMessage() can also be of type array or null; however, Faulancer\Translate\Translator::translate() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
38
        }
39
40
        return $result;
41
    }
42
43
}