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

MenuItemCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A removeById() 0 12 3
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