Passed
Push — dev ( 72e750...cd9670 )
by Nico
25:25 queued 15:41
created

AbstractVisualPanel::getViewportPerColumn()   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<int, VisualPanelRow> */
18
    private ?array $extendedrows = null;
19
20
    /** @var null|array<array{value: int}> */
21
    protected ?array $headRow = null;
22
23
    /** @var null|array<array{value: int}> */
24
    protected ?array $extendedheadRow = null;
25
26
    private ?float $viewport = null;
27
28
    private ?string $viewportPerColumn = null;
29
30
    private ?string $viewportForFont = null;
31
32 1
    public function __construct(
33
        LoggerUtilInterface $loggerUtil
34
    ) {
35 1
        $this->loggerUtil = $loggerUtil;
36
    }
37
38
    /**
39
     * @return array<array{value: int}>
40
     */
41
    public abstract function getHeadRow(): array;
42
43
    /**
44
     * @return array<int, VisualPanelRow>
45
     */
46
    public function getRows(): array
47
    {
48
        if ($this->rows === null) {
49
            $this->rows = $this->loadLSS();
50
        }
51
        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...
52
    }
53
54
    public function getExtendedRows(): array
55
    {
56
        if ($this->extendedrows === null) {
57
            $this->extendedrows = $this->loadExtendedLSS();
58
        }
59
        return $this->extendedrows;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->extendedrows 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...
60
    }
61
62
63
    /**
64
     * @return array<VisualPanelRow>
65
     */
66
    protected abstract function loadLSS(): array;
67
68
    /**
69
     * @return array<VisualPanelRow>
70
     */
71
    protected abstract function loadExtendedLSS(): array;
72
73
    protected abstract function getPanelViewportPercentage(): int;
74
75
    private function getViewport(): float
76
    {
77
        if ($this->viewport === null) {
78
            $navPercentage = 100;
79
            $perColumn = $navPercentage / count($this->getHeadRow());
80
            $this->viewport = min($perColumn, 1.7);
81
        }
82
        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...
83
    }
84
85
    public function getViewportPerColumn(): string
86
    {
87
        if ($this->viewportPerColumn === null) {
88
            $this->viewportPerColumn = number_format($this->getViewport(), 1);
89
        }
90
        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...
91
    }
92
93
    public function getViewportForFont(): string
94
    {
95
        if ($this->viewportForFont === null) {
96
            $this->viewportForFont = number_format($this->getViewport() / 2, 1);
97
        }
98
        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...
99
    }
100
}
101