Control::retrieving()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Shaper's control
4
 * User: moyo
5
 * Date: 22/02/2018
6
 * Time: 3:24 PM
7
 */
8
9
namespace Carno\Shaping;
10
11
use Closure;
12
13
class Control
14
{
15
    /**
16
     * @var Shaper[]
17
     */
18
    private static $instances = [];
19
20
    /**
21
     * @param Shaper $shaper
22
     */
23
    public static function register(Shaper $shaper) : void
24
    {
25
        self::$instances[spl_object_id($shaper)] = $shaper;
26
    }
27
28
    /**
29
     * @param Shaper $shaper
30
     */
31
    public static function deregister(Shaper $shaper) : void
32
    {
33
        unset(self::$instances[spl_object_id($shaper)]);
34
    }
35
36
    /**
37
     * @param Closure $receiver
38
     */
39
    public static function retrieving(Closure $receiver) : void
40
    {
41
        array_walk(self::$instances, function (Shaper $shaper) use ($receiver) {
42
            $receiver($shaper);
43
        });
44
    }
45
}
46