Vocabulary::add()   A
last analyzed

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
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
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
 * Vocabulary class.
22
 *
23
 * Represents a collection of terms, allowing for the addition and retrieval of terms by their ID.
24
 */
25
class Vocabulary extends CecilCollection implements ItemInterface
26
{
27
    /**
28
     * Adds a term to a Vocabulary collection.
29
     * {@inheritdoc}
30
     */
31 1
    public function add(ItemInterface $item): CollectionInterface
32
    {
33 1
        if ($this->has($item->getId())) {
34
            // return if already exists
35 1
            return $this;
36
        }
37
38 1
        $this->items[] = $item;
39
40 1
        return $this;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function get(string $id): Term
47
    {
48 1
        return parent::get($id);
49
    }
50
}
51