Passed
Push — dev ( 7914d2...bbc331 )
by Janko
10:29
created

ModuleScreenTab   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 45
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTabTitle() 0 3 1
A __construct() 0 1 1
B getCssClass() 0 36 9
1
<?php
2
3
namespace Stu\Lib\ModuleScreen;
4
5
use Stu\Orm\Entity\Module;
6
7
class ModuleScreenTab
8
{
9 3
    public function __construct(private ModuleSelectorInterface $moduleSelector) {}
10
11 3
    public function getTabTitle(): string
12
    {
13 3
        return $this->moduleSelector->getModuleDescription();
14
    }
15
16 3
    public function getCssClass(): string
17
    {
18 3
        $class = 'module_selector';
19
20 3
        if ($this->moduleSelector->getAvailableModules() === []) {
21 3
            return $class;
22
        }
23
24 3
        if ($this->moduleSelector->allowEmptySlot()) {
25
26 3
            if ($this->moduleSelector->isEmptySlot()) {
27
                $class .= ' module_selector_skipped';
28 3
            } elseif (!$this->moduleSelector->hasSelectedModule()) {
29 1
                $class .= ' module_selector_unselected';
30
            }
31
        }
32
33 3
        if ($this->moduleSelector->isMandatory()) {
34
35 3
            $buildplan = $this->moduleSelector->getBuildplan();
36
37 3
            if (!$this->moduleSelector->hasSelectedModule()) {
38 1
                $class .= ' module_selector_unselected';
39 2
            } elseif ($buildplan !== null) {
40
41
                /** @var Module $mod */
42 2
                $mod = $buildplan->getModulesByType($this->moduleSelector->getModuleType())->first();
43 2
                $commodityId = $mod->getCommodityId();
44
45 2
                $stor = $this->moduleSelector->getHost()->getStorage()[$commodityId] ?? null;
46 2
                if ($stor === null) {
47 2
                    $class .= ' module_selector_unselected';
48
                }
49
            }
50
        }
51 3
        return $class;
52
    }
53
}
54