ChainCollection::forgetAbout()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 6
nop 3
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan\Core;
4
5
use Imanghafoori\HeyMan\Switching\HeyManSwitcher;
6
7
class ChainCollection
8
{
9
    public $data = [];
10
11 14
    public function forgetAbout($manager, $models, $event = null)
12
    {
13 14
        $models = is_array($models[0]) ? $models[0] : $models;
14
15 14
        foreach ($models as $model) {
16 14
            if ($event) {
17 4
                unset($this->data[$manager][$model][$event]);
18
            } else {
19 14
                unset($this->data[$manager][$model]);
20
            }
21
        }
22 14
    }
23
24 106
    public function commitChain()
25
    {
26 106
        $chain = resolve('heyman.chain');
27 106
        $callback = resolve(ReactionFactory::class)->make();
28 106
        $manager = $chain->get('manager');
29 106
        $switchableListener = resolve(HeyManSwitcher::class)->wrapForIgnorance($callback, $manager);
30 106
        $event = $chain->get('event');
31
32 106
        foreach ($chain->get('watchedEntities') as $value) {
33 106
            $this->data[$manager][$value][$event][] = $switchableListener;
34
        }
35 106
    }
36
37
    /**
38
     * initialize the chain.
39
     *
40
     * @param $manager
41
     * @param  array  $values
42
     * @param  string  $param
43
     */
44 116
    public function init($manager, array $values, string $param = 'default')
45
    {
46 116
        $chain = resolve('heyman.chain');
47 116
        $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

47
        $chain->/** @scrutinizer ignore-call */ 
48
                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...
48 116
        $chain->set('watchedEntities', $values);
49 116
        $chain->set('event', $param);
50 116
    }
51
}
52