Passed
Push — master ( 8242d2...71bfa3 )
by Arnold
05:32
created

FlashTrait::flash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
12
trait FlashTrait
13
{
14
    protected FlashBag $flashes;
15
16
    /**
17
     * Add a flash message.
18
     *
19
     * @param string $type         flash type, eg. 'error', 'notice' or 'success'
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 9 found
Loading history...
20
     * @param string $message      flash message
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter name; 6 found
Loading history...
21
     * @param string $contentType  mime, eg 'text/plain' or 'text/html'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
22
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
23
    public function flash(string $type, string $message, string $contentType = 'text/plain'): void
24
    {
25
        $this->flashes()->add($type, $message, $contentType);
26
    }
27
28
    /**
29
     * Get the bag with flash messages.
30
     *
31
     * @return FlashBag
32
     */
33
    public function flashes(): FlashBag
34
    {
35
        /** @var SessionInterface $session */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
36
        $session = $this;
37
        $this->flashes = $this->flashes->withSession($session);
38
39
        return $this->flashes;
40
    }
41
}
42