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

src/Sylius/Component/Addressing/Model/Country.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
use Sylius\Component\Resource\Model\ToggleableTrait;
19
use Symfony\Component\Intl\Intl;
20
21
class Country implements CountryInterface
22
{
23
    use ToggleableTrait;
24
25
    /**
26
     * @var mixed
27
     */
28
    protected $id;
29
30
    /**
31
     * Country code ISO 3166-1 alpha-2.
32
     *
33
     * @var string|null
34
     */
35
    protected $code;
36
37
    /**
38
     * @var Collection|ProvinceInterface[]
39
     */
40
    protected $provinces;
41
42
    public function __construct()
43
    {
44
        $this->provinces = 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...del\ProvinceInterface>> of property $provinces.

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...
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function __toString(): string
51
    {
52
        return (string) ($this->getName() ?? $this->getCode());
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getId()
59
    {
60
        return $this->id;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getCode(): ?string
67
    {
68
        return $this->code;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function setCode(?string $code): void
75
    {
76
        $this->code = $code;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getName(?string $locale = null): ?string
83
    {
84
        return Intl::getRegionBundle()->getCountryName($this->code, $locale);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getProvinces(): Collection
91
    {
92
        return $this->provinces;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function hasProvinces(): bool
99
    {
100
        return !$this->provinces->isEmpty();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function addProvince(ProvinceInterface $province): void
107
    {
108
        if (!$this->hasProvince($province)) {
109
            $this->provinces->add($province);
110
            $province->setCountry($this);
111
        }
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function removeProvince(ProvinceInterface $province): void
118
    {
119
        if ($this->hasProvince($province)) {
120
            $this->provinces->removeElement($province);
121
            $province->setCountry(null);
122
        }
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function hasProvince(ProvinceInterface $province): bool
129
    {
130
        return $this->provinces->contains($province);
131
    }
132
}
133