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

ShipcountDataProviderFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 11
cp 0
rs 10
wmc 5

2 Methods

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