TableHandler::setModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jidaikobo\Kontiki\Handlers;
4
5
use Jidaikobo\Kontiki\Models\ModelInterface;
6
use Jidaikobo\Kontiki\Utils\MessageUtils;
7
8
class TableHandler
9
{
10
    private ?ModelInterface $model = null;
11
    private string $tableHtml = '';
12
13
    public function setModel(ModelInterface $model): void
14
    {
15
        $this->model = $model;
16
    }
17
    public function setHtml(string $html): void
18
    {
19
        $this->tableHtml = $html;
20
    }
21
22
    public function addErrors(array $errors): void
23
    {
24
        if (empty($errors)) {
25
            return;
26
        }
27
        $this->tableHtml = MessageUtils::errorHtml($errors, $this->model) . $this->tableHtml;
0 ignored issues
show
Bug introduced by
It seems like $this->model can also be of type null; however, parameter $model of Jidaikobo\Kontiki\Utils\MessageUtils::errorHtml() does only seem to accept Jidaikobo\Kontiki\Models\ModelInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

27
        $this->tableHtml = MessageUtils::errorHtml($errors, /** @scrutinizer ignore-type */ $this->model) . $this->tableHtml;
Loading history...
28
    }
29
30
    public function addSuccessMessages(array $successMessages): void
31
    {
32
        if (empty($successMessages)) {
33
            return;
34
        }
35
        $successMessage = join($successMessages);
0 ignored issues
show
Bug introduced by
The call to join() has too few arguments starting with array. ( Ignorable by Annotation )

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

35
        $successMessage = /** @scrutinizer ignore-call */ join($successMessages);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
36
        $this->tableHtml = MessageUtils::alertHtml($successMessage) . $this->tableHtml;
37
    }
38
39
    public function getHtml(): string
40
    {
41
        return $this->tableHtml;
42
    }
43
}
44