SlotContainer::add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\View\Slot;
19
20
use CuyZ\Notiz\Core\Exception\DuplicateEntryException;
21
use CuyZ\Notiz\View\Slot\Application\Slot;
22
23
class SlotContainer
24
{
25
    /**
26
     * @var Slot[]
27
     */
28
    protected $slots = [];
29
30
    /**
31
     * @param Slot $slot
32
     *
33
     * @throws DuplicateEntryException
34
     */
35
    public function add(Slot $slot)
36
    {
37
        if ($this->has($slot->getName())) {
38
            throw DuplicateEntryException::slotContainerDuplication($slot->getName());
39
        }
40
41
        $this->slots[$slot->getName()] = $slot;
42
    }
43
44
    /**
45
     * @param string $name
46
     * @return bool
47
     */
48
    public function has(string $name): bool
49
    {
50
        return isset($this->slots[$name]);
51
    }
52
53
    /**
54
     * @return Slot[]
55
     */
56
    public function getList(): array
57
    {
58
        return $this->slots;
59
    }
60
}
61