Completed
Push — master ( f2042d...10cdad )
by Kamil
29:04 queued 13:16
created

src/Sylius/Component/Core/Model/Taxon.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\Core\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Resource\Model\TimestampableTrait;
19
use Sylius\Component\Taxonomy\Model\Taxon as BaseTaxon;
20
use Sylius\Component\Taxonomy\Model\TaxonTranslation;
21
22
class Taxon extends BaseTaxon implements TaxonInterface
23
{
24
    use TimestampableTrait;
25
26
    /**
27
     * @var Collection|ImageInterface[]
28
     */
29
    protected $images;
30
31
    public function __construct()
32
    {
33
        parent::__construct();
34
35
        $this->createdAt = new \DateTime();
36
        $this->images = 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...\Model\ImageInterface>> of property $images.

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...
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getImages(): Collection
43
    {
44
        return $this->images;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getImagesByType(string $type): Collection
51
    {
52
        return $this->images->filter(function (ImageInterface $image) use ($type): bool {
53
            return $type === $image->getType();
54
        });
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function hasImages(): bool
61
    {
62
        return !$this->images->isEmpty();
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function hasImage(ImageInterface $image): bool
69
    {
70
        return $this->images->contains($image);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function addImage(ImageInterface $image): void
77
    {
78
        $image->setOwner($this);
79
        $this->images->add($image);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function removeImage(ImageInterface $image): void
86
    {
87
        if ($this->hasImage($image)) {
88
            $image->setOwner(null);
89
            $this->images->removeElement($image);
90
        }
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public static function getTranslationClass(): string
97
    {
98
        return TaxonTranslation::class;
99
    }
100
}
101