Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

ExtensionChain::buildItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Menu Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\MenuBundle\Extension;
18
19
use Knp\Menu\Factory\CoreExtension;
20
use Knp\Menu\Factory\ExtensionInterface;
21
use Knp\Menu\ItemInterface;
22
23
class ExtensionChain implements ExtensionInterface
24
{
25
    /**
26
     * @var \SplPriorityQueue|ExtensionInterface[]
27
     */
28
    private $extensions;
29
30
    /**
31
     * ExtensionChain constructor.
32
     */
33 12
    public function __construct()
34
    {
35 12
        $this->extensions = new \SplPriorityQueue();
36 12
        $this->addExtension(new CoreExtension(), -20);
37 12
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 12
    public function buildOptions(array $options)
43
    {
44 12
        foreach ($this->getExtensions() as $extension) {
45 12
            $options = $extension->buildOptions($options);
46
        }
47
48 12
        return $options;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 12
    public function buildItem(ItemInterface $item, array $options)
55
    {
56 12
        foreach ($this->getExtensions() as $extension) {
57 12
            $extension->buildItem($item, $options);
58
        }
59 12
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 12
    public function addExtension(ExtensionInterface $extension, int $priority = 0)
65
    {
66 12
        $this->extensions->insert($extension, $priority);
67 12
    }
68
69 12
    private function getExtensions()
70
    {
71 12
        return clone $this->extensions;
72
    }
73
}
74