Completed
Push — master ( ab8175...d69783 )
by Kamil
15s
created

Suite::getListeners()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 7
rs 9.4285
c 2
b 0
f 1
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\FixturesBundle\Suite;
13
14
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
15
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
16
use Zend\Stdlib\SplPriorityQueue;
17
18
/**
19
 * @author Kamil Kokot <[email protected]>
20
 */
21
final class Suite implements SuiteInterface
22
{
23
    /**
24
     * @var string
25
     */
26
    private $name;
27
28
    /**
29
     * @var SplPriorityQueue
30
     */
31
    private $fixtures;
32
33
    /**
34
     * @var SplPriorityQueue
35
     */
36
    private $listeners;
37
38
    /**
39
     * @param string $name
40
     */
41
    public function __construct($name)
42
    {
43
        $this->name = $name;
44
        $this->fixtures = new SplPriorityQueue();
45
        $this->listeners = new SplPriorityQueue();
46
    }
47
48
    /**
49
     * @param FixtureInterface $fixture
50
     * @param array $options
51
     * @param int $priority
52
     */
53
    public function addFixture(FixtureInterface $fixture, array $options, $priority = 0)
54
    {
55
        $this->fixtures->insert(['fixture' => $fixture, 'options' => $options], $priority);
56
    }
57
58
    /**
59
     * @param ListenerInterface $listener
60
     * @param array $options
61
     * @param int $priority
62
     */
63
    public function addListener(ListenerInterface $listener, array $options, $priority = 0)
64
    {
65
        $this->listeners->insert(['listener' => $listener, 'options' => $options], $priority);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getName()
72
    {
73
        return $this->name;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getFixtures()
80
    {
81
        $fixtures = clone $this->fixtures;
82
        foreach ($fixtures as $fixture) {
83
            yield $fixture['fixture'] => $fixture['options'];
84
        }
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getListeners()
91
    {
92
        $listeners = clone $this->listeners;
93
        foreach ($listeners as $listener) {
94
            yield $listener['listener'] => $listener['options'];
95
        }
96
    }
97
}
98