Passed
Pull Request — master (#2331)
by Janko
11:37 queued 06:03
created

SystemDeactivation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 64.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 29
ccs 11
cts 17
cp 0.6471
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deactivateIntern() 0 23 5
A __construct() 0 3 1
1
<?php
2
3
namespace Stu\Component\Spacecraft\System\Control;
4
5
use Stu\Component\Spacecraft\System\Exception\AlreadyOffException;
6
use Stu\Component\Spacecraft\System\Exception\DeactivationConditionsNotMetException;
7
use Stu\Component\Spacecraft\System\Exception\SystemNotDeactivatableException;
8
use Stu\Component\Spacecraft\System\Exception\SystemNotFoundException;
9
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface;
10
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
11
use Stu\Lib\Information\InformationInterface;
12
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
13
14
class SystemDeactivation
15
{
16 1
    public function __construct(
17
        private readonly SpacecraftSystemManagerInterface $spacecraftSystemManager
18 1
    ) {}
19
20 5
    public function deactivateIntern(
21
        SpacecraftWrapperInterface $wrapper,
22
        spacecraftSystemTypeEnum $type,
23
        InformationInterface $informations
24
    ): bool {
25 5
        $systemName = $type->getDescription();
26 5
        $ship = $wrapper->get();
27
28
        try {
29 5
            $this->spacecraftSystemManager->deactivate($wrapper, $type);
30 3
            $informations->addInformationf(_('%s: System %s deaktiviert'), $ship->getName(), $systemName);
31 3
            return true;
32 3
        } catch (AlreadyOffException) {
33 3
            $informations->addInformationf(_('%s: System %s ist bereits deaktiviert'), $ship->getName(), $systemName);
34
        } catch (SystemNotDeactivatableException) {
35
            $informations->addInformationf(_('%s: [b][color=#ff2626]System %s besitzt keinen Deaktivierungsmodus[/color][/b]'), $ship->getName(), $systemName);
36
        } catch (DeactivationConditionsNotMetException $e) {
37
            $informations->addInformationf(_('%s: [b][color=#ff2626]System %s konnte nicht deaktiviert werden, weil %s[/color][/b]'), $ship->getName(), $systemName, $e->getMessage());
38
        } catch (SystemNotFoundException) {
39
            $informations->addInformationf(_('%s: System %s nicht vorhanden'), $ship->getName(), $systemName);
40
        }
41
42 3
        return false;
43
    }
44
}
45