Test Failed
Push — main ( f68dd4...f46f5c )
by Bingo
14:33
created

CallableElementUtil::getCalledProcessDefinition()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 25
rs 9.4888
cc 5
nc 5
nop 4
1
<?php
2
3
namespace Jabe\Engine\Impl\Util;
4
5
use Jabe\Engine\ProcessEngineException;
6
use Jabe\Engine\Delegate\VariableScopeInterface;
7
use Jabe\Engine\Impl\Context\Context;
8
use Jabe\Engine\Impl\Core\Model\BaseCallableElement;
9
use Jabe\Engine\Impl\El\StartProcessVariableScope;
10
use Jabe\Engine\Impl\Persistence\Deploy\Cache\DeploymentCache;
11
use Jabe\Engine\Impl\Persistence\Entity\ProcessDefinitionEntity;
12
use Jabe\Engine\Impl\Pvm\Process\ProcessDefinitionImpl;
13
use Jabe\Engine\Repository\ProcessDefinitionInterface;
14
15
class CallableElementUtil
16
{
17
    public static function getDeploymentCache(): DeploymentCache
18
    {
19
        return Context::getProcessEngineConfiguration()
20
            ->getDeploymentCache();
0 ignored issues
show
Bug introduced by
The method getDeploymentCache() does not exist on Jabe\Engine\Impl\Cfg\Pro...EngineConfigurationImpl. ( Ignorable by Annotation )

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

20
            ->/** @scrutinizer ignore-call */ getDeploymentCache();

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...
21
    }
22
23
    public static function getProcessDefinitionToCall(
24
        VariableScopeInterface $execution,
25
        string $defaultTenantId,
26
        BaseCallableElement $callableElement
27
    ): ProcessDefinitionImpl {
28
        $processDefinitionKey = $callableElement->getDefinitionKey($execution);
29
        $tenantId = $callableElement->getDefinitionTenantId($execution, $defaultTenantId);
0 ignored issues
show
Unused Code introduced by
The call to Jabe\Engine\Impl\Core\Mo...getDefinitionTenantId() has too many arguments starting with $defaultTenantId. ( Ignorable by Annotation )

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

29
        /** @scrutinizer ignore-call */ 
30
        $tenantId = $callableElement->getDefinitionTenantId($execution, $defaultTenantId);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
30
31
        return self::getCalledProcessDefinition($execution, $callableElement, $processDefinitionKey, $tenantId);
32
    }
33
34
    public static function getStaticallyBoundProcessDefinition(
35
        string $callingProcessDefinitionId,
0 ignored issues
show
Unused Code introduced by
The parameter $callingProcessDefinitionId is not used and could be removed. ( Ignorable by Annotation )

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

35
        /** @scrutinizer ignore-unused */ string $callingProcessDefinitionId,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
        string $activityId,
0 ignored issues
show
Unused Code introduced by
The parameter $activityId is not used and could be removed. ( Ignorable by Annotation )

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

36
        /** @scrutinizer ignore-unused */ string $activityId,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
        BaseCallableElement $callableElement,
38
        ?string $tenantId
39
    ): ?ProcessDefinitionInterface {
40
        if ($callableElement->hasDynamicReferences()) {
0 ignored issues
show
Bug introduced by
The method hasDynamicReferences() does not exist on Jabe\Engine\Impl\Core\Model\BaseCallableElement. ( Ignorable by Annotation )

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

40
        if ($callableElement->/** @scrutinizer ignore-call */ hasDynamicReferences()) {

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...
41
            return null;
42
        }
43
44
        $emptyVariableScope = StartProcessVariableScope::getSharedInstance();
45
46
        $targetTenantId = $callableElement->getDefinitionTenantId($emptyVariableScope, $tenantId);
0 ignored issues
show
Unused Code introduced by
The call to Jabe\Engine\Impl\Core\Mo...getDefinitionTenantId() has too many arguments starting with $tenantId. ( Ignorable by Annotation )

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

46
        /** @scrutinizer ignore-call */ 
47
        $targetTenantId = $callableElement->getDefinitionTenantId($emptyVariableScope, $tenantId);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
47
48
        try {
49
            $processDefinitionKey = $callableElement->getDefinitionKey($emptyVariableScope);
50
            return self::getCalledProcessDefinition($emptyVariableScope, $callableElement, $processDefinitionKey, $targetTenantId);
51
        } catch (\Exception $e) {
52
            //UTIL_LOGGER.debugCouldNotResolveCallableElement(callingProcessDefinitionId, activityId, e);
53
            return null;
54
        }
55
    }
56
57
    private static function getCalledProcessDefinition(
58
        VariableScopeInterface $execution,
59
        BaseCallableElement $callableElement,
60
        string $processDefinitionKey,
61
        string $tenantId
62
    ): ProcessDefinitionEntity {
63
64
        $deploymentCache = getDeploymentCache();
0 ignored issues
show
Bug introduced by
The function getDeploymentCache was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

64
        $deploymentCache = /** @scrutinizer ignore-call */ getDeploymentCache();
Loading history...
65
66
        $processDefinition = null;
67
68
        if ($callableElement->isLatestBinding()) {
69
            $processDefinition = $deploymentCache->findDeployedLatestProcessDefinitionByKeyAndTenantId($processDefinitionKey, $tenantId);
70
        } elseif ($callableElement->isDeploymentBinding()) {
71
            $deploymentId = $callableElement->getDeploymentId();
72
            $processDefinition = $deploymentCache->findDeployedProcessDefinitionByDeploymentAndKey($deploymentId, $processDefinitionKey);
73
        } elseif ($callableElement->isVersionBinding()) {
74
            $version = $callableElement->getVersion($execution);
75
            $processDefinition = $deploymentCache->findDeployedProcessDefinitionByKeyVersionAndTenantId($processDefinitionKey, $version, $tenantId);
76
        } elseif ($callableElement->isVersionTagBinding()) {
77
            $versionTag = $callableElement->getVersionTag($execution);
78
            $processDefinition = $deploymentCache->findDeployedProcessDefinitionByKeyVersionTagAndTenantId($processDefinitionKey, $versionTag, $tenantId);
79
        }
80
81
        return $processDefinition;
82
    }
83
}
84