|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Component\Station\Dock; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Component\Station\Dock\DockModeEnum; |
|
9
|
|
|
use Stu\Component\Station\Dock\DockTypeEnum; |
|
10
|
|
|
use Stu\Orm\Entity\DockingPrivilegeInterface; |
|
11
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
12
|
|
|
use Stu\Orm\Entity\StationInterface; |
|
13
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
14
|
|
|
use Stu\Orm\Repository\DockingPrivilegeRepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class DockPrivilegeUtility implements DockPrivilegeUtilityInterface |
|
17
|
|
|
{ |
|
18
|
28 |
|
public function __construct(private readonly DockingPrivilegeRepositoryInterface $dockingPrivilegeRepository) {} |
|
19
|
|
|
|
|
20
|
27 |
|
#[Override] |
|
21
|
|
|
public function checkPrivilegeFor(StationInterface $station, UserInterface|ShipInterface $source): bool |
|
22
|
|
|
{ |
|
23
|
|
|
try { |
|
24
|
27 |
|
return array_reduce( |
|
25
|
27 |
|
$this->dockingPrivilegeRepository->getByStation($station), |
|
26
|
27 |
|
fn(bool $isAllowed, DockingPrivilegeInterface $privilege): bool => $isAllowed || $this->isAllowed($privilege, $source), |
|
27
|
27 |
|
false |
|
28
|
27 |
|
); |
|
29
|
7 |
|
} catch (DockingUnallowedException) { |
|
30
|
7 |
|
return false; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
27 |
|
private function isAllowed(DockingPrivilegeInterface $privilege, UserInterface|ShipInterface $source): bool |
|
35
|
|
|
{ |
|
36
|
27 |
|
$user = $source instanceof UserInterface ? $source : $source->getUser(); |
|
37
|
|
|
|
|
38
|
27 |
|
$isMatch = match ($privilege->getPrivilegeType()) { |
|
39
|
27 |
|
DockTypeEnum::USER => $privilege->getTargetId() === $user->getId(), |
|
40
|
20 |
|
DockTypeEnum::ALLIANCE => $user->getAlliance() !== null && $privilege->getTargetId() === $user->getAlliance()->getId(), |
|
41
|
13 |
|
DockTypeEnum::FACTION => $privilege->getTargetId() == $user->getFactionId(), |
|
42
|
6 |
|
DockTypeEnum::SHIP => $source instanceof ShipInterface && $privilege->getTargetId() == $source->getId(), |
|
43
|
27 |
|
}; |
|
44
|
|
|
|
|
45
|
27 |
|
if (!$isMatch) { |
|
46
|
11 |
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
18 |
|
if ($privilege->getPrivilegeMode() === DockModeEnum::DENY) { |
|
50
|
7 |
|
throw new DockingUnallowedException(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
11 |
|
return true; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
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