Test Failed
Push — main ( 92cbf8...131025 )
by Bingo
08:08
created

UpdateProcessDefinitionSuspensionStateBuilderImpl   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 18
eloc 42
c 1
b 0
f 0
dl 0
loc 118
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A processDefinitionTenantId() 0 7 1
A getProcessDefinitionKey() 0 3 1
A isTenantIdSet() 0 3 1
A getProcessDefinitionTenantId() 0 3 1
A getProcessDefinitionId() 0 3 1
A validateParameters() 0 10 3
A executionDate() 0 4 1
A activate() 0 6 1
A includeProcessInstances() 0 4 1
A byProcessDefinitionKey() 0 5 1
A byProcessDefinitionId() 0 5 1
A processDefinitionWithoutTenantId() 0 5 1
A __construct() 0 3 1
A isIncludeProcessInstances() 0 3 1
A getExecutionDate() 0 3 1
A suspend() 0 6 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Repository;
4
5
use Jabe\Engine\Impl\ProcessEngineLogger;
6
use Jabe\Engine\Impl\Cmd\{
7
    ActivateProcessDefinitionCmd,
8
    CommandLogger,
9
    SuspendProcessDefinitionCmd
10
};
11
use Jabe\Engine\Impl\Interceptor\CommandExecutorInterface;
12
use Jabe\Engine\Impl\Util\EnsureUtil;
13
use Jabe\Engine\Repository\{
14
    UpdateProcessDefinitionSuspensionStateBuilderInterface,
15
    UpdateProcessDefinitionSuspensionStateSelectBuilderInterface,
16
    UpdateProcessDefinitionSuspensionStateTenantBuilderInterface
17
};
18
19
class UpdateProcessDefinitionSuspensionStateBuilderImpl implements UpdateProcessDefinitionSuspensionStateBuilderInterface, UpdateProcessDefinitionSuspensionStateSelectBuilderInterface, UpdateProcessDefinitionSuspensionStateTenantBuilderInterface
20
{
21
    //private final static CommandLogger LOG = ProcessEngineLogger.CMD_LOGGER;
22
23
    protected $commandExecutor;
24
25
    protected $processDefinitionKey;
26
    protected $processDefinitionId;
27
28
    protected $includeProcessInstances = false;
29
    protected $executionDate;
30
31
    protected $processDefinitionTenantId;
32
    protected $isTenantIdSet = false;
33
34
    public function __construct(CommandExecutorInterface $commandExecutor = null)
35
    {
36
        $this->commandExecutor = $commandExecutor;
37
    }
38
39
    public function byProcessDefinitionId(string $processDefinitionId): UpdateProcessDefinitionSuspensionStateBuilderImpl
40
    {
41
        EnsureUtil::ensureNotNull("processDefinitionId", "processDefinitionId", $processDefinitionId);
42
        $this->processDefinitionId = $processDefinitionId;
43
        return $this;
44
    }
45
46
    public function byProcessDefinitionKey(string $processDefinitionKey): UpdateProcessDefinitionSuspensionStateBuilderImpl
47
    {
48
        EnsureUtil::ensureNotNull("processDefinitionKey", "processDefinitionKey", $processDefinitionKey);
49
        $this->processDefinitionKey = $processDefinitionKey;
50
        return $this;
51
    }
52
53
    public function includeProcessInstances(bool $includeProcessInstance): UpdateProcessDefinitionSuspensionStateBuilderImpl
54
    {
55
        $this->includeProcessInstances = $includeProcessInstance;
56
        return $this;
57
    }
58
59
    public function executionDate(string $date): UpdateProcessDefinitionSuspensionStateBuilderImpl
60
    {
61
        $this->executionDate = $date;
62
        return $this;
63
    }
64
65
    public function processDefinitionWithoutTenantId(): UpdateProcessDefinitionSuspensionStateBuilderImpl
66
    {
67
        $this->processDefinitionTenantId = null;
68
        $this->isTenantIdSet = true;
69
        return $this;
70
    }
71
72
    public function processDefinitionTenantId(string $tenantId): UpdateProcessDefinitionSuspensionStateBuilderImpl
73
    {
74
        EnsureUtil::ensureNotNull("tenantId", "tenantId", $tenantId);
75
76
        $this->processDefinitionTenantId = $tenantId;
77
        $this->isTenantIdSet = true;
78
        return $this;
79
    }
80
81
    public function activate(): void
82
    {
83
        $this->validateParameters();
84
85
        $command = new ActivateProcessDefinitionCmd($this);
86
        $this->commandExecutor->execute($command);
0 ignored issues
show
Bug introduced by
The method execute() 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

86
        $this->commandExecutor->/** @scrutinizer ignore-call */ 
87
                                execute($command);

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...
87
    }
88
89
    public function suspend(): void
90
    {
91
        $this->validateParameters();
92
93
        $command = new SuspendProcessDefinitionCmd($this);
94
        $this->commandExecutor->execute($command);
95
    }
96
97
    protected function validateParameters(): void
98
    {
99
        EnsureUtil::ensureOnlyOneNotNull("Need to specify either a process instance id or a process definition key.", $this->processDefinitionId, $this->processDefinitionKey);
100
101
        if ($this->processDefinitionId !== null && $this->isTenantIdSet) {
102
            //throw LOG.exceptionUpdateSuspensionStateForTenantOnlyByProcessDefinitionKey();
103
            throw new \Exception("exceptionUpdateSuspensionStateForTenantOnlyByProcessDefinitionKey");
104
        }
105
106
        EnsureUtil::ensureNotNull("commandExecutor", "commandExecutor", $this->commandExecutor);
107
    }
108
109
    public function getProcessDefinitionKey(): string
110
    {
111
        return $this->processDefinitionKey;
112
    }
113
114
    public function getProcessDefinitionId(): string
115
    {
116
        return $this->processDefinitionId;
117
    }
118
119
    public function isIncludeProcessInstances(): bool
120
    {
121
        return $this->includeProcessInstances;
122
    }
123
124
    public function getExecutionDate(): string
125
    {
126
        return $this->executionDate;
127
    }
128
129
    public function getProcessDefinitionTenantId(): string
130
    {
131
        return $this->processDefinitionTenantId;
132
    }
133
134
    public function isTenantIdSet(): bool
135
    {
136
        return $this->isTenantIdSet;
137
    }
138
}
139