|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use RuntimeException; |
|
9
|
|
|
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperFactoryInterface; |
|
10
|
|
|
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperInterface; |
|
11
|
|
|
use Stu\Module\Colony\Lib\ColonyLoaderInterface; |
|
12
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftLoaderInterface; |
|
13
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
14
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
15
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
|
16
|
|
|
use Stu\Orm\Entity\TrumfieldInterface; |
|
17
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
18
|
|
|
use Stu\Orm\Repository\TrumfieldRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
class TransferEntityLoader implements TransferEntityLoaderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @param SpacecraftLoaderInterface<SpacecraftWrapperInterface> $spacecraftLoader*/ |
|
23
|
1 |
|
public function __construct( |
|
24
|
|
|
private ColonyLoaderInterface $colonyLoader, |
|
25
|
|
|
private SpacecraftLoaderInterface $spacecraftLoader, |
|
26
|
|
|
private TrumfieldRepositoryInterface $trumfieldRepository, |
|
27
|
|
|
private StorageEntityWrapperFactoryInterface $storageEntityWrapperFactory |
|
28
|
1 |
|
) {} |
|
29
|
|
|
|
|
30
|
13 |
|
#[Override] |
|
31
|
|
|
public function loadEntity( |
|
32
|
|
|
int $id, |
|
33
|
|
|
TransferEntityTypeEnum $entityType, |
|
34
|
|
|
bool $checkForEntityLock = true, |
|
35
|
|
|
?UserInterface $user = null |
|
36
|
|
|
): StorageEntityWrapperInterface { |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** @var null|SpacecraftInterface|ColonyInterface|TrumfieldInterface */ |
|
40
|
13 |
|
$target = match ($entityType) { |
|
41
|
13 |
|
TransferEntityTypeEnum::SHIP, |
|
42
|
13 |
|
TransferEntityTypeEnum::STATION => $this->loadSpacecraft($id, $checkForEntityLock, $user), |
|
43
|
5 |
|
TransferEntityTypeEnum::COLONY => $this->loadColony($id, $checkForEntityLock, $user), |
|
44
|
1 |
|
TransferEntityTypeEnum::TRUMFIELD => $this->trumfieldRepository->find($id) |
|
45
|
13 |
|
}; |
|
46
|
|
|
|
|
47
|
13 |
|
if ($target === null) { |
|
48
|
|
|
throw new TransferEntityNotFoundException(sprintf( |
|
49
|
|
|
'entity with id %d and type %s does not exist', |
|
50
|
|
|
$id, |
|
51
|
|
|
$entityType->value |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
13 |
|
return $this->storageEntityWrapperFactory->wrapStorageEntity($target); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
13 |
|
private function loadSpacecraft(int $id, bool $checkForEntityLock, ?UserInterface $user): ?SpacecraftInterface |
|
59
|
|
|
{ |
|
60
|
13 |
|
$spacecraftWrapper = $user !== null |
|
61
|
11 |
|
? $this->spacecraftLoader->getWrapperByIdAndUser($id, $user->getId(), false, $checkForEntityLock) |
|
62
|
10 |
|
: $this->spacecraftLoader->find($id, $checkForEntityLock); |
|
63
|
|
|
|
|
64
|
13 |
|
return $spacecraftWrapper !== null |
|
65
|
13 |
|
? $spacecraftWrapper->get() |
|
66
|
13 |
|
: null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
4 |
|
private function loadColony(int $id, bool $checkForEntityLock, ?UserInterface $user): ColonyInterface |
|
70
|
|
|
{ |
|
71
|
4 |
|
return $user !== null |
|
72
|
2 |
|
? $this->colonyLoader->loadWithOwnerValidation($id, $user->getId(), $checkForEntityLock) |
|
73
|
4 |
|
: $this->colonyLoader->load($id, $checkForEntityLock); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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