Passed
Push — dev ( 04bdae...5ade2a )
by Janko
28:32
created

ShipcountDataProviderFactory::getDataProvider()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 12
ccs 0
cts 8
cp 0
crap 20
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel\Layer\DataProvider\Shipcount;
6
7
use RuntimeException;
8
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\AbstractPanelLayerDataProvider;
9
use Stu\Orm\Repository\MapRepositoryInterface;
10
use Stu\Orm\Repository\StarSystemMapRepositoryInterface;
11
12
final class ShipcountDataProviderFactory implements ShipcountDataProviderFactoryInterface
13
{
14
    private MapRepositoryInterface $mapRepository;
15
16
    private StarSystemMapRepositoryInterface $starSystemMapRepository;
17
18
    public function __construct(
19
        MapRepositoryInterface $mapRepository,
20
        StarSystemMapRepositoryInterface $starSystemMapRepository
21
    ) {
22
        $this->mapRepository = $mapRepository;
23
        $this->starSystemMapRepository = $starSystemMapRepository;
24
    }
25
26
    public function getDataProvider(int $id, ShipcountLayerTypeEnum $type): AbstractPanelLayerDataProvider
27
    {
28
        switch ($type) {
29
            case ShipcountLayerTypeEnum::ALL:
30
                return new GeneralShipcountDataProvider($this->mapRepository, $this->starSystemMapRepository);
31
            case ShipcountLayerTypeEnum::ALLIANCE_ONLY:
32
                return new AllianceShipcountDataProvider($id, $this->mapRepository, $this->starSystemMapRepository);
33
            case ShipcountLayerTypeEnum::USER_ONLY:
34
                return new UserShipcountDataProvider($id, $this->mapRepository, $this->starSystemMapRepository);
35
        }
36
37
        throw new RuntimeException(sprintf('Shipcount layer type %d is not supported', $type->value));
38
    }
39
}
40