ItemBagFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createUnique() 0 3 1
A createDuplicated() 0 3 1
A create() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RedRat\Presenthor\Bag;
6
7
use RedRat\Presenthor\Item\ItemInterface;
8
9
/**
10
 * ItemBag Factory
11
 *
12
 * @package RedRat\Presenthor\Bag
13
 */
14
class ItemBagFactory
15
{
16
    /**
17
     * @param array $items
18
     * @return ItemBagInterface
19
     */
20 1
    public static function createUnique(array $items): ItemBagInterface
21
    {
22 1
        return self::create($items, false);
23
    }
24
25
    /**
26
     * @param array $items
27
     * @return ItemBagInterface
28
     */
29 1
    public static function createDuplicated(array $items): ItemBagInterface
30
    {
31 1
        return self::create($items, true);
32
    }
33
34
    /**
35
     * @param array $items
36
     * @param bool $acceptDuplicate
37
     * @return ItemBagInterface
38
     */
39 2
    protected static function create(array $items, bool $acceptDuplicate): ItemBagInterface
40
    {
41 2
        $itemBag = new ItemBag();
42
43
        /** @var ItemInterface $item */
44 2
        foreach ($items as $item) {
45 2
            if ($item instanceof ItemInterface) {
46 2
                $itemBag->addItem($item, $acceptDuplicate);
47
            }
48
        }
49
50 2
        return $itemBag;
51
    }
52
}
53