Completed
Push — master ( 43cd61...c32de9 )
by Iman
05:22
created

ChainCollection::forgetAbout()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Imanghafoori\HeyMan\Core;
4
5
use Imanghafoori\HeyMan\Switching\HeyManSwitcher;
6
use Imanghafoori\HeyMan\Reactions\ReactionFactory;
7
use Imanghafoori\HeyMan\Normilizers\InputNormalizer;
8
9
class ChainCollection
10
{
11
    use InputNormalizer;
12
13
    public $data = [];
14
15 14
    public function forgetAbout($manager, $models, $event = null)
16
    {
17 14
        $models = $this->normalizeInput($models);
18
19 14
        foreach ($models as $model) {
20 14
            if ($event) {
21 4
                unset($this->data[$manager][$model][$event]);
22
            } else {
23 14
                unset($this->data[$manager][$model]);
24
            }
25
        }
26 14
    }
27
28 96
    public function commitChain()
29
    {
30 96
        $chain = resolve('heyman.chain');
31 96
        $callback = resolve(ReactionFactory::class)->make();
32 96
        $manager = $chain->get('manager');
33 96
        $switchableListener = resolve(HeyManSwitcher::class)->wrapForIgnorance($callback, $manager);
34 96
        $event = $chain->get('event');
35
36 96
        foreach ($chain->get('watchedEntities') as $value) {
37 96
            $this->data[$manager][$value][$event][] = $switchableListener;
38
        }
39 96
    }
40
41
    /**
42
     * initialize the chain.
43
     *
44
     * @param $manager
45
     * @param array  $values
46
     * @param string $param
47
     */
48 105
    public function init($manager, array $values, string $param = 'default')
49
    {
50 105
        $chain = resolve('heyman.chain');
51 105
        $chain->set('manager', $manager);
0 ignored issues
show
Bug introduced by
The method set() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

51
        $chain->/** @scrutinizer ignore-call */ 
52
                set('manager', $manager);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52 105
        $chain->set('watchedEntities', $values);
53 105
        $chain->set('event', $param);
54 105
    }
55
}
56