Passed
Pull Request — dev (#2038)
by Janko
10:55
created

CrewEnhancement::addExpertise()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 10
nop 3
dl 0
loc 29
ccs 17
cts 17
cp 1
crap 6
rs 9.1111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Crew\Skill;
6
7
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
8
use Stu\Orm\Entity\SpacecraftInterface;
9
10
class CrewEnhancement implements CrewEnhancementInterface
11
{
12 3
    public function __construct(
13
        private SkillEnhancementCacheInterface $skillEnhancementCache,
14
        private RaiseExpertise $raiseExpertise
15 3
    ) {}
16
17 2
    public function addExpertise(
18
        SpacecraftInterface|SpacecraftWrapperInterface $target,
19
        SkillEnhancementEnum $trigger,
20
        int $percentage
21
    ): void {
22
23 2
        $spacecraft = $target instanceof SpacecraftInterface ? $target : $target->get();
24
25 2
        $enhancements = $this->skillEnhancementCache->getSkillEnhancements($trigger);
26 2
        if ($enhancements === null) {
27 1
            return;
28
        }
29
30 1
        foreach ($spacecraft->getCrewAssignments() as $crewAssignment) {
31 1
            $position = $crewAssignment->getPosition();
32 1
            if ($position === null) {
33 1
                continue;
34
            }
35
36 1
            if (!array_key_exists($position->value, $enhancements)) {
37 1
                continue;
38
            }
39
40 1
            $this->raiseExpertise->raiseExpertise(
41 1
                $crewAssignment->getCrew(),
42 1
                $spacecraft,
43 1
                $position,
44 1
                $enhancements[$position->value],
45 1
                $percentage
46 1
            );
47
        }
48
    }
49
}
50