Test Failed
Push — main ( 5f778a...f68dd4 )
by Bingo
06:33
created

ActivityBehaviorUtil::getActivityBehavior()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Util;
4
5
use Jabe\Engine\Impl\Pvm\{
6
    PvmActivityInterface,
7
    PvmException
8
};
9
use Jabe\Engine\Impl\Pvm\Delegate\ActivityBehaviorInterface;
10
use Jabe\Engine\Impl\Pvm\Runtime\PvmExecutionImpl;
11
use Jabe\Engine\Impl\Util\EnsureUtil;
12
13
class ActivityBehaviorUtil
14
{
15
    public static function getActivityBehavior(/*PvmExecutionImpl*/$execution): ?ActivityBehaviorInterface
16
    {
17
        if ($execution instanceof PvmExecutionImpl) {
18
            $id = $execution->getId();
19
20
            $activity = $execution->getActivity();
21
            EnsureUtil::ensureNotNull("Execution '" . $id . "' has no current activity.", "activity", $activity);
22
23
            $behavior = $activity->getActivityBehavior();
24
            EnsureUtil::ensureNotNull("There is no behavior specified in " . $activity . " for execution '" . $id . "'.", "behavior", $behavior);
25
26
            return $behavior;
27
        }
28
        return null;
29
    }
30
}
31