Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

src/Sylius/Component/Addressing/Model/Zone.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Addressing\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
19
class Zone implements ZoneInterface
20
{
21
    /**
22
     * @var mixed
23
     */
24
    protected $id;
25
26
    /**
27
     * @var string|null
28
     */
29
    protected $code;
30
31
    /**
32
     * @var string|null
33
     */
34
    protected $name;
35
36
    /**
37
     * @var string|null
38
     */
39
    protected $type;
40
41
    /**
42
     * @var string|null
43
     */
44
    protected $scope = Scope::ALL;
45
46
    /**
47
     * @var Collection|ZoneMemberInterface[]
48
     */
49
    protected $members;
50
51
    public function __construct()
52
    {
53
        $this->members = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\C...l\ZoneMemberInterface>> of property $members.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function __toString(): string
60
    {
61
        return (string) $this->getName();
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public static function getTypes(): array
68
    {
69
        return [self::TYPE_COUNTRY, self::TYPE_PROVINCE, self::TYPE_ZONE];
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getId()
76
    {
77
        return $this->id;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getCode(): ?string
84
    {
85
        return $this->code;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function setCode(?string $code): void
92
    {
93
        $this->code = $code;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getName(): ?string
100
    {
101
        return $this->name;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function setName(?string $name): void
108
    {
109
        $this->name = $name;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function getType(): ?string
116
    {
117
        return $this->type;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     *
123
     * @throws \InvalidArgumentException
124
     */
125
    public function setType(?string $type): void
126
    {
127
        if (!in_array($type, static::getTypes(), true)) {
128
            throw new \InvalidArgumentException('Wrong zone type supplied.');
129
        }
130
131
        $this->type = $type;
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function getScope(): ?string
138
    {
139
        return $this->scope;
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     */
145
    public function setScope(?string $scope): void
146
    {
147
        $this->scope = $scope;
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153
    public function getMembers(): Collection
154
    {
155
        return $this->members;
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    public function hasMembers(): bool
162
    {
163
        return !$this->members->isEmpty();
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function addMember(ZoneMemberInterface $member): void
170
    {
171
        if (!$this->hasMember($member)) {
172
            $this->members->add($member);
173
            $member->setBelongsTo($this);
174
        }
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function removeMember(ZoneMemberInterface $member): void
181
    {
182
        if ($this->hasMember($member)) {
183
            $this->members->removeElement($member);
184
            $member->setBelongsTo(null);
185
        }
186
    }
187
188
    /**
189
     * {@inheritdoc}
190
     */
191
    public function hasMember(ZoneMemberInterface $member): bool
192
    {
193
        return $this->members->contains($member);
194
    }
195
}
196