Test Failed
Push — main ( ea931b...8f4107 )
by Bingo
06:03
created

ModificationUtil::handleChildRemovalInScope()   B

Complexity

Conditions 8
Paths 14

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 28
rs 8.4444
cc 8
nc 14
nop 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Util;
4
5
use Jabe\Engine\Impl\Persistence\Entity\ExecutionEntity;
6
use Jabe\Engine\Impl\Pvm\Delegate\ModificationObserverBehaviorInterface;
7
use Jabe\Engine\Impl\Pvm\Process\{
8
    ActivityImpl,
9
    ScopeImpl
10
};
11
use Jabe\Engine\Impl\Pvm\Runtime\PvmExecutionImpl;
12
13
class ModificationUtil
14
{
15
    public static function handleChildRemovalInScope(ExecutionEntity $removedExecution): void
16
    {
17
        $activity = $removedExecution->getActivity();
18
        if ($activity === null) {
19
            if ($removedExecution->getSuperExecution() !== null) {
20
                $removedExecution = $removedExecution->getSuperExecution();
21
                $activity = $removedExecution->getActivity();
22
                if ($activity == null) {
23
                    return;
24
                }
25
            } else {
26
                return;
27
            }
28
        }
29
        $flowScope = $activity->getFlowScope();
30
31
        $scopeExecution = $removedExecution->getParentScopeExecution(false);
32
        $executionInParentScope = $removedExecution->isConcurrent() ? $removedExecution : $removedExecution->getParent();
33
34
        if ($flowScope->getActivityBehavior() != null && $flowScope->getActivityBehavior() instanceof ModificationObserverBehaviorInterface) {
35
            // let child removal be handled by the scope itself
36
            $behavior = $flowScope->getActivityBehavior();
37
            $behavior->destroyInnerInstance($executionInParentScope);
0 ignored issues
show
Bug introduced by
It seems like $executionInParentScope can also be of type null; however, parameter $concurrentExecution of Jabe\Engine\Impl\Pvm\Del...:destroyInnerInstance() does only seem to accept Jabe\Engine\Impl\Pvm\Del...ivityExecutionInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            $behavior->destroyInnerInstance(/** @scrutinizer ignore-type */ $executionInParentScope);
Loading history...
38
        } else {
39
            if ($executionInParentScope->isConcurrent()) {
0 ignored issues
show
Bug introduced by
The method isConcurrent() does not exist on null. ( Ignorable by Annotation )

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

39
            if ($executionInParentScope->/** @scrutinizer ignore-call */ isConcurrent()) {

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...
40
                $executionInParentScope->remove();
41
                $scopeExecution->tryPruneLastConcurrentChild();
42
                $scopeExecution->forceUpdate();
43
            }
44
        }
45
    }
46
}
47