Passed
Pull Request — master (#2331)
by Janko
11:37 queued 06:03
created

getWrappersBySourceAndUserAndTarget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Station\Lib;
6
7
use RuntimeException;
8
use Stu\Module\Spacecraft\Lib\SourceAndTargetWrappersInterface;
9
use Stu\Module\Spacecraft\Lib\SpacecraftLoaderInterface;
10
use Stu\Orm\Entity\Station;
11
12
final class StationLoader implements StationLoaderInterface
13
{
14
    /**
15
     * @param SpacecraftLoaderInterface<StationWrapperInterface> $spacecraftLoader
16
     */
17 1
    public function __construct(
18
        private SpacecraftLoaderInterface $spacecraftLoader
19 1
    ) {}
20
21 10
    #[\Override]
22
    public function getByIdAndUser(
23
        int $stationId,
24
        int $userId,
25
        bool $allowUplink = false,
26
        bool $checkForEntityLock = true
27
    ): Station {
28 10
        $spacecraft = $this->spacecraftLoader->getByIdAndUser(
29 10
            $stationId,
30 10
            $userId,
31 10
            $allowUplink,
32 10
            $checkForEntityLock
33 10
        );
34
35 10
        if (!$spacecraft instanceof Station) {
36
            throw new RuntimeException(sprintf('stationId %d is not a station', $stationId));
37
        }
38
39 10
        return $spacecraft;
40
    }
41
42 9
    #[\Override]
43
    public function getWrapperByIdAndUser(
44
        int $stationId,
45
        int $userId,
46
        bool $allowUplink = false,
47
        bool $checkForEntityLock = true
48
    ): StationWrapperInterface {
49 9
        $wrapper = $this->spacecraftLoader->getWrapperByIdAndUser(
50 9
            $stationId,
51 9
            $userId,
52 9
            $allowUplink,
53 9
            $checkForEntityLock
54 9
        );
55
56 9
        if (!$wrapper instanceof StationWrapperInterface) {
57
            throw new RuntimeException(sprintf('stationId %d is not a station', $stationId));
58
        }
59
60 9
        return $wrapper;
61
    }
62
63 2
    #[\Override]
64
    public function getWrappersBySourceAndUserAndTarget(
65
        int $stationId,
66
        int $userId,
67
        int $targetId,
68
        bool $allowUplink = false,
69
        bool $checkForEntityLock = true
70
    ): SourceAndTargetWrappersInterface {
71 2
        return $this->spacecraftLoader->getWrappersBySourceAndUserAndTarget(
72 2
            $stationId,
73 2
            $userId,
74 2
            $targetId,
75 2
            $allowUplink,
76 2
            $checkForEntityLock
77 2
        );
78
    }
79
80
    #[\Override]
81
    public function find(int $stationId, bool $checkForEntityLock = true): ?StationWrapperInterface
82
    {
83
        $wrapper = $this->spacecraftLoader->find(
84
            $stationId,
85
            $checkForEntityLock
86
        );
87
88
        if ($wrapper !== null && !$wrapper instanceof StationWrapperInterface) {
89
            throw new RuntimeException(sprintf('stationId %d is not a station', $stationId));
90
        }
91
92
        return $wrapper;
93
    }
94
}
95