| Total Complexity | 9 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | trait ImagesAwareTrait |
||
| 12 | { |
||
| 13 | |||
| 14 | /** @var Collection|ImageInterface[] */ |
||
| 15 | protected $images; |
||
| 16 | |||
| 17 | public function initializeImagesCollection(): void |
||
| 18 | { |
||
| 19 | $this->images = new ArrayCollection(); |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * {@inheritdoc} |
||
| 24 | */ |
||
| 25 | public function getImages(): Collection |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | public function getImagesByType(string $type): Collection |
||
| 34 | { |
||
| 35 | return $this->images->filter(function (ImageInterface $image) use ($type) { |
||
| 36 | return $type === $image->getType(); |
||
| 37 | }); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc} |
||
| 42 | */ |
||
| 43 | public function hasImages(): bool |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function hasImage(ImageInterface $image): bool |
||
| 52 | { |
||
| 53 | return $this->images->contains($image); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | public function addImage(ImageInterface $image): void |
||
| 60 | { |
||
| 61 | if (false === $this->hasImage($image)) { |
||
| 62 | $image->setOwner($this); |
||
| 63 | $this->images->add($image); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | public function removeImage(ImageInterface $image): void |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 |