Passed
Pull Request — dev (#2044)
by Nico
11:37
created

BorderDataProviderFactory::getDataProvider()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 13.1446

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 6
nop 2
dl 0
loc 20
ccs 5
cts 12
cp 0.4167
crap 13.1446
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel\Layer\DataProvider\Border;
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\Component\Spacecraft\SpacecraftLssModeEnum;
10
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\AbstractPanelLayerDataProvider;
11
use Stu\Orm\Repository\LocationRepositoryInterface;
12
use Stu\Orm\Repository\MapRepositoryInterface;
13
use Stu\Orm\Repository\StarSystemMapRepositoryInterface;
14
use Stu\Orm\Entity\SpacecraftInterface;
15
use Stu\Orm\Repository\AstroEntryRepositoryInterface;
16
17
final class BorderDataProviderFactory implements BorderDataProviderFactoryInterface
18
{
19 2
    public function __construct(
20
        private LocationRepositoryInterface $locationRepository,
21
        private MapRepositoryInterface $mapRepository,
22
        private StarSystemMapRepositoryInterface $starSystemMapRepository,
23
        private AstroEntryRepositoryInterface $astroEntryRepository
24 2
    ) {}
25
26 1
    #[Override]
27
    public function getDataProvider(?SpacecraftInterface $currentSpacecraft, ?bool $isOnShipLevel): AbstractPanelLayerDataProvider
28
    {
29
30 1
        if ($currentSpacecraft != null) {
31
32 1
            switch ($currentSpacecraft->getLssMode()) {
33 1
                case SpacecraftLssModeEnum::NORMAL:
34 1
                    return new NormalBorderDataProvider($this->locationRepository, $this->mapRepository, $this->starSystemMapRepository);
35
                case SpacecraftLssModeEnum::BORDER:
36
                    return new RegionBorderDataProvider($this->locationRepository, $this->mapRepository, $this->starSystemMapRepository);
37
                case SpacecraftLssModeEnum::IMPASSABLE:
38
                    return new ImpassableBorderDataProvider($currentSpacecraft, $this->mapRepository, $this->starSystemMapRepository);
39
                case SpacecraftLssModeEnum::CARTOGRAPHING:
40
                    return new CartographyBorderDataProvider($currentSpacecraft, $this->mapRepository, $this->starSystemMapRepository, $this->astroEntryRepository);
41
            }
42
        }
43
44
45
        throw new RuntimeException(sprintf('border type is not supported'));
46
    }
47
}