Passed
Push — master ( 66fdc9...e2b180 )
by Alexander
08:00 queued 05:21
created

FlashMessage::withoutCloseButton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Widget;
6
7
use Yiisoft\Yii\Bulma\Message;
8
use Yiisoft\Yii\Web\Flash;
9
10
final class FlashMessage extends \Yiisoft\Widget\Widget
11
{
12
    private Flash $flash;
13
    private bool $withoutCloseButton = false;
14
    private string $size = '';
15
16 8
    public function __construct(Flash $flash)
17
    {
18 8
        $this->flash = $flash;
19 8
    }
20
21 8
    public function run(): string
22
    {
23 8
        $flashes = $this->flash->getAll();
24 8
        $html = '';
25
26 8
        foreach ($flashes as $type => $data) {
27 2
            foreach ($data as $message) {
28 2
                $html .= Message::widget()
29 2
                    ->headerColor($type)
0 ignored issues
show
Bug introduced by
The method headerColor() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Yii\Bulma\Message. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
                    ->/** @scrutinizer ignore-call */ headerColor($type)
Loading history...
30 2
                    ->headerMessage($message['header'] ?? '')
31 2
                    ->body($message['body'] ?? '')
32 2
                    ->withoutCloseButton($this->withoutCloseButton)
33 2
                    ->size($this->size)
34 2
                    ->render();
35
            }
36
        }
37
38 8
        return $html;
39
    }
40
41
    public function withoutCloseButton(bool $value): self
42
    {
43
        $new = clone $this;
44
        $new->withoutCloseButton = $value;
45
        return $new;
46
    }
47
48
    public function size(string $value): self
49
    {
50
        $new = clone $this;
51
        $new->size = $value;
52
        return $new;
53
    }
54
}
55