Passed
Push — master ( 8cd431...bc71f5 )
by Janko
09:12
created

ModuleScreenTab::getCssClass()   B

Complexity

Conditions 9
Paths 21

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 9.0101

Importance

Changes 0
Metric Value
cc 9
eloc 19
nc 21
nop 0
dl 0
loc 36
ccs 19
cts 20
cp 0.95
crap 9.0101
rs 8.0555
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Lib\ModuleScreen;
4
5
use Stu\Orm\Entity\Module;
6
7
class ModuleScreenTab
8
{
9
    private const string UNSELECTED_CLASS = ' module_selector_unselected';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 9 at column 25
Loading history...
10
11 3
    public function __construct(private ModuleSelectorInterface $moduleSelector) {}
12
13 3
    public function getTabTitle(): string
14
    {
15 3
        return $this->moduleSelector->getModuleDescription();
16
    }
17
18 3
    public function getCssClass(): string
19
    {
20 3
        $class = 'module_selector';
21
22 3
        if ($this->moduleSelector->getAvailableModules() === []) {
23 3
            return $class;
24
        }
25
26 3
        if ($this->moduleSelector->allowEmptySlot()) {
27
28 3
            if ($this->moduleSelector->isEmptySlot()) {
29
                $class .= ' module_selector_skipped';
30 3
            } elseif (!$this->moduleSelector->hasSelectedModule()) {
31 1
                $class .= self::UNSELECTED_CLASS;
32
            }
33
        }
34
35 3
        if ($this->moduleSelector->isMandatory()) {
36
37 3
            $buildplan = $this->moduleSelector->getBuildplan();
38
39 3
            if (!$this->moduleSelector->hasSelectedModule()) {
40 1
                $class .= self::UNSELECTED_CLASS;
41 2
            } elseif ($buildplan !== null) {
42
43
                /** @var Module $mod */
44 2
                $mod = $buildplan->getModulesByType($this->moduleSelector->getModuleType())->first();
45 2
                $commodityId = $mod->getCommodityId();
46
47 2
                $stor = $this->moduleSelector->getHost()->getStorage()[$commodityId] ?? null;
48 2
                if ($stor === null) {
49 2
                    $class .= self::UNSELECTED_CLASS;
50
                }
51
            }
52
        }
53 3
        return $class;
54
    }
55
}
56