Passed
Push — master ( 4e2a61...b4d3e2 )
by Iman
09:39
created

AllChains::forgetAbout()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
1
<?php
2
3
namespace Imanghafoori\HeyMan\WatchingStrategies;
4
5
use Imanghafoori\HeyMan\{Normilizers\InputNormalizer, Reactions\ReactionFactory, Switching\HeyManSwitcher};
6
7
class AllChains
8
{
9
    use InputNormalizer;
10
11
    public $data = [];
12
13
    public function forgetAbout($manager, $models, $event = null)
14
    {
15
        $models = $this->normalizeInput($models);
16
17
        foreach ($models as $model) {
18
            if ($event) {
19
                unset($this->data[$manager][$model][$event]);
20
            } else {
21
                unset($this->data[$manager][$model]);
22
            }
23
        }
24
    }
25
26
    public function commitChain()
27
    {
28
        $chain = resolve('heyman.chain');
29
        $callback = resolve(ReactionFactory::class)->make();
30
        $manager = $chain->get('manager');
31
        $switchableListener = resolve(HeyManSwitcher::class)->wrapForIgnorance($callback, $manager);
32
        $event = $chain->get('event');
33
34
        foreach ($chain->get('watchedEntities') as $value) {
35
            $this->data[$manager][$value][$event][] = $switchableListener;
36
        }
37
    }
38
}
39