Vocabulary   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 24
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A add() 0 10 2
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