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

CreateEnhancementLog::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Control\StuTime;
8
use Stu\Orm\Entity\CrewSkillInterface;
9
use Stu\Orm\Entity\SkillEnhancementInterface;
10
use Stu\Orm\Repository\SkillEnhancementLogRepositoryInterface;
11
12
class CreateEnhancementLog
13
{
14 3
    public function __construct(
15
        private SkillEnhancementLogRepositoryInterface $skillEnhancementLogRepository,
16
        private StuTime $stuTime
17 3
    ) {}
18
19 2
    public function createEnhancementLog(
20
        CrewSkillInterface $crewSkill,
21
        string $spacecraftName,
22
        SkillEnhancementInterface $enhancement,
23
        int $amount,
24
        CrewSkillLevelEnum $oldRank
0 ignored issues
show
Bug introduced by
The type Stu\Component\Crew\Skill\CrewSkillLevelEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
    ): void {
26
27 2
        $crew = $crewSkill->getCrew();
28
29 2
        $log = $this->skillEnhancementLogRepository
30 2
            ->prototype()
31 2
            ->setUser($crew->getUser())
32 2
            ->setEnhancement($enhancement)
33 2
            ->setCrewName($crew->getName())
34 2
            ->setShipName($spacecraftName)
35 2
            ->setCrewId($crew->getId())
36 2
            ->setExpertise($amount)
37 2
            ->setExpertiseSum($crewSkill->getExpertise())
38 2
            ->setPromotion($this->getPromotion($oldRank, $crewSkill->getRank()))
39 2
            ->setTimestamp($this->stuTime->time());
40
41 2
        $this->skillEnhancementLogRepository->save($log);
42
    }
43
44 2
    private function getPromotion(CrewSkillLevelEnum $oldRank, CrewSkillLevelEnum $newRank): ?string
45
    {
46 2
        return $oldRank !== $newRank
47 1
            ? sprintf('Beförderung %s -> %s', $oldRank->getDescription(), $newRank->getDescription())
48 2
            : null;
49
    }
50
}
51