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

AllChains   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forgetAbout() 0 9 3
A commitChain() 0 10 2
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