Passed
Push — master ( df16e4...50087e )
by Nico
27:13 queued 16:48
created

WormholeEntry::getRestrictions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\JoinColumn;
12
use Doctrine\ORM\Mapping\ManyToOne;
13
use Doctrine\ORM\Mapping\OneToMany;
14
use Doctrine\ORM\Mapping\Table;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
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...
18
use Stu\Component\Map\WormholeEntryTypeEnum;
19
use Stu\Orm\Repository\WormholeEntryRepository;
20
21
#[Table(name: 'stu_wormhole_entry')]
22
#[Entity(repositoryClass: WormholeEntryRepository::class)]
23
class WormholeEntry implements WormholeEntryInterface
24
{
25
    #[Id]
26
    #[Column(type: 'integer')]
27
    #[GeneratedValue(strategy: 'IDENTITY')]
28
    private int $id;
29
30
    #[Column(type: 'integer')]
31
    private int $map_id;
0 ignored issues
show
introduced by
The private property $map_id is not used, and could be removed.
Loading history...
32
33
    #[Column(type: 'integer')]
34
    private int $system_id;
0 ignored issues
show
introduced by
The private property $system_id is not used, and could be removed.
Loading history...
35
36
    #[Column(type: 'integer')]
37
    private int $system_map_id;
0 ignored issues
show
introduced by
The private property $system_map_id is not used, and could be removed.
Loading history...
38
39
    #[Column(type: 'string', length: 10, enumType: WormholeEntryTypeEnum::class)]
40
    private WormholeEntryTypeEnum $type = WormholeEntryTypeEnum::BOTH;
41
42
    #[Column(type: 'integer', nullable: true)]
43
    private ?int $last_used = null;
44
45
    #[Column(type: 'integer', nullable: true)]
46
    private ?int $cooldown = null;
47
48
    #[ManyToOne(targetEntity: 'Map', inversedBy: 'wormholeEntries')]
49
    #[JoinColumn(name: 'map_id', referencedColumnName: 'id')]
50
    private MapInterface $map;
51
52
    #[ManyToOne(targetEntity: 'StarSystem')]
53
    #[JoinColumn(name: 'system_id', referencedColumnName: 'id')]
54
    private StarSystemInterface $starSystem;
55
56
    #[ManyToOne(targetEntity: 'StarSystemMap', inversedBy: 'wormholeEntries')]
57
    #[JoinColumn(name: 'system_map_id', referencedColumnName: 'id')]
58
    private StarSystemMapInterface $systemMap;
59
60
    /**
61
     * @var Collection<int, WormholeRestriction>
62
     */
63
    #[OneToMany(targetEntity: 'WormholeRestriction', mappedBy: 'wormholeEntry')]
64
    private Collection $restrictions;
65
66
67
    public function __construct()
68
    {
69
        $this->restrictions = new ArrayCollection();
70
    }
71
72
73
    #[Override]
74
    public function getId(): int
75
    {
76
        return $this->id;
77
    }
78
79
    #[Override]
80
    public function getMap(): MapInterface
81
    {
82
        return $this->map;
83
    }
84
85
    #[Override]
86
    public function getSystem(): StarSystemInterface
87
    {
88
        return $this->starSystem;
89
    }
90
91
    #[Override]
92
    public function getSystemMap(): StarSystemMapInterface
93
    {
94
        return $this->systemMap;
95
    }
96
97
    #[Override]
98
    public function setLastUsed(int $lastUsed): WormholeEntryInterface
99
    {
100
        $this->last_used = $lastUsed;
101
102
        return $this;
103
    }
104
105
    #[Override]
106
    public function isUsable(LocationInterface $location): bool
107
    {
108
        if (
109
            $this->last_used !== null && $this->cooldown !== null
110
            && $this->last_used + $this->cooldown * 60 > time()
111
        ) {
112
            return false;
113
        }
114
115
        if ($this->type === WormholeEntryTypeEnum::BOTH) {
116
            return true;
117
        }
118
119
        if ($this->type === WormholeEntryTypeEnum::MAP_TO_W) {
120
            return $location === $this->map;
121
        }
122
123
        return $location === $this->systemMap;
124
    }
125
126
    #[Override]
127
    /**
128
     * @return Collection<int, WormholeRestriction>
129
     */
130
    public function getRestrictions(): iterable
131
    {
132
        return $this->restrictions;
133
    }
134
}
135