Completed
Push — master ( e8da74...847a65 )
by Iman
10:06 queued 06:57
created

BaseManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 53
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A forgetAbout() 0 7 3
A init() 0 6 1
A start() 0 5 3
A commitChain() 0 6 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies;
4
5
use Imanghafoori\HeyMan\HeyManSwitcher;
6
7
class BaseManager
8
{
9
    protected $initial = [];
10
11
    protected $event;
12
13
    protected $data = [];
14
15 105
    public function start()
16
    {
17 105
        foreach ($this->data as $value => $callbacks) {
18 41
            foreach ($callbacks as $key => $cb) {
19 41
                $this->register($value, $cb, $key);
0 ignored issues
show
Bug introduced by
The method register() does not exist on Imanghafoori\HeyMan\WatchingStrategies\BaseManager. It seems like you code against a sub-type of said class. However, the method does not exist in Imanghafoori\HeyMan\Watc...gies\RouterEventManager. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
                $this->/** @scrutinizer ignore-call */ 
20
                       register($value, $cb, $key);
Loading history...
20
            }
21
        }
22 105
    }
23
24 13
    public function forgetAbout($models, $event = 'a')
25
    {
26 13
        foreach ($models as $model) {
27 13
            if (is_null($event)) {
28 1
                unset($this->data[$model]);
29
            } else {
30 13
                unset($this->data[$model][$event]);
31
            }
32
        }
33 13
    }
34
35
    /**
36
     * ViewEventManager constructor.
37
     *
38
     * @param $value
39
     * @param string $param
40
     *
41
     * @return ViewEventManager
42
     */
43 101
    public function init(array $value, string $param = 'a')
44
    {
45 101
        $this->initial = $value;
46 101
        $this->event = $param;
47
48 101
        return $this;
49
    }
50
51
    /**
52
     * @param callable $callback
53
     */
54 93
    public function commitChain(callable $callback)
55
    {
56 93
        $switchableListener = app(HeyManSwitcher::class)->wrapForIgnorance($callback, $this->type);
57
58 93
        foreach ($this->initial as $value) {
59 93
            $this->data[$value][$this->event][] = $switchableListener;
60
        }
61 93
    }
62
}
63