Passed
Push — master ( 02b349...362dfe )
by Janko
10:06
created

AbstractPanelLayerDataProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 5
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Map\VisualPanel\Layer\DataProvider;
6
7
use Doctrine\ORM\Query\ResultSetMapping;
8
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...
9
use Stu\Lib\Map\VisualPanel\Layer\Data\CellDataInterface;
10
use Stu\Lib\Map\VisualPanel\PanelBoundaries;
11
use Stu\Orm\Repository\LocationRepositoryInterface;
12
use Stu\Orm\Repository\MapRepositoryInterface;
13
use Stu\Orm\Repository\StarSystemMapRepositoryInterface;
14
15
abstract class AbstractPanelLayerDataProvider implements PanelLayerDataProviderInterface
16
{
17 2
    public function __construct(
18
        protected LocationRepositoryInterface $locationRepository,
19
        protected MapRepositoryInterface $mapRepository,
20
        protected StarSystemMapRepositoryInterface $starSystemMapRepository
21
    ) {
22 2
    }
23
24
    /**
25
     * @return string The class name of the entity.
26
     * @psalm-return class-string
27
     */
28
    abstract protected function getDataClassString(): string;
29
30
    abstract protected function addFieldResults(ResultSetMapping $rsm): void;
31
32
    /** @return array<CellDataInterface> */
33
    abstract protected function provideDataForMap(PanelBoundaries $boundaries): array;
34
35
    /** @return array<CellDataInterface> */
36
    abstract protected function provideDataForSystemMap(PanelBoundaries $boundaries): array;
37
38
    #[Override]
39
    public function loadData(PanelBoundaries $boundaries): array
40
    {
41
        if ($boundaries->isOnMap()) {
42
43
            return $this->provideDataForMap($boundaries);
44
        } else {
45
46
            return $this->provideDataForSystemMap($boundaries);
47
        }
48
    }
49
50
    protected function createResultSetMapping(): ResultSetMapping
51
    {
52
        $rsm = new ResultSetMapping();
53
        $rsm->addEntityResult($this->getDataClassString(), 'd');
54
        $rsm->addFieldResult('d', 'x', 'x');
55
        $rsm->addFieldResult('d', 'y', 'y');
56
57
        $this->addFieldResults($rsm);
58
59
        return $rsm;
60
    }
61
}
62