Passed
Push — dev ( b01017...737777 )
by Janko
05:10
created

StationLoader::find()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 13
ccs 0
cts 8
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Station\Lib;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use RuntimeException;
9
use Stu\Module\Spacecraft\Lib\SourceAndTargetWrappersInterface;
10
use Stu\Module\Spacecraft\Lib\SpacecraftLoaderInterface;
11
use Stu\Orm\Entity\Station;
12
use Stu\Orm\Entity\Spacecraft;
13
14
final class StationLoader implements StationLoaderInterface
15
{
16
    /**
17
     * @param SpacecraftLoaderInterface<StationWrapperInterface> $spacecraftLoader
18
     */
19 1
    public function __construct(
20
        private SpacecraftLoaderInterface $spacecraftLoader
21 1
    ) {}
22
23 10
    #[Override]
24
    public function getByIdAndUser(
25
        int $stationId,
26
        int $userId,
27
        bool $allowUplink = false,
28
        bool $checkForEntityLock = true
29
    ): Station {
30
31 10
        $spacecraft = $this->spacecraftLoader->getByIdAndUser(
32 10
            $stationId,
33 10
            $userId,
34 10
            $allowUplink,
35 10
            $checkForEntityLock
36 10
        );
37
38 10
        if (!$spacecraft instanceof Station) {
39
            throw new RuntimeException(sprintf('stationId %d is not a station', $stationId));
40
        }
41
42 10
        return $spacecraft;
43
    }
44
45 9
    #[Override]
46
    public function getWrapperByIdAndUser(
47
        int $stationId,
48
        int $userId,
49
        bool $allowUplink = false,
50
        bool $checkForEntityLock = true
51
    ): StationWrapperInterface {
52
53 9
        $wrapper = $this->spacecraftLoader->getWrapperByIdAndUser(
54 9
            $stationId,
55 9
            $userId,
56 9
            $allowUplink,
57 9
            $checkForEntityLock
58 9
        );
59
60 9
        if (!$wrapper instanceof StationWrapperInterface) {
61
            throw new RuntimeException(sprintf('stationId %d is not a station', $stationId));
62
        }
63
64 9
        return $wrapper;
65
    }
66
67 2
    #[Override]
68
    public function getWrappersBySourceAndUserAndTarget(
69
        int $stationId,
70
        int $userId,
71
        int $targetId,
72
        bool $allowUplink = false,
73
        bool $checkForEntityLock = true
74
    ): SourceAndTargetWrappersInterface {
75
76 2
        return $this->spacecraftLoader->getWrappersBySourceAndUserAndTarget(
77 2
            $stationId,
78 2
            $userId,
79 2
            $targetId,
80 2
            $allowUplink,
81 2
            $checkForEntityLock
82 2
        );
83
    }
84
85
    #[Override]
86
    public function find(int $stationId, bool $checkForEntityLock = true): ?StationWrapperInterface
87
    {
88
        $wrapper = $this->spacecraftLoader->find(
89
            $stationId,
90
            $checkForEntityLock
91
        );
92
93
        if ($wrapper !== null && !$wrapper instanceof StationWrapperInterface) {
94
            throw new RuntimeException(sprintf('stationId %d is not a station', $stationId));
95
        }
96
97
        return $wrapper;
98
    }
99
100
    public function save(Spacecraft $station): void
101
    {
102
        $this->spacecraftLoader->save($station);
103
    }
104
}
105