RegistrationListener::getCallbacks()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 4
nop 0
1
<?php
2
3
namespace Magium\Util\TestCase;
4
5
use Magium\AbstractTestCase;
6
use Zend\Stdlib\SplPriorityQueue;
7
8
class RegistrationListener
9
{
10
    protected static $callbacks;
11
12
    public static function executeCallbacks(AbstractTestCase $testCase)
13
    {
14
        $callbacks = self::getCallbacks();
15
        self::$callbacks = new SplPriorityQueue();
16
        foreach ($callbacks as $callback) {
17
            list($callback, $priority) = $callback;
18
            if ($callback instanceof RegistrationCallbackInterface) {
19
                $callback->register($testCase);
20
            }
21
            self::addCallback($callback, $priority);
22
        }
23
    }
24
25
    /**
26
     * @return SplPriorityQueue
27
     */
28
29
    protected static function getCallbacks()
30
    {
31
        if (!self::$callbacks instanceof SplPriorityQueue) {
32
            self::$callbacks = new SplPriorityQueue();
33
        }
34
        return self::$callbacks;
35
    }
36
37
    public static function addCallback(RegistrationCallbackInterface $callback, $priority = 0)
38
    {
39
        self::getCallbacks()->insert([$callback, $priority], $priority);
40
    }
41
42
}
43