Passed
Push — master ( b68383...74043c )
by Alexander
05:41
created

FlashMessage::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Widget;
6
7
use Yiisoft\Session\Flash\FlashInterface;
8
use Yiisoft\Yii\Bootstrap5\Alert;
9
use Yiisoft\Widget\Widget;
10
11
final class FlashMessage extends Widget
12
{
13
    private FlashInterface $flash;
14
15 6
    public function __construct(FlashInterface $flash)
16
    {
17 6
        $this->flash = $flash;
18 6
    }
19
20 6
    public function run(): string
21
    {
22 6
        $flashes = $this->flash->getAll();
23
24 6
        $html = [];
25 6
        foreach ($flashes as $type => $data) {
26 2
            foreach ($data as $message) {
27 2
                $html[] = Alert::widget()
28 2
                    ->options(['class' => "alert-{$type} shadow"])
0 ignored issues
show
Bug introduced by
The method options() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Form\Widget\Form or Yiisoft\Yii\Bootstrap5\Nav or Yiisoft\Yii\Bootstrap5\Button or Yiisoft\Yii\Bootstrap5\Carousel or Yiisoft\Yii\Bootstrap5\Progress or Yiisoft\Yii\Bootstrap5\Dropdown or Yiisoft\Yii\Bootstrap5\ButtonDropdown or Yiisoft\Yii\Bootstrap5\Tabs or App\Blog\Widget\PostCard or Yiisoft\Yii\Bootstrap5\Accordion or Yiisoft\Yii\Bootstrap5\Breadcrumbs or App\Widget\OffsetPagination or Yiisoft\Yii\Bootstrap5\Modal or Yiisoft\Yii\Bootstrap5\Alert or Yiisoft\Yii\Bootstrap5\NavBar or Yiisoft\Yii\Bootstrap5\ButtonToolbar or Yiisoft\Yii\Bootstrap5\ButtonGroup. ( Ignorable by Annotation )

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

28
                    ->/** @scrutinizer ignore-call */ options(['class' => "alert-{$type} shadow"])
Loading history...
29 2
                    ->body($message['body'])
30
                ;
31
            }
32
        }
33
34 6
        return implode($html);
35
    }
36
}
37