Completed
Push — master ( 4da1f4...8b580e )
by Paweł
08:27
created

AuthorsAwareTrait::hasAuthor()   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 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Bridge Component.
7
 *
8
 * Copyright 2018 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 2018 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Component\Bridge\Model;
18
19
use Doctrine\Common\Collections\Collection;
20
21
trait AuthorsAwareTrait
22
{
23
    protected $authors;
24
25
    public function getAuthors(): Collection
26
    {
27
        return $this->authors;
28
    }
29
30
    public function setAuthors(Collection $authors): void
31
    {
32
        $this->authors = $authors;
33
    }
34
35
    public function addAuthor(AuthorInterface $author): void
36
    {
37
        if (!$this->hasAuthor($author)) {
38
            $this->authors->add($author);
39
        }
40
    }
41
42
    public function removeAuthor(AuthorInterface $author): void
43
    {
44
        if ($this->hasAuthor($author)) {
45
            $this->authors->removeElement($author);
46
        }
47
    }
48
49
    public function hasAuthor(AuthorInterface $author): bool
50
    {
51
        return $this->authors->contains($author);
52
    }
53
}
54