Passed
Push — quality ( aaf71d...3e536e )
by Arnaud
09:55
created

Vocabulary::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Collection\Taxonomy;
15
16
use Cecil\Collection\Collection as CecilCollection;
17
use Cecil\Collection\CollectionInterface;
18
use Cecil\Collection\ItemInterface;
19
20
/**
21
 * Class Vocabulary.
22
 */
23
class Vocabulary extends CecilCollection implements ItemInterface
24
{
25
    /**
26
     * Adds a term to a Vocabulary collection.
27
     * {@inheritdoc}
28
     */
29 1
    public function add(ItemInterface $item): CollectionInterface
30
    {
31 1
        if ($this->has($item->getId())) {
32
            // return if already exists
33 1
            return $this;
34
        }
35
36 1
        $this->items[] = $item;
37
38 1
        return $this;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function get(string $id): Term
45
    {
46
        return parent::get($id);
47
    }
48
}
49