Menu::add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
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\Menu;
15
16
use Cecil\Collection\Collection as CecilCollection;
17
use Cecil\Collection\CollectionInterface;
18
use Cecil\Collection\ItemInterface;
19
20
/**
21
 * Menu item class.
22
 *
23
 * Represents a menu in a collection, allowing for the addition and replacement of menu entries.
24
 */
25
class Menu extends CecilCollection implements ItemInterface
26
{
27
    /**
28
     * Add or replace menu entry.
29
     * {@inheritdoc}
30
     */
31
    public function add(ItemInterface $item): CollectionInterface
32
    {
33
        if ($this->has($item->getId())) {
34
            $this->replace($item->getId(), $item);
35
36
            return $this;
37
        }
38
39
        return parent::add($item);
40
    }
41
}
42