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
|
|
|
|
14
|
|
|
final class AllianceDeletionHandler implements PlayerDeletionHandlerInterface |
15
|
|
|
{ |
16
|
3 |
|
public function __construct(private AllianceJobRepositoryInterface $allianceJobRepository, private AllianceActionManagerInterface $allianceActionManager) {} |
17
|
|
|
|
18
|
3 |
|
#[Override] |
19
|
|
|
public function delete(UserInterface $user): void |
20
|
|
|
{ |
21
|
3 |
|
foreach ($this->allianceJobRepository->getByUser($user->getId()) as $job) { |
22
|
3 |
|
if ($job->getType() === AllianceEnum::ALLIANCE_JOBS_FOUNDER) { |
23
|
2 |
|
$alliance = $job->getAlliance(); |
24
|
|
|
|
25
|
2 |
|
$successor = $alliance->getSuccessor(); |
26
|
|
|
|
27
|
2 |
|
$diplomatic = $alliance->getDiplomatic(); |
28
|
|
|
|
29
|
2 |
|
$members = $alliance->getMembers(); |
30
|
2 |
|
$members->removeElement($user); |
31
|
|
|
|
32
|
2 |
|
$lastonlinemember = $this->getLastOnlineMember($members); |
|
|
|
|
33
|
|
|
|
34
|
2 |
|
if ($successor === null && $lastonlinemember === null) { |
35
|
1 |
|
$this->allianceJobRepository->delete($job); |
36
|
1 |
|
$this->allianceActionManager->delete($alliance->getId(), true); |
37
|
|
|
} |
38
|
2 |
|
if ($successor !== null) { |
39
|
1 |
|
$successorUserId = $successor->getUserId(); |
40
|
|
|
|
41
|
1 |
|
$this->allianceActionManager->setJobForUser( |
42
|
1 |
|
$alliance->getId(), |
43
|
1 |
|
$successorUserId, |
44
|
1 |
|
AllianceEnum::ALLIANCE_JOBS_FOUNDER |
45
|
1 |
|
); |
46
|
1 |
|
$this->allianceJobRepository->delete($successor); |
47
|
|
|
} |
48
|
2 |
|
if ($successor == null && $lastonlinemember != null) { |
49
|
|
|
if ($diplomatic !== null && $lastonlinemember == $diplomatic->getUser()) { |
50
|
|
|
$this->allianceJobRepository->delete($diplomatic); |
51
|
|
|
} |
52
|
|
|
$this->allianceActionManager->setJobForUser( |
53
|
|
|
$alliance->getId(), |
54
|
|
|
$lastonlinemember->getId(), |
55
|
|
|
AllianceEnum::ALLIANCE_JOBS_FOUNDER |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
1 |
|
$this->allianceJobRepository->delete($job); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Collection<int, UserInterface> $members |
66
|
|
|
*/ |
67
|
2 |
|
private function getLastOnlineMember(Collection $members): ?UserInterface |
68
|
|
|
{ |
69
|
2 |
|
$lastOnlineMember = null; |
70
|
2 |
|
$maxLastAction = 0; |
71
|
|
|
|
72
|
2 |
|
foreach ($members as $member) { |
73
|
|
|
if ($member->getLastAction() > $maxLastAction) { |
74
|
|
|
$maxLastAction = $member->getLastAction(); |
75
|
|
|
$lastOnlineMember = $member; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
return $lastOnlineMember; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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