Passed
Push — dev ( cd9670...85e666 )
by Nico
10:06 queued 54s
created

AbstractVisualPanel::getRows()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel;
6
7
use Stu\Lib\Map\VisualPanel\VisualPanelRow;
8
use Stu\Module\Logging\LoggerUtilInterface;
9
10
abstract class AbstractVisualPanel
11
{
12
    protected LoggerUtilInterface $loggerUtil;
13
14
    /** @var null|array<int, VisualPanelRow> */
15
    private ?array $rows = null;
16
17
    /** @var null|array<array{value: int}> */
18
    protected ?array $headRow = null;
19
20
    private ?float $viewport = null;
21
22
    private ?string $viewportPerColumn = null;
23
24
    private ?string $viewportForFont = null;
25
26 1
    public function __construct(
27
        LoggerUtilInterface $loggerUtil
28
    ) {
29 1
        $this->loggerUtil = $loggerUtil;
30
    }
31
32
    /**
33
     * @return array<array{value: int}>
34
     */
35
    public abstract function getHeadRow(): array;
36
37
    /**
38
     * @return array<int, VisualPanelRow>
39
     */
40
    public function getRows(): array
41
    {
42
        if ($this->rows === null) {
43
            $this->rows = $this->loadLSS();
44
        }
45
        return $this->rows;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->rows could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
46
    }
47
48
    /**
49
     * @return array<VisualPanelRow>
50
     */
51
    protected abstract function loadLSS(): array;
52
53
    protected abstract function getPanelViewportPercentage(): int;
54
55
    private function getViewport(): float
56
    {
57
        if ($this->viewport === null) {
58
            $navPercentage = 100;
59
            $perColumn = $navPercentage / count($this->getHeadRow());
60
            $this->viewport = min($perColumn, 1.7);
61
        }
62
        return $this->viewport;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->viewport could return the type null which is incompatible with the type-hinted return double. Consider adding an additional type-check to rule them out.
Loading history...
63
    }
64
65
    public function getViewportPerColumn(): string
66
    {
67
        if ($this->viewportPerColumn === null) {
68
            $this->viewportPerColumn = number_format($this->getViewport(), 1);
69
        }
70
        return $this->viewportPerColumn;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->viewportPerColumn could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
71
    }
72
73
    public function getViewportForFont(): string
74
    {
75
        if ($this->viewportForFont === null) {
76
            $this->viewportForFont = number_format($this->getViewport() / 2, 1);
77
        }
78
        return $this->viewportForFont;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->viewportForFont could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
79
    }
80
}
81