1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Component\Player\Deletion\Handler; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Stu\Component\Alliance\AllianceEnum; |
|
|
|
|
10
|
|
|
use Stu\Module\Alliance\Lib\AllianceActionManagerInterface; |
11
|
|
|
use Stu\Orm\Entity\UserInterface; |
12
|
|
|
use Stu\Orm\Repository\AllianceJobRepositoryInterface; |
13
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
14
|
|
|
|
15
|
|
|
final class AllianceDeletionHandler implements PlayerDeletionHandlerInterface |
16
|
|
|
{ |
17
|
4 |
|
public function __construct(private AllianceJobRepositoryInterface $allianceJobRepository, private AllianceActionManagerInterface $allianceActionManager, private UserRepositoryInterface $userRepository) {} |
18
|
|
|
|
19
|
3 |
|
#[Override] |
20
|
|
|
public function delete(UserInterface $user): void |
21
|
|
|
{ |
22
|
3 |
|
foreach ($this->allianceJobRepository->getByUser($user->getId()) as $job) { |
23
|
3 |
|
if ($job->getType() === AllianceEnum::ALLIANCE_JOBS_FOUNDER) { |
24
|
|
|
|
25
|
2 |
|
$alliance = $job->getAlliance(); |
26
|
2 |
|
$successor = $alliance->getSuccessor(); |
27
|
2 |
|
$diplomatic = $alliance->getDiplomatic(); |
28
|
|
|
|
29
|
2 |
|
$members = $alliance->getMembers(); |
30
|
2 |
|
$members->removeElement($user); |
31
|
2 |
|
$user->setAlliance(null); |
32
|
2 |
|
$this->userRepository->save($user); |
33
|
|
|
|
34
|
2 |
|
$lastonlinemember = $this->getLastOnlineMember($members); |
|
|
|
|
35
|
|
|
|
36
|
2 |
|
if ($successor === null && $lastonlinemember === null) { |
37
|
1 |
|
$this->allianceJobRepository->delete($job); |
38
|
1 |
|
$this->allianceActionManager->delete($alliance); |
39
|
|
|
} |
40
|
2 |
|
if ($successor !== null) { |
41
|
1 |
|
$successorUserId = $successor->getUserId(); |
42
|
|
|
|
43
|
1 |
|
$this->allianceActionManager->setJobForUser( |
44
|
1 |
|
$alliance->getId(), |
45
|
1 |
|
$successorUserId, |
46
|
1 |
|
AllianceEnum::ALLIANCE_JOBS_FOUNDER |
47
|
1 |
|
); |
48
|
1 |
|
$this->allianceJobRepository->delete($successor); |
49
|
|
|
} |
50
|
2 |
|
if ($successor == null && $lastonlinemember != null) { |
51
|
|
|
if ($diplomatic !== null && $lastonlinemember == $diplomatic->getUser()) { |
52
|
|
|
$this->allianceJobRepository->delete($diplomatic); |
53
|
|
|
} |
54
|
|
|
$this->allianceActionManager->setJobForUser( |
55
|
|
|
$alliance->getId(), |
56
|
|
|
$lastonlinemember->getId(), |
57
|
|
|
AllianceEnum::ALLIANCE_JOBS_FOUNDER |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} else { |
61
|
1 |
|
$this->allianceJobRepository->delete($job); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param Collection<int, UserInterface> $members |
68
|
|
|
*/ |
69
|
2 |
|
private function getLastOnlineMember(Collection $members): ?UserInterface |
70
|
|
|
{ |
71
|
2 |
|
$lastOnlineMember = null; |
72
|
2 |
|
$maxLastAction = 0; |
73
|
|
|
|
74
|
2 |
|
foreach ($members as $member) { |
75
|
|
|
if ($member->getLastAction() > $maxLastAction) { |
76
|
|
|
$maxLastAction = $member->getLastAction(); |
77
|
|
|
$lastOnlineMember = $member; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
return $lastOnlineMember; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths