Test Failed
Push — main ( 5af89f...c76fcf )
by Bingo
05:51
created

ExecutionQueryImpl   B

Complexity

Total Complexity 45

Size/Duplication

Total Lines 285
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 45
eloc 104
c 1
b 0
f 0
dl 0
loc 285
rs 8.8

43 Methods

Rating   Name   Duplication   Size   Complexity  
A processInstanceBusinessKey() 0 5 1
A getEventSubscriptions() 0 3 1
A activityId() 0 4 1
A incidentType() 0 5 1
A getProcessInstanceId() 0 3 1
A incidentId() 0 5 1
A suspended() 0 4 1
A setEventSubscriptions() 0 3 1
A executeList() 0 7 1
A getProcessInstanceIds() 0 3 1
A incidentMessage() 0 5 1
A getIncidentType() 0 3 1
A setSuspensionState() 0 3 1
A processInstanceId() 0 5 1
A __construct() 0 3 1
A orderByProcessDefinitionKey() 0 4 1
A processVariableValueEquals() 0 4 1
A processDefinitionId() 0 5 1
A orderByProcessDefinitionId() 0 4 1
A messageEventSubscription() 0 3 1
A eventSubscription() 0 12 3
A getActivityId() 0 3 1
A signalEventSubscription() 0 3 1
A getProcessDefinitionId() 0 3 1
A active() 0 4 1
A getIncidentMessage() 0 3 1
A tenantIdIn() 0 6 1
A messageEventSubscriptionName() 0 3 1
A getExecutionId() 0 3 1
A orderByProcessInstanceId() 0 4 1
A processDefinitionKey() 0 5 1
A orderByTenantId() 0 4 1
A getProcessDefinitionKey() 0 3 1
A processVariableValueNotEquals() 0 4 1
A getIncidentMessageLike() 0 3 1
A incidentMessageLike() 0 5 1
A signalEventSubscriptionName() 0 3 1
A getBusinessKey() 0 3 1
A executionId() 0 5 1
A withoutTenantId() 0 5 1
A getIncidentId() 0 3 1
A getSuspensionState() 0 3 1
A executeCount() 0 7 1

How to fix   Complexity   

Complex Class

Complex classes like ExecutionQueryImpl often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ExecutionQueryImpl, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Jabe\Engine\Impl;
4
5
use Jabe\Engine\Impl\Event\EventType;
6
use Jabe\Engine\Impl\Interceptor\{
7
    CommandContext,
8
    CommandExecutorInterface
9
};
10
use Jabe\Engine\Impl\Persistence\Entity\SuspensionState;
11
use Jabe\Engine\Impl\Util\EnsureUtil;
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Util\EnsureUtil was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Jabe\Engine\Runtime\ExecutionQueryInterface;
13
14
class ExecutionQueryImpl extends AbstractVariableQueryImpl implements ExecutionQueryInterface
15
{
16
    protected $processDefinitionId;
17
    protected $processDefinitionKey;
18
    protected $businessKey;
19
    protected $activityId;
20
    protected $executionId;
21
    protected $processInstanceId;
22
    protected $eventSubscriptions;
23
    protected $suspensionState;
24
    protected $incidentType;
25
    protected $incidentId;
26
    protected $incidentMessage;
27
    protected $incidentMessageLike;
28
29
    protected $isTenantIdSet = false;
30
    protected $tenantIds = [];
31
32
    public function __construct(CommandExecutorInterface $commandExecutor)
33
    {
34
        parent::__construct($commandExecutor);
35
    }
36
37
    public function processDefinitionId(string $processDefinitionId): ExecutionQueryImpl
38
    {
39
        EnsureUtil::ensureNotNull("Process definition id", "processDefinitionId", $processDefinitionId);
40
        $this->processDefinitionId = $processDefinitionId;
41
        return $this;
42
    }
43
44
    public function processDefinitionKey(string $processDefinitionKey): ExecutionQueryImpl
45
    {
46
        EnsureUtil::ensureNotNull("Process definition key", "processDefinitionKey", $processDefinitionKey);
47
        $this->processDefinitionKey = $processDefinitionKey;
48
        return $this;
49
    }
50
51
    public function processInstanceId(string $processInstanceId): ExecutionQueryImpl
52
    {
53
        EnsureUtil::ensureNotNull("Process instance id", "processInstanceId", $processInstanceId);
54
        $this->processInstanceId = $processInstanceId;
55
        return $this;
56
    }
57
58
    public function processInstanceBusinessKey(string $businessKey): ExecutionQueryInterface
59
    {
60
        EnsureUtil::ensureNotNull("Business key", "businessKey", $businessKey);
61
        $this->businessKey = $businessKey;
62
        return $this;
63
    }
64
65
    public function executionId(string $executionId): ExecutionQueryImpl
66
    {
67
        EnsureUtil::ensureNotNull("Execution id", "executionId", $executionId);
68
        $this->executionId = $executionId;
69
        return $this;
70
    }
71
72
    public function activityId(string $activityId): ExecutionQueryImpl
73
    {
74
        $this->activityId = $activityId;
75
        return $this;
76
    }
77
78
    public function signalEventSubscription(string $signalName): ExecutionQueryInterface
79
    {
80
        return $this->eventSubscription(EventType::signal(), $signalName);
81
    }
82
83
    public function signalEventSubscriptionName(string $signalName): ExecutionQueryInterface
84
    {
85
        return $this->eventSubscription(EventType::signal(), $signalName);
86
    }
87
88
    public function messageEventSubscriptionName(string $messageName): ExecutionQueryInterface
89
    {
90
        return $this->eventSubscription(EventType::message(), $messageName);
91
    }
92
93
    public function messageEventSubscription(): ExecutionQueryInterface
94
    {
95
        return $this->eventSubscription(EventType::message(), null);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type string expected by parameter $eventName of Jabe\Engine\Impl\Executi...pl::eventSubscription(). ( Ignorable by Annotation )

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

95
        return $this->eventSubscription(EventType::message(), /** @scrutinizer ignore-type */ null);
Loading history...
96
    }
97
98
    public function eventSubscription(EventType $eventType, string $eventName): ExecutionQueryInterface
99
    {
100
        EnsureUtil::ensureNotNull("event type", "eventType", $eventType);
101
        if (EventType::message() != $eventType) {
102
            // event name is optional for message events
103
            EnsureUtil::ensureNotNull("event name", "eventName", $eventName);
104
        }
105
        if (empty($this->eventSubscriptions)) {
106
            $this->eventSubscriptions = [];
107
        }
108
        $this->eventSubscriptions[] = new EventSubscriptionQueryValue($eventName, $eventType->name());
109
        return $this;
110
    }
111
112
    public function suspended(): ExecutionQueryInterface
113
    {
114
        $this->suspensionState = SuspensionState::suspended();
115
        return $this;
116
    }
117
118
    public function active(): ExecutionQueryInterface
119
    {
120
        $this->suspensionState = SuspensionState::active();
121
        return $this;
122
    }
123
124
    public function processVariableValueEquals(string $variableName, $variableValue): ExecutionQueryInterface
125
    {
126
        $this->addVariable($variableName, $variableValue, QueryOperator::EQUALS, false);
127
        return $this;
128
    }
129
130
    public function processVariableValueNotEquals(string $variableName, $variableValue): ExecutionQueryInterface
131
    {
132
        $this->addVariable($variableName, $variableValue, QueryOperator::NOT_EQUALS, false);
133
        return $this;
134
    }
135
136
    public function incidentType(string $incidentType): ExecutionQueryInterface
137
    {
138
        EnsureUtil::ensureNotNull("incident type", "incidentType", $incidentType);
139
        $this->incidentType = $incidentType;
140
        return $this;
141
    }
142
143
    public function incidentId(string $incidentId): ExecutionQueryInterface
144
    {
145
        EnsureUtil::ensureNotNull("incident id", "incidentId", $incidentId);
146
        $this->incidentId = $incidentId;
147
        return $this;
148
    }
149
150
    public function incidentMessage(string $incidentMessage): ExecutionQueryInterface
151
    {
152
        EnsureUtil::ensureNotNull("incident message", "incidentMessage", $incidentMessage);
153
        $this->incidentMessage = $incidentMessage;
154
        return $this;
155
    }
156
157
    public function incidentMessageLike(string $incidentMessageLike): ExecutionQueryInterface
158
    {
159
        EnsureUtil::ensureNotNull("incident messageLike", "incidentMessageLike", $incidentMessageLike);
160
        $this->incidentMessageLike = $incidentMessageLike;
161
        return $this;
162
    }
163
164
    public function tenantIdIn(array $tenantIds): ExecutionQueryInterface
165
    {
166
        EnsureUtil::ensureNotNull("tenantIds", "tenantIds", $tenantIds);
167
        $this->tenantIds = $tenantIds;
168
        $this->isTenantIdSet = true;
169
        return $this;
170
    }
171
172
    public function withoutTenantId(): ExecutionQueryInterface
173
    {
174
        $this->tenantIds = null;
175
        $this->isTenantIdSet = true;
176
        return $this;
177
    }
178
179
    //ordering ////////////////////////////////////////////////////
180
181
    public function orderByProcessInstanceId(): ExecutionQueryImpl
182
    {
183
        $this->orderBy(ExecutionQueryProperty::processInstanceId());
184
        return $this;
185
    }
186
187
    public function orderByProcessDefinitionId(): ExecutionQueryImpl
188
    {
189
        $this->orderBy(new QueryOrderingProperty(QueryOrderingProperty::RELATION_PROCESS_DEFINITION, ExecutionQueryProperty::processDefinitionId()));
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\QueryOrderingProperty was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
190
        return $this;
191
    }
192
193
    public function orderByProcessDefinitionKey(): ExecutionQueryImpl
194
    {
195
        $this->orderBy(new QueryOrderingProperty(QueryOrderingProperty::RELATION_PROCESS_DEFINITION, ExecutionQueryProperty::processDefinitionKey()));
196
        return $this;
197
    }
198
199
    public function orderByTenantId(): ExecutionQueryInterface
200
    {
201
        $this->orderBy(ExecutionQueryProperty::tenantId());
0 ignored issues
show
Bug Best Practice introduced by
The method Jabe\Engine\Impl\Executi...eryProperty::tenantId() is not static, but was called statically. ( Ignorable by Annotation )

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

201
        $this->orderBy(ExecutionQueryProperty::/** @scrutinizer ignore-call */ tenantId());
Loading history...
202
        return $this;
203
    }
204
205
    //results ////////////////////////////////////////////////////
206
    public function executeCount(CommandContext $commandContext): int
207
    {
208
        $this->checkQueryOk();
209
        $this->ensureVariablesInitialized();
210
        return $commandContext
211
        ->getExecutionManager()
212
        ->findExecutionCountByQueryCriteria($this);
213
    }
214
215
    public function executeList(CommandContext $commandContext, Page $page): array
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
216
    {
217
        $this->checkQueryOk();
218
        $this->ensureVariablesInitialized();
219
        return $commandContext
220
        ->getExecutionManager()
221
        ->findExecutionsByQueryCriteria($this, $page);
222
    }
223
224
    //getters ////////////////////////////////////////////////////
225
226
    public function getProcessDefinitionKey(): string
227
    {
228
        return $this->processDefinitionKey;
229
    }
230
231
    public function getProcessDefinitionId(): string
232
    {
233
        return $this->processDefinitionId;
234
    }
235
236
    public function getActivityId(): string
237
    {
238
        return $this->activityId;
239
    }
240
241
    public function getProcessInstanceId(): string
242
    {
243
        return $this->processInstanceId;
244
    }
245
246
    public function getProcessInstanceIds(): array
247
    {
248
        return [];
249
    }
250
251
    public function getBusinessKey(): string
252
    {
253
        return $this->businessKey;
254
    }
255
256
    public function getExecutionId(): string
257
    {
258
        return $this->executionId;
259
    }
260
261
    public function getSuspensionState(): SuspensionState
262
    {
263
        return $this->suspensionState;
264
    }
265
266
    public function setSuspensionState(SuspensionState $suspensionState): void
267
    {
268
        $this->suspensionState = $suspensionState;
269
    }
270
271
    public function getEventSubscriptions(): array
272
    {
273
        return $this->eventSubscriptions;
274
    }
275
276
    public function setEventSubscriptions(array $eventSubscriptions): void
277
    {
278
        $this->eventSubscriptions = $eventSubscriptions;
279
    }
280
281
    public function getIncidentId(): string
282
    {
283
        return $this->incidentId;
284
    }
285
286
    public function getIncidentType(): string
287
    {
288
        return $this->incidentType;
289
    }
290
291
    public function getIncidentMessage(): string
292
    {
293
        return $this->incidentMessage;
294
    }
295
296
    public function getIncidentMessageLike(): string
297
    {
298
        return $this->incidentMessageLike;
299
    }
300
}
301