Passed
Push — dev ( 709bf3...12fc43 )
by Nico
10:02
created

SignaturePanelEntry::getLayer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Admin\View\ShowSignatures;
6
7
class SignaturePanelEntry
8
{
9
    private $data = [];
10
11
    private ?int $row = null;
12
13
    public function __construct(&$entry = [])
14
    {
15
        $this->data = $entry;
16
    }
17
18
    public function getPosX(): int
19
    {
20
        return $this->data['posx'];
21
    }
22
23
    public function getPosY(): int
24
    {
25
        return $this->data['posy'];
26
    }
27
28
    public function getMapfieldType(): int
29
    {
30
        return $this->data['type'];
31
    }
32
33
    public function getLayer(): int
34
    {
35
        return $this->data['layer'];
36
    }
37
38
    public function getShipCount(): int
39
    {
40
        return $this->data['shipcount'];
41
    }
42
43
    public function hasShips(): bool
44
    {
45
        return $this->data['shipcount'] > 0;
46
    }
47
48
    public function getSubspaceCode(): ?string
49
    {
50
        $code = sprintf('%d%d%d%d', $this->getCode('d1c'), $this->getCode('d2c'), $this->getCode('d3c'), $this->getCode('d4c'));
51
        return $code == '0000' ? null : $code;
52
    }
53
54
    private function getCode(string $column): int
55
    {
56
        $shipCount = $this->data[$column] ?? 0;
57
58
        if ($shipCount == 0) {
59
            return 0;
60
        }
61
        if ($shipCount == 1) {
62
            return 1;
63
        }
64
        if ($shipCount < 6) {
65
            return 2;
66
        }
67
        if ($shipCount < 11) {
68
            return 3;
69
        }
70
        if ($shipCount < 21) {
71
            return 4;
72
        }
73
74
        return 5;
75
    }
76
77
    public function getDisplayCount(): string
78
    {
79
        if ($this->hasShips()) {
80
            return strval($this->getShipCount());
81
        }
82
        return "";
83
    }
84
85
    public function getCacheValue(): string
86
    {
87
        return $this->getPosX() . "_" . $this->getPosY() . "_" . $this->getMapfieldType() . "_" . $this->getLayer() . "_" . $this->getDisplayCount();
88
    }
89
90
    public $currentShipPosX = null;
91
    public $currentShipPosY = null;
92
93
    private $cssClass = 'lss';
94
95
    public function setCSSClass(string $class): void
96
    {
97
        $this->cssClass = $class;
98
    }
99
100
    public function getCSSClass(): string
101
    {
102
        return $this->cssClass;
103
    }
104
105
    public function getRow(): ?int
106
    {
107
        return $this->row;
108
    }
109
110
    public function setRow(int $row): void
111
    {
112
        $this->row = $row;
113
    }
114
}
115