Passed
Push — dev ( 1f861c...ab5646 )
by Janko
92:20
created

createLocationString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 16
ccs 0
cts 11
cp 0
crap 12
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
    }
39
40
    protected function provideDataForMap(PanelBoundaries $boundaries): array
41
    {
42
        return $this->mapRepository->getCartographingData(
43
            $boundaries,
44
            $this->createResultSetMapping(),
45
            $this->createLocationArray()
46
        );
47
    }
48
49
    protected function provideDataForSystemMap(PanelBoundaries $boundaries): array
50
    {
51
        return $this->starSystemMapRepository->getCartographingData(
52
            $boundaries,
53
            $this->createResultSetMapping(),
54
            $this->createLocationArray()
55
        );
56
    }
57
58
    /**
59
     * @return array<int>
60
     */
61
    private function createLocationArray(): array
62
    {
63
        $astroEntries = $this->astroEntryRepository->getByUserAndState(
64
            $this->currentSpacecraft->getUser(),
65
            1
66
        );
67
68
        $locations = [];
69
        foreach ($astroEntries as $entry) {
70
            $fieldIds = unserialize($entry->getFieldIds());
71
            if (is_array($fieldIds)) {
72
                $locations = array_merge($locations, $fieldIds);
73
            }
74
        }
75
76
        return $locations;
77
    }
78
}
79