Test Failed
Push — main ( c76fcf...a2096a )
by Bingo
14:02
created

HistoricActivityInstanceQueryImpl   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 326
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 55
eloc 115
c 1
b 0
f 1
dl 0
loc 326
rs 6

51 Methods

Rating   Name   Duplication   Size   Complexity  
A processInstanceId() 0 4 1
A orderByExecutionId() 0 4 1
A getActivityInstanceState() 0 3 1
A isUnfinished() 0 3 1
A taskAssignee() 0 4 1
A getFinishedAfter() 0 3 1
A finished() 0 4 1
A getActivityType() 0 3 1
A completeScope() 0 8 2
A processDefinitionId() 0 4 1
A orderByHistoricActivityInstanceStartTime() 0 4 1
A orderByActivityName() 0 4 1
A activityId() 0 4 1
A unfinished() 0 4 1
A orderByHistoricActivityInstanceId() 0 4 1
A orderByActivityType() 0 4 1
A orderByActivityId() 0 4 1
A orderByProcessDefinitionId() 0 4 1
A executeCount() 0 6 1
A finishedBefore() 0 4 1
A activityName() 0 4 1
A executionId() 0 4 1
A getActivityId() 0 3 1
A getStartedBefore() 0 3 1
A orderByHistoricActivityInstanceEndTime() 0 4 1
A startedAfter() 0 4 1
A getProcessInstanceId() 0 3 1
A executeList() 0 6 1
A withoutTenantId() 0 5 1
A canceled() 0 7 2
A activityType() 0 4 1
A __construct() 0 3 1
A getAssignee() 0 3 1
A isFinished() 0 3 1
A getActivityName() 0 3 1
A isTenantIdSet() 0 3 1
A getFinishedBefore() 0 3 1
A getStartedAfter() 0 3 1
A hasExcludingConditions() 0 5 3
A orderByProcessInstanceId() 0 4 1
A orderByHistoricActivityInstanceDuration() 0 4 1
A activityInstanceId() 0 4 1
A getExecutionId() 0 3 1
A startedBefore() 0 4 1
A activityNameLike() 0 4 1
A getProcessDefinitionId() 0 3 1
A finishedAfter() 0 4 1
A orderByTenantId() 0 3 1
A getActivityInstanceId() 0 3 1
A orderPartiallyByOccurrence() 0 4 1
A tenantIdIn() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like HistoricActivityInstanceQueryImpl 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 HistoricActivityInstanceQueryImpl, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Jabe\Engine\Impl;
4
5
use Jabe\Engine\ProcessEngineException;
6
use Jabe\Engine\History\HistoricActivityInstanceQueryInterface;
7
use Jabe\Engine\Impl\Interceptor\{
8
    CommandContext,
9
    CommandExecutorInterface
10
};
11
use Jabe\Engine\Impl\Pvm\Runtime\ActivityInstanceState;
12
use Jabe\Engine\Impl\Util\{
13
    CompareUtil,
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\Util\CompareUtil 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...
14
    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...
15
};
16
17
class HistoricActivityInstanceQueryImpl extends AbstractQuery implements HistoricActivityInstanceQueryInterface
18
{
19
    protected $activityInstanceId;
20
    protected $processInstanceId;
21
    protected $executionId;
22
    protected $processDefinitionId;
23
    protected $activityId;
24
    protected $activityName;
25
    protected $activityNameLike;
26
    protected $activityType;
27
    protected $assignee;
28
    protected $finished;
29
    protected $unfinished;
30
    protected $startedBefore;
31
    protected $startedAfter;
32
    protected $finishedBefore;
33
    protected $finishedAfter;
34
    protected $activityInstanceState;
35
    protected $tenantIds = [];
36
    protected $isTenantIdSet;
37
38
    public function __construct(CommandExecutor $commandExecutor = null)
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\CommandExecutor 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...
39
    {
40
        parent::__construct($commandExecutor);
41
    }
42
43
    public function executeCount(CommandContext $commandContext): int
44
    {
45
        $this->checkQueryOk();
46
        return $commandContext
47
        ->getHistoricActivityInstanceManager()
48
        ->findHistoricActivityInstanceCountByQueryCriteria($this);
49
    }
50
51
    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...
52
    {
53
        $this->checkQueryOk();
54
        return $commandContext
55
        ->getHistoricActivityInstanceManager()
56
        ->findHistoricActivityInstancesByQueryCriteria($this, $page);
57
    }
58
59
    public function processInstanceId(string $processInstanceId): HistoricActivityInstanceQueryImpl
60
    {
61
        $this->processInstanceId = $processInstanceId;
62
        return $this;
63
    }
64
65
    public function executionId(string $executionId): HistoricActivityInstanceQueryImpl
66
    {
67
        $this->executionId = $executionId;
68
        return $this;
69
    }
70
71
    public function processDefinitionId(string $processDefinitionId): HistoricActivityInstanceQueryImpl
72
    {
73
        $this->processDefinitionId = $processDefinitionId;
74
        return $this;
75
    }
76
77
    public function activityId(string $activityId): HistoricActivityInstanceQueryImpl
78
    {
79
        $this->activityId = $activityId;
80
        return $this;
81
    }
82
83
    public function activityName(string $activityName): HistoricActivityInstanceQueryImpl
84
    {
85
        $this->activityName = $activityName;
86
        return $this;
87
    }
88
89
    public function activityNameLike(string $activityNameLike): HistoricActivityInstanceQueryImpl
90
    {
91
        $this->activityNameLike = $activityNameLike;
92
        return $this;
93
    }
94
95
    public function activityType(string $activityType): HistoricActivityInstanceQueryImpl
96
    {
97
        $this->activityType = $activityType;
98
        return $this;
99
    }
100
101
    public function taskAssignee(string $assignee): HistoricActivityInstanceQueryImpl
102
    {
103
        $this->assignee = $assignee;
104
        return $this;
105
    }
106
107
    public function finished(): HistoricActivityInstanceQueryImpl
108
    {
109
        $this->finished = true;
110
        return $this;
111
    }
112
113
    public function unfinished(): HistoricActivityInstanceQueryImpl
114
    {
115
        $this->unfinished = true;
116
        return $this;
117
    }
118
119
    public function completeScope(): HistoricActivityInstanceQueryImpl
120
    {
121
        if ($this->activityInstanceState != null) {
122
            throw new ProcessEngineException("Already querying for activity instance state <" . $this->activityInstanceState . ">");
123
        }
124
125
        $this->activityInstanceState = ActivityInstanceState::scopeComplete();
126
        return $this;
127
    }
128
129
    public function canceled(): HistoricActivityInstanceQueryImpl
130
    {
131
        if ($this->activityInstanceState != null) {
132
            throw new ProcessEngineException("Already querying for activity instance state <" . $activityInstanceState . ">");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $activityInstanceState seems to be never defined.
Loading history...
133
        }
134
        $this->activityInstanceState = ActivityInstanceState::canceled();
135
        return $this;
136
    }
137
138
    public function startedAfter(string $date): HistoricActivityInstanceQueryImpl
139
    {
140
        $this->startedAfter = $date;
141
        return $this;
142
    }
143
144
    public function startedBefore(string $date): HistoricActivityInstanceQueryImpl
145
    {
146
        $this->startedBefore = $date;
147
        return $this;
148
    }
149
150
    public function finishedAfter(string $date): HistoricActivityInstanceQueryImpl
151
    {
152
        $this->finishedAfter = $date;
153
        return $this;
154
    }
155
156
    public function finishedBefore(string $date): HistoricActivityInstanceQueryImpl
157
    {
158
        $this->finishedBefore = $date;
159
        return $this;
160
    }
161
162
    public function tenantIdIn(array $tenantIds): HistoricActivityInstanceQueryInterface
163
    {
164
        EnsureUtil::ensureNotNull("tenantIds", "tenantIds", $tenantIds);
165
        $this->tenantIds = $tenantIds;
166
        $this->isTenantIdSet = true;
167
        return $this;
168
    }
169
170
    public function withoutTenantId(): HistoricActivityInstanceQueryInterface
171
    {
172
        $this->tenantIds = null;
173
        $this->isTenantIdSet = true;
174
        return $this;
175
    }
176
177
    protected function hasExcludingConditions(): bool
178
    {
179
        return parent::hasExcludingConditions()
180
        || CompareUtil::areNotInAscendingOrder($this->startedAfter, $this->startedBefore)
181
        || CompareUtil::areNotInAscendingOrder($this->finishedAfter, $this->finishedBefore);
182
    }
183
184
    // ordering /////////////////////////////////////////////////////////////////
185
186
    public function orderByHistoricActivityInstanceDuration(): HistoricActivityInstanceQueryImpl
187
    {
188
        $this->orderBy(HistoricActivityInstanceQueryProperty::duration());
189
        return $this;
190
    }
191
192
    public function orderByHistoricActivityInstanceEndTime(): HistoricActivityInstanceQueryImpl
193
    {
194
        $this->orderBy(HistoricActivityInstanceQueryProperty::end());
195
        return $this;
196
    }
197
198
    public function orderByExecutionId(): HistoricActivityInstanceQueryImpl
199
    {
200
        $this->orderBy(HistoricActivityInstanceQueryProperty::executionId());
201
        return $this;
202
    }
203
204
    public function orderByHistoricActivityInstanceId(): HistoricActivityInstanceQueryImpl
205
    {
206
        $this->orderBy(HistoricActivityInstanceQueryProperty::historicActivityInstanceId());
207
        return $this;
208
    }
209
210
    public function orderByProcessDefinitionId(): HistoricActivityInstanceQueryImpl
211
    {
212
        $this->orderBy(HistoricActivityInstanceQueryProperty::processDefinitionId());
213
        return $this;
214
    }
215
216
    public function orderByProcessInstanceId(): HistoricActivityInstanceQueryImpl
217
    {
218
        $this->orderBy(HistoricActivityInstanceQueryProperty::processInstanceId());
219
        return $this;
220
    }
221
222
    public function orderByHistoricActivityInstanceStartTime(): HistoricActivityInstanceQueryImpl
223
    {
224
        $this->orderBy(HistoricActivityInstanceQueryProperty::start());
225
        return $this;
226
    }
227
228
    public function orderByActivityId(): HistoricActivityInstanceQueryInterface
229
    {
230
        $this->orderBy(HistoricActivityInstanceQueryProperty::activityId());
231
        return $this;
232
    }
233
234
    public function orderByActivityName(): HistoricActivityInstanceQueryImpl
235
    {
236
        $this->orderBy(HistoricActivityInstanceQueryProperty::activityName());
237
        return $this;
238
    }
239
240
    public function orderByActivityType(): HistoricActivityInstanceQueryImpl
241
    {
242
        $this->orderBy(HistoricActivityInstanceQueryProperty::activityType());
243
        return $this;
244
    }
245
246
    public function orderPartiallyByOccurrence(): HistoricActivityInstanceQueryInterface
247
    {
248
        $this->orderBy(HistoricActivityInstanceQueryProperty::sequenceCounter());
249
        return $this;
250
    }
251
252
    public function orderByTenantId(): HistoricActivityInstanceQueryInterface
253
    {
254
        return orderBy(HistoricActivityInstanceQueryProperty::tenantId());
0 ignored issues
show
Bug introduced by
The function orderBy 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

254
        return /** @scrutinizer ignore-call */ orderBy(HistoricActivityInstanceQueryProperty::tenantId());
Loading history...
255
    }
256
257
    public function activityInstanceId(string $activityInstanceId): HistoricActivityInstanceQueryImpl
258
    {
259
        $this->activityInstanceId = $activityInstanceId;
260
        return $this;
261
    }
262
263
    // getters and setters //////////////////////////////////////////////////////
264
265
    public function getProcessInstanceId(): string
266
    {
267
        return $this->processInstanceId;
268
    }
269
270
    public function getExecutionId(): string
271
    {
272
        return $this->executionId;
273
    }
274
275
    public function getProcessDefinitionId(): string
276
    {
277
        return $this->processDefinitionId;
278
    }
279
280
    public function getActivityId(): string
281
    {
282
        return $this->activityId;
283
    }
284
285
    public function getActivityName(): string
286
    {
287
        return $this->activityName;
288
    }
289
290
    public function getActivityType(): string
291
    {
292
        return $this->activityType;
293
    }
294
295
    public function getAssignee(): string
296
    {
297
        return $this->assignee;
298
    }
299
300
    public function isFinished(): bool
301
    {
302
        return $this->finished;
303
    }
304
305
    public function isUnfinished(): bool
306
    {
307
        return $this->unfinished;
308
    }
309
310
    public function getActivityInstanceId(): string
311
    {
312
        return $this->activityInstanceId;
313
    }
314
315
    public function getStartedAfter(): string
316
    {
317
        return $this->startedAfter;
318
    }
319
320
    public function getStartedBefore(): string
321
    {
322
        return $this->startedBefore;
323
    }
324
325
    public function getFinishedAfter(): string
326
    {
327
        return $this->finishedAfter;
328
    }
329
330
    public function getFinishedBefore(): string
331
    {
332
        return $this->finishedBefore;
333
    }
334
335
    public function getActivityInstanceState(): ActivityInstanceState
336
    {
337
        return $this->activityInstanceState;
338
    }
339
340
    public function isTenantIdSet(): bool
341
    {
342
        return $this->isTenantIdSet;
343
    }
344
}
345