-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCreateEnhancementLog.php
More file actions
50 lines (41 loc) · 1.54 KB
/
CreateEnhancementLog.php
File metadata and controls
50 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Stu\Component\Crew\Skill;
use Stu\Module\Control\StuTime;
use Stu\Orm\Entity\CrewSkillInterface;
use Stu\Orm\Entity\SkillEnhancementInterface;
use Stu\Orm\Repository\SkillEnhancementLogRepositoryInterface;
class CreateEnhancementLog
{
public function __construct(
private SkillEnhancementLogRepositoryInterface $skillEnhancementLogRepository,
private StuTime $stuTime
) {}
public function createEnhancementLog(
CrewSkillInterface $crewSkill,
string $spacecraftName,
SkillEnhancementInterface $enhancement,
int $amount,
CrewSkillLevelEnum $oldRank
): void {
$crew = $crewSkill->getCrew();
$log = $this->skillEnhancementLogRepository
->prototype()
->setUser($crew->getUser())
->setEnhancement($enhancement)
->setCrewName($crew->getName())
->setShipName($spacecraftName)
->setCrewId($crew->getId())
->setExpertise($amount)
->setExpertiseSum($crewSkill->getExpertise())
->setPromotion($this->getPromotion($oldRank, $crewSkill->getRank()))
->setTimestamp($this->stuTime->time());
$this->skillEnhancementLogRepository->save($log);
}
private function getPromotion(CrewSkillLevelEnum $oldRank, CrewSkillLevelEnum $newRank): ?string
{
return $oldRank !== $newRank
? sprintf('Beförderung %s -> %s', $oldRank->getDescription(), $newRank->getDescription())
: null;
}
}