TableService::tableHtml()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
nop 4
dl 0
loc 12
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Jidaikobo\Kontiki\Services;
4
5
use Jidaikobo\Kontiki\Models\ModelInterface;
6
use Jidaikobo\Kontiki\Renderers\TableRenderer;
7
use Jidaikobo\Kontiki\Handlers\TableHandler;
8
use Slim\Views\PhpRenderer;
9
10
class TableService
11
{
12
    private TableRenderer $tableRenderer;
13
    private TableHandler $tableHandler;
14
    private PhpRenderer $view;
15
    private ?ModelInterface $model = null;
16
17
    public function __construct(
18
        TableRenderer $tableRenderer,
19
        TableHandler $tableHandler,
20
        PhpRenderer $view
21
    ) {
22
        $this->tableRenderer = $tableRenderer;
23
        $this->tableHandler = $tableHandler;
24
        $this->view = $view;
25
    }
26
27
    public function setModel(ModelInterface $model): void
28
    {
29
        $this->model = $model;
30
    }
31
32
    public function tableHtml(
33
        array $data,
34
        string $adminDirName,
35
        array $routes = [],
36
        string $context = 'all'
37
    ): string {
38
        $this->tableRenderer->setModel($this->model);
0 ignored issues
show
Bug introduced by
It seems like $this->model can also be of type null; however, parameter $model of Jidaikobo\Kontiki\Render...bleRenderer::setModel() 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

38
        $this->tableRenderer->setModel(/** @scrutinizer ignore-type */ $this->model);
Loading history...
39
        return $this->tableRenderer->render(
40
            $data,
41
            $adminDirName,
42
            $routes,
43
            $context
44
        );
45
    }
46
47
    public function addMessages(
48
        string $tableHtml,
49
        array $errors,
50
        array $success = []
51
    ): string {
52
        $this->tableHandler->setModel($this->model);
0 ignored issues
show
Bug introduced by
It seems like $this->model can also be of type null; however, parameter $model of Jidaikobo\Kontiki\Handle...ableHandler::setModel() 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

52
        $this->tableHandler->setModel(/** @scrutinizer ignore-type */ $this->model);
Loading history...
53
        $this->tableHandler->setHtml($tableHtml);
54
        $this->tableHandler->addErrors($errors);
55
        $this->tableHandler->addSuccessMessages($success);
56
        return $this->tableHandler->getHtml();
57
    }
58
}
59