FlashTrait::flash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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