Completed
Push — master ( 05bb5a...5289b8 )
by Rafał
34:32 queued 04:15
created

RelatedArticlesAwareTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addRelatedArticle() 0 7 2
A removeRelatedArticle() 0 7 2
A hasRelatedArticle() 0 4 1
A getRelatedArticles() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Publisher Content Bundle.
7
 *
8
 * Copyright 2019 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2019 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Model;
18
19
use Doctrine\Common\Collections\Collection;
20
21
trait RelatedArticlesAwareTrait
22
{
23
    /**
24
     * @var RelatedArticleInterface[]|Collection
25
     */
26
    protected $relatedArticles;
27
28
    public function addRelatedArticle(RelatedArticleInterface $relatedArticle): void
29
    {
30
        if (!$this->hasRelatedArticle($relatedArticle)) {
31
            $relatedArticle->setRelatesTo($this);
32
            $this->relatedArticles->add($relatedArticle);
33
        }
34
    }
35
36
    public function removeRelatedArticle(RelatedArticleInterface $relatedArticle): void
37
    {
38
        if ($this->hasRelatedArticle($relatedArticle)) {
39
            $relatedArticle->setRelatesTo(null);
40
            $this->relatedArticles->removeElement($relatedArticle);
41
        }
42
    }
43
44
    public function hasRelatedArticle(RelatedArticleInterface $relatedArticle): bool
45
    {
46
        return $this->relatedArticles->contains($relatedArticle);
47
    }
48
49
    public function getRelatedArticles(): Collection
50
    {
51
        return $this->relatedArticles;
52
    }
53
}
54