Passed
Pull Request — master (#2052)
by Nico
20:53 queued 08:59
created

getDataClassString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
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\Border;
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\BorderData;
10
use Stu\Lib\Map\VisualPanel\PanelBoundaries;
11
use Stu\Orm\Entity\SpacecraftInterface;
12
use Stu\Orm\Repository\MapRepositoryInterface;
13
use Stu\Orm\Repository\StarSystemMapRepositoryInterface;
14
use Stu\Orm\Repository\AstroEntryRepositoryInterface;
15
16
final class CartographyBorderDataProvider extends AbstractBorderDataProvider
17
{
18
19
    public function __construct(
20
        private SpacecraftInterface $currentSpacecraft,
21
        protected MapRepositoryInterface $mapRepository,
22
        protected StarSystemMapRepositoryInterface $starSystemMapRepository,
23
        private AstroEntryRepositoryInterface $astroEntryRepository
24
    ) {
25
        $this->astroEntryRepository = $astroEntryRepository;
26
    }
27
28
    #[Override]
29
    protected function getDataClassString(): string
30
    {
31
        return BorderData::class;
32
    }
33
34
    #[Override]
35
    protected function addFieldResults(ResultSetMapping $rsm): void
36
    {
37
        $rsm->addFieldResult('d', 'cartographing', 'cartographing');
38
        $rsm->addFieldResult('d', 'complementary_color', 'complementary_color');
39
    }
40
41
    protected function provideDataForMap(PanelBoundaries $boundaries): array
42
    {
43
        return $this->mapRepository->getCartographingData(
44
            $boundaries,
45
            $this->createResultSetMapping(),
46
            $this->createLocationArray()
47
        );
48
    }
49
50
    protected function provideDataForSystemMap(PanelBoundaries $boundaries): array
51
    {
52
        return $this->starSystemMapRepository->getCartographingData(
53
            $boundaries,
54
            $this->createResultSetMapping(),
55
            $this->createLocationArray()
56
        );
57
    }
58
59
    /**
60
     * @return array<int>
61
     */
62
    private function createLocationArray(): array
63
    {
64
        $astroEntries = $this->astroEntryRepository->getByUserAndState(
65
            $this->currentSpacecraft->getUser(),
66
            1
67
        );
68
69
        $locations = [];
70
        foreach ($astroEntries as $entry) {
71
            $fieldIds = unserialize($entry->getFieldIds());
72
            if (is_array($fieldIds)) {
73
                $locations = array_merge($locations, $fieldIds);
74
            }
75
        }
76
77
        return $locations;
78
    }
79
}
80