Completed
Push — master ( 1f36be...d8b059 )
by Beñat
03:59
created

MenuItemCollection::removeById()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel library.
5
 *
6
 * Copyright (c) 2016 LIN3S <[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
namespace LIN3S\CMSKernel\Domain\Model\Menu;
13
14
use LIN3S\SharedKernel\Domain\Model\Collection;
15
use LIN3S\SharedKernel\Domain\Model\CollectionElementAlreadyRemovedException;
16
17
/**
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
class MenuItemCollection extends Collection
21
{
22
    protected function type()
23
    {
24
        return MenuItem::class;
25
    }
26
27
    public function removeById(MenuItemId $menuItemId)
28
    {
29
        $menuItems = $this->toArray();
30
        foreach ($menuItems as $item) {
31
            if ($menuItemId->equals($item->id())) {
32
                $this->remove($item);
33
34
                return;
35
            }
36
        }
37
        throw new CollectionElementAlreadyRemovedException();
38
    }
39
}
40