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

Sylius/Component/Taxation/Model/TaxCategory.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\Taxation\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Resource\Model\TimestampableTrait;
19
20
class TaxCategory implements TaxCategoryInterface
21
{
22
    use TimestampableTrait;
23
24
    /**
25
     * @var mixed
26
     */
27
    protected $id;
28
29
    /**
30
     * @var string
31
     */
32
    protected $code;
33
    /**
34
     * @var string
35
     */
36
    protected $name;
37
38
    /**
39
     * @var string
40
     */
41
    protected $description;
42
43
    /**
44
     * @var Collection|TaxRateInterface[]
45
     */
46
    protected $rates;
47
48
    public function __construct()
49
    {
50
        $this->rates = 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...odel\TaxRateInterface>> of property $rates.

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...
51
        $this->createdAt = new \DateTime();
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function __toString(): string
58
    {
59
        return (string) $this->getName();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getId()
66
    {
67
        return $this->id;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getCode(): ?string
74
    {
75
        return $this->code;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function setCode(?string $code): void
82
    {
83
        $this->code = $code;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function getName(): ?string
90
    {
91
        return $this->name;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function setName(?string $name): void
98
    {
99
        $this->name = $name;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getDescription(): ?string
106
    {
107
        return $this->description;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function setDescription(?string $description): void
114
    {
115
        $this->description = $description;
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function getRates(): Collection
122
    {
123
        return $this->rates;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function addRate(TaxRateInterface $rate): void
130
    {
131
        if (!$this->hasRate($rate)) {
132
            $rate->setCategory($this);
133
            $this->rates->add($rate);
134
        }
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function removeRate(TaxRateInterface $rate): void
141
    {
142
        if ($this->hasRate($rate)) {
143
            $rate->setCategory(null);
144
            $this->rates->removeElement($rate);
145
        }
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151
    public function hasRate(TaxRateInterface $rate): bool
152
    {
153
        return $this->rates->contains($rate);
154
    }
155
}
156