FlashTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A flash() 0 3 1
A flashes() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\Session\Flash;
6
7
use Jasny\Session\SessionInterface;
8
9
/**
10
 * Trait for flash messages.
11
 */
12
trait FlashTrait
13
{
14
    protected FlashBag $flashBag;
15
16
    /**
17
     * Add a flash message.
18
     *
19
     * @param string $type         flash type, eg. 'error', 'notice' or 'success'
20
     * @param string $message      flash message
21
     * @param string $contentType  mime, eg 'text/plain' or 'text/html'
22
     */
23 1
    public function flash(string $type, string $message, string $contentType = 'text/plain'): void
24
    {
25 1
        $this->flashes()->add($type, $message, $contentType);
26 1
    }
27
28
    /**
29
     * Get the bag with flash messages.
30
     */
31 2
    public function flashes(): FlashBag
32
    {
33
        /** @var SessionInterface $session */
34 2
        $session = $this;
35 2
        $this->flashBag = $this->flashBag->withSession($session);
36
37 2
        return $this->flashBag;
38
    }
39
}
40