Completed
Push — locale-in-url ( c8ed20...ec55a8 )
by Kamil
46:19 queued 21:47
created

Taxon::getImages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
namespace Sylius\Component\Core\Model;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Sylius\Component\Resource\Model\TimestampableTrait;
17
use Sylius\Component\Taxonomy\Model\Taxon as BaseTaxon;
18
use Sylius\Component\Taxonomy\Model\TaxonTranslation;
19
20
/**
21
 * @author Grzegorz Sadowski <[email protected]>
22
 */
23
class Taxon extends BaseTaxon implements TaxonInterface
24
{
25
    use TimestampableTrait;
26
27
    /**
28
     * @var Collection|ImageInterface[]
29
     */
30
    protected $images;
31
32
    public function __construct()
33
    {
34
        parent::__construct();
35
36
        $this->createdAt = new \DateTime();
37
        $this->products = new ArrayCollection();
0 ignored issues
show
Bug introduced by
The property products does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
        $this->images = new ArrayCollection();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getImages()
45
    {
46
        return $this->images;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getImagesByType($type)
53
    {
54
        return $this->images->filter(function (ImageInterface $image) use ($type) {
55
            return $type === $image->getType();
56
        });
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function hasImages()
63
    {
64
        return !$this->images->isEmpty();
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function hasImage(ImageInterface $image)
71
    {
72
        return $this->images->contains($image);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function addImage(ImageInterface $image)
79
    {
80
        $image->setOwner($this);
81
        $this->images->add($image);
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function removeImage(ImageInterface $image)
88
    {
89
        if ($this->hasImage($image)) {
90
            $image->setOwner(null);
91
            $this->images->removeElement($image);
92
        }
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public static function getTranslationClass()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
99
    {
100
        return TaxonTranslation::class;
101
    }
102
}
103