Passed
Push — dev ( d85471...98511f )
by Janko
18:01
created

ShipLoader   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 27.5%

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 89
ccs 11
cts 40
cp 0.275
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getByIdAndUser() 0 20 2
A getWrapperByIdAndUser() 0 20 2
A find() 0 13 3
A getWrappersBySourceAndUserAndTarget() 0 15 1
A save() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\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\ShipInterface;
12
use Stu\Orm\Entity\SpacecraftInterface;
13
14
final class ShipLoader implements ShipLoaderInterface
15
{
16
    /**
17
     * @param SpacecraftLoaderInterface<ShipWrapperInterface> $spacecraftLoader
18
     */
19 1
    public function __construct(
20
        private SpacecraftLoaderInterface $spacecraftLoader
21 1
    ) {}
22
23 2
    #[Override]
24
    public function getByIdAndUser(
25
        int $shipId,
26
        int $userId,
27
        bool $allowUplink = false,
28
        bool $checkForEntityLock = true
29
    ): ShipInterface {
30
31 2
        $spacecraft = $this->spacecraftLoader->getByIdAndUser(
32 2
            $shipId,
33 2
            $userId,
34 2
            $allowUplink,
35 2
            $checkForEntityLock
36 2
        );
37
38 2
        if (!$spacecraft instanceof ShipInterface) {
39
            throw new RuntimeException(sprintf('shipId %d is not a ship', $shipId));
40
        }
41
42 2
        return $spacecraft;
43
    }
44
45
    #[Override]
46
    public function getWrapperByIdAndUser(
47
        int $shipId,
48
        int $userId,
49
        bool $allowUplink = false,
50
        bool $checkForEntityLock = true
51
    ): ShipWrapperInterface {
52
53
        $wrapper = $this->spacecraftLoader->getWrapperByIdAndUser(
54
            $shipId,
55
            $userId,
56
            $allowUplink,
57
            $checkForEntityLock
58
        );
59
60
        if (!$wrapper instanceof ShipWrapperInterface) {
61
            throw new RuntimeException(sprintf('shipId %d is not a ship', $shipId));
62
        }
63
64
        return $wrapper;
65
    }
66
67
    #[Override]
68
    public function getWrappersBySourceAndUserAndTarget(
69
        int $shipId,
70
        int $userId,
71
        int $targetId,
72
        bool $allowUplink = false,
73
        bool $checkForEntityLock = true
74
    ): SourceAndTargetWrappersInterface {
75
76
        return $this->spacecraftLoader->getWrappersBySourceAndUserAndTarget(
77
            $shipId,
78
            $userId,
79
            $targetId,
80
            $allowUplink,
81
            $checkForEntityLock
82
        );
83
    }
84
85
    #[Override]
86
    public function find(int $shipId, bool $checkForEntityLock = true): ?ShipWrapperInterface
87
    {
88
        $wrapper = $this->spacecraftLoader->find(
89
            $shipId,
90
            $checkForEntityLock
91
        );
92
93
        if ($wrapper !== null && !$wrapper instanceof ShipWrapperInterface) {
94
            throw new RuntimeException(sprintf('shipId %d is not a ship', $shipId));
95
        }
96
97
        return $wrapper;
98
    }
99
100
    public function save(SpacecraftInterface $ship): void
101
    {
102
        $this->spacecraftLoader->save($ship);
103
    }
104
}
105