Completed
Pull Request — master (#106)
by
unknown
03:48
created

TTaggable::hasTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 4
c 1
b 1
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Nayjest\Grids\Components\Base;
3
4
5
trait TTaggable
6
{
7
    protected $tags = [];
8
9
    /**
10
     * @return array
11
     */
12
    public function getTags()
13
    {
14
        return $this->tags;
15
    }
16
17
    /**
18
     * @param array $tags
19
     * @return $this
20
     */
21
    public function setTags(array $tags)
22
    {
23
        $this->tags = $tags;
24
        return $this;
25
    }
26
27
    /**
28
     * @param string $tagName
29
     * @return bool
30
     */
31
    public function hasTag($tagName)
32
    {
33
        return in_array($tagName, $this->tags);
34
    }
35
36
    /**
37
     * @param array|string[] $tagNames
38
     * @return bool
39
     */
40
    public function hasTags(array $tagNames)
41
    {
42
        foreach ($tagNames as $tag) {
43
            if (!$this->hasTag($tag)) {
44
                return false;
45
            }
46
        }
47
        return true;
48
    }
49
}
50
51