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

ExtensionChain   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 51
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A buildOptions() 0 8 2
A buildItem() 0 6 2
A addExtension() 0 4 1
A getExtensions() 0 4 1
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