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

BorderDataProviderFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 29
ccs 7
cts 14
cp 0.5
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getDataProvider() 0 20 6
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
}