Passed
Pull Request — master (#2257)
by Janko
10:11 queued 05:17
created

StarSystemMap::getMapRegion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\JoinColumn;
12
use Doctrine\ORM\Mapping\ManyToOne;
13
use Doctrine\ORM\Mapping\OneToMany;
14
use Doctrine\ORM\Mapping\OneToOne;
15
use Doctrine\ORM\Mapping\Table;
16
use Doctrine\ORM\Mapping\UniqueConstraint;
17
use Stu\Orm\Repository\StarSystemMapRepository;
18
19
#[Table(name: 'stu_sys_map')]
20
#[UniqueConstraint(name: 'system_coordinates_idx', columns: ['sx', 'sy', 'systems_id'])]
21
#[Entity(repositoryClass: StarSystemMapRepository::class)]
22
class StarSystemMap extends Location
23
{
24
    #[Column(type: 'smallint')]
25
    private int $sx = 0;
26
27
    #[Column(type: 'smallint')]
28
    private int $sy = 0;
29
30
    #[Column(type: 'integer')]
31
    private int $systems_id = 0;
32
33
    #[ManyToOne(targetEntity: StarSystem::class, inversedBy: 'fields')]
34
    #[JoinColumn(name: 'systems_id', nullable: false, referencedColumnName: 'id')]
35
    private StarSystem $starSystem;
36
37
    #[OneToOne(targetEntity: Colony::class, mappedBy: 'starsystem_map')]
38
    private ?Colony $colony = null;
39
40
    /**
41
     * @var ArrayCollection<int, WormholeEntry>
42
     */
43
    #[OneToMany(targetEntity: WormholeEntry::class, mappedBy: 'systemMap')]
44
    private Collection $wormholeEntries;
45
46
    public function __construct()
47
    {
48
        parent::__construct();
49
        $this->wormholeEntries = new ArrayCollection();
50
    }
51
52 5
    public function getLayer(): ?Layer
53
    {
54 5
        return $this->layer;
55
    }
56
57 18
    public function getSx(): int
58
    {
59 18
        return $this->sx;
60
    }
61
62
    public function setSx(int $sx): StarSystemMap
63
    {
64
        $this->sx = $sx;
65
66
        return $this;
67
    }
68
69 7
    public function getX(): int
70
    {
71 7
        return $this->getSx();
72
    }
73
74 18
    public function getSy(): int
75
    {
76 18
        return $this->sy;
77
    }
78
79
    public function setSy(int $sy): StarSystemMap
80
    {
81
        $this->sy = $sy;
82
83
        return $this;
84
    }
85
86 7
    public function getY(): int
87
    {
88 7
        return $this->getSy();
89
    }
90
91
    public function getSystemId(): int
92
    {
93
        return $this->systems_id;
94
    }
95
96 18
    public function getSystem(): StarSystem
97
    {
98 18
        return $this->starSystem;
99
    }
100
101
    public function setSystem(StarSystem $starSystem): StarSystemMap
102
    {
103
        $this->starSystem = $starSystem;
104
105
        return $this;
106
    }
107
108 1
    public function getColony(): ?Colony
109
    {
110 1
        return $this->colony;
111
    }
112
113
    public function getMapRegion(): ?MapRegion
114
    {
115
        return null;
116
    }
117
118
    public function getAdministratedRegion(): ?MapRegion
119
    {
120
        return null;
121
    }
122
123
    public function getInfluenceArea(): ?StarSystem
124
    {
125
        return null;
126
    }
127
128
    protected function getWormholeEntries(): Collection
129
    {
130
        return $this->wormholeEntries;
131
    }
132
133
    public function getFieldStyle(): string
134
    {
135
        return "background-image: url('/assets/map/" . $this->getFieldId() . ".png'); opacity:1;";
136
    }
137
138
    public function getSectorId(): ?int
139
    {
140
        $parentMap = $this->getSystem()->getMap();
141
        if ($parentMap === null) {
142
            return null;
143
        }
144
145
        return $parentMap->getSectorId();
146
    }
147
148 6
    public function getSectorString(): string
149
    {
150 6
        return sprintf(
151 6
            '%d|%d (%s-%s)',
152 6
            $this->getSx(),
153 6
            $this->getSy(),
154 6
            $this->getSystem()->getName(),
155 6
            $this->getSystem()->isWormhole() ? 'Wurmloch' : 'System'
156 6
        );
157
    }
158
}
159