Completed
Push — 1.4 ( a3fc6f...89c66f )
by Paweł
14s
created

KeywordsAwareTrait::getKeywordsNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Bundle\ContentBundle\Model;
18
19
use Doctrine\Common\Collections\Collection;
20
21 View Code Duplication
trait KeywordsAwareTrait
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    protected $keywords;
24
25
    public function getKeywords(): Collection
26
    {
27
        return $this->keywords;
28
    }
29
30
    public function setKeywords(Collection $keywords): void
31
    {
32
        $this->keywords = $keywords;
33
    }
34
35
    public function addKeyword(KeywordInterface $keyword): void
36
    {
37
        if (!$this->hasKeyword($keyword)) {
38
            $this->keywords->add($keyword);
39
        }
40
    }
41
42
    public function removeKeyword(KeywordInterface $keyword): void
43
    {
44
        if ($this->hasKeyword($keyword)) {
45
            $this->keywords->removeElement($keyword);
46
        }
47
    }
48
49
    public function hasKeyword(KeywordInterface $keyword): bool
50
    {
51
        return $this->keywords->contains($keyword);
52
    }
53
54
    public function getKeywordsNames(): array
55
    {
56
        return array_map(function ($keyword) {
57
            return $keyword->getName();
58
        }, $this->keywords->toArray());
59
    }
60
}
61