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

HistoricDetailQueryImpl   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 351
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 54
eloc 125
c 1
b 0
f 1
dl 0
loc 351
rs 6.4799

47 Methods

Rating   Name   Duplication   Size   Complexity  
A isInitial() 0 3 1
A variableTypeIn() 0 5 1
A orderPartiallyByOccurrence() 0 4 1
A activityId() 0 4 1
A __construct() 0 3 1
A getExcludeTaskRelated() 0 3 1
A getOccurredBefore() 0 3 1
A variableUpdates() 0 4 1
A getActivityId() 0 3 1
A activityInstanceId() 0 4 1
A orderByTenantId() 0 3 1
A shouldFetchValue() 0 5 2
A lowerCase() 0 6 2
A excludeTaskDetails() 0 4 1
A isTenantIdSet() 0 3 1
A orderByVariableType() 0 4 1
A initial() 0 4 1
A executeCount() 0 6 1
A orderByVariableName() 0 4 1
A userOperationId() 0 5 1
A taskId() 0 4 1
A orderByVariableRevision() 0 4 1
A disableCustomObjectDeserialization() 0 4 1
A occurredBefore() 0 5 1
A executionId() 0 4 1
A variableInstanceId() 0 5 1
A orderByProcessInstanceId() 0 4 1
A getTaskId() 0 3 1
A executeList() 0 22 6
A tenantIdIn() 0 6 1
A withoutTenantId() 0 5 1
A orderByFormPropertyId() 0 4 1
A occurredAfter() 0 5 1
A processInstanceIdIn() 0 5 1
A getOccurredAfter() 0 3 1
A formProperties() 0 4 1
A detailId() 0 5 1
A processInstanceId() 0 4 1
A disableBinaryFetching() 0 4 1
A formFields() 0 4 1
A getType() 0 3 1
A getProcessInstanceId() 0 3 1
A getExecutionId() 0 3 1
A getDetailId() 0 3 1
A sequenceCounter() 0 4 1
A getProcessInstanceIds() 0 3 1
A orderByTime() 0 4 1

How to fix   Complexity   

Complex Class

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

1
<?php
2
3
namespace Jabe\Engine\Impl;
4
5
use Jabe\Engine\History\HistoricDetailQueryInterface;
6
use Jabe\Engine\Impl\Cmd\CommandLogger;
7
use Jabe\Engine\Impl\Interceptor\{
8
    CommandContext,
9
    CommandExecutorInterface
10
};
11
use Jabe\Engine\Impl\Persistence\Entity\HistoricDetailVariableInstanceUpdateEntity;
12
use Jabe\Engine\Impl\Variable\Serializer\AbstractTypedValueSerializer;
13
14
class HistoricDetailQueryImpl extends AbstractQuery implements HistoricDetailQueryInterface
15
{
16
    //private final static CommandLogger LOG = ProcessEngineLogger.CMD_LOGGER;
17
18
    protected $detailId;
19
    protected $taskId;
20
    protected $processInstanceId;
21
    //protected String caseInstanceId;
22
    protected $executionId;
23
    //protected String caseExecutionId;
24
    protected $activityId;
25
    protected $activityInstanceId;
26
    protected $type;
27
    protected $variableInstanceId;
28
    protected $variableTypes = [];
29
    protected $tenantIds = [];
30
    protected $isTenantIdSet;
31
    protected $processInstanceIds = [];
32
    protected $userOperationId;
33
    protected $sequenceCounter;
34
    protected $occurredBefore;
35
    protected $occurredAfter;
36
    protected $initial = false;
37
    protected $excludeTaskRelated = false;
38
    protected $isByteArrayFetchingEnabled = true;
39
    protected $isCustomObjectDeserializationEnabled = true;
40
41
    public function __construct(CommandExecutorInterface $commandExecutor = null)
42
    {
43
        parent::__construct($commandExecutor);
44
    }
45
46
    public function detailId(string $id): HistoricDetailQueryInterface
47
    {
48
        EnsureUtil::ensureNotNull("detailId", "id", $id);
0 ignored issues
show
Bug introduced by
The type Jabe\Engine\Impl\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...
49
        $this->detailId = $id;
50
        return $this;
51
    }
52
53
    public function variableInstanceId(string $variableInstanceId): HistoricDetailQueryInterface
54
    {
55
        EnsureUtil::ensureNotNull("variableInstanceId", "variableInstanceId", $variableInstanceId);
56
        $this->variableInstanceId = $variableInstanceId;
57
        return $this;
58
    }
59
60
    public function variableTypeIn(array $variableTypes): HistoricDetailQueryInterface
61
    {
62
        EnsureUtil::ensureNotNull("Variable types", "variableTypes", $variableTypes);
63
        $this->variableTypes = $this->lowerCase($variableTypes);
64
        return $this;
65
    }
66
67
    private function lowerCase(array $variableTypes): array
68
    {
69
        for ($i = 0; $i < count($variableTypes); $i += 1) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
70
            $variableTypes[$i] = strtolower($variableTypes[$i]);
71
        }
72
        return $variableTypes;
73
    }
74
75
    public function processInstanceId(string $processInstanceId): HistoricDetailQueryInterface
76
    {
77
        $this->processInstanceId = $processInstanceId;
78
        return $this;
79
    }
80
81
    /*public HistoricDetailQueryInterface caseInstanceId(string $caseInstanceId) {
82
        EnsureUtil::ensureNotNull("Case instance id", caseInstanceId);
83
        $this->caseInstanceId = caseInstanceId;
84
        return $this;
85
    }*/
86
87
    public function executionId(string $executionId): HistoricDetailQueryInterface
88
    {
89
        $this->executionId = $executionId;
90
        return $this;
91
    }
92
93
    /*public HistoricDetailQueryInterface caseExecutionId(string $caseExecutionId) {
94
        EnsureUtil::ensureNotNull("Case execution id", caseExecutionId);
95
        $this->caseExecutionId = caseExecutionId;
96
        return $this;
97
    }*/
98
99
    public function activityId(string $activityId): HistoricDetailQueryInterface
100
    {
101
        $this->activityId = $activityId;
102
        return $this;
103
    }
104
105
    public function activityInstanceId(string $activityInstanceId): HistoricDetailQueryInterface
106
    {
107
        $this->activityInstanceId = $activityInstanceId;
108
        return $this;
109
    }
110
111
    public function taskId(string $taskId): HistoricDetailQueryInterface
112
    {
113
        $this->taskId = $taskId;
114
        return $this;
115
    }
116
117
    public function formProperties(): HistoricDetailQueryInterface
118
    {
119
        $this->type = "FormProperty";
120
        return $this;
121
    }
122
123
    public function formFields(): HistoricDetailQueryInterface
124
    {
125
        $this->type = "FormProperty";
126
        return $this;
127
    }
128
129
    public function variableUpdates(): HistoricDetailQueryInterface
130
    {
131
        $this->type = "VariableUpdate";
132
        return $this;
133
    }
134
135
    public function tenantIdIn(array $tenantIds): HistoricDetailQueryInterface
136
    {
137
        EnsureUtil::ensureNotNull("tenantIds", "tenantIds", $tenantIds);
138
        $this->tenantIds = $tenantIds;
139
        $this->isTenantIdSet = true;
140
        return $this;
141
    }
142
143
    public function withoutTenantId(): HistoricDetailQueryInterface
144
    {
145
        $this->tenantIds = null;
146
        $this->isTenantIdSet = true;
147
        return $this;
148
    }
149
150
    public function processInstanceIdIn(array $processInstanceIds): HistoricDetailQueryInterface
151
    {
152
        EnsureUtil::ensureNotNull("Process Instance Ids", "processInstanceIds", $processInstanceIds);
153
        $this->processInstanceIds = $processInstanceIds;
154
        return $this;
155
    }
156
157
    public function userOperationId(string $userOperationId): HistoricDetailQueryInterface
158
    {
159
        EnsureUtil::ensureNotNull("userOperationId", "userOperationId", $userOperationId);
160
        $this->userOperationId = $userOperationId;
161
        return $this;
162
    }
163
164
    public function sequenceCounter(int $sequenceCounter): HistoricDetailQueryImpl
165
    {
166
        $this->sequenceCounter = $sequenceCounter;
167
        return $this;
168
    }
169
170
    public function excludeTaskDetails(): HistoricDetailQueryInterface
171
    {
172
        $this->excludeTaskRelated = true;
173
        return $this;
174
    }
175
176
    public function occurredBefore(string $date): HistoricDetailQueryInterface
177
    {
178
        EnsureUtil::ensureNotNull("occurred before", "date", $date);
179
        $this->occurredBefore = $date;
180
        return $this;
181
    }
182
183
    public function occurredAfter(string $date): HistoricDetailQueryInterface
184
    {
185
        EnsureUtil::ensureNotNull("occurred after", "date", $date);
186
        $this->occurredAfter = $date;
187
        return $this;
188
    }
189
190
    public function executeCount(CommandContext $commandContext): int
191
    {
192
        $this->checkQueryOk();
193
        return $commandContext
194
            ->getHistoricDetailManager()
195
            ->findHistoricDetailCountByQueryCriteria($this);
196
    }
197
198
    public function disableBinaryFetching(): HistoricDetailQueryInterface
199
    {
200
        $this->isByteArrayFetchingEnabled = false;
201
        return $this;
202
    }
203
204
    public function disableCustomObjectDeserialization(): HistoricDetailQueryInterface
205
    {
206
        $this->isCustomObjectDeserializationEnabled = false;
207
        return $this;
208
    }
209
210
    public function initial(): HistoricDetailQueryInterface
211
    {
212
        $this->initial = true;
213
        return $this;
214
    }
215
216
    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...
217
    {
218
        $this->checkQueryOk();
219
        $historicDetails = $commandContext
220
            ->getHistoricDetailManager()
221
            ->findHistoricDetailsByQueryCriteria($this, $page);
222
        if (!empty($historicDetails)) {
223
            foreach ($historicDetails as $historicDetail) {
224
                if ($historicDetail instanceof HistoricDetailVariableInstanceUpdateEntity) {
225
                    $entity = $historicDetail;
226
                    if ($this->shouldFetchValue($entity)) {
227
                        try {
228
                            $entity->getTypedValue($this->isCustomObjectDeserializationEnabled);
229
                        } catch (\Exception $t) {
230
                            // do not fail if one of the variables fails to load
231
                            //LOG.exceptionWhileGettingValueForVariable(t);
232
                        }
233
                    }
234
                }
235
            }
236
        }
237
        return $historicDetails;
238
    }
239
240
    protected function shouldFetchValue(HistoricDetailVariableInstanceUpdateEntity $entity): bool
241
    {
242
        // do not fetch values for byte arrays eagerly (unless requested by the user)
243
        return $this->isByteArrayFetchingEnabled
244
            || !in_array($entity->getSerializer()->getType()->getName(), AbstractTypedValueSerializer::BINARY_VALUE_TYPES);
245
    }
246
247
    // order by /////////////////////////////////////////////////////////////////
248
249
    public function orderByProcessInstanceId(): HistoricDetailQueryInterface
250
    {
251
        $this->orderBy(HistoricDetailQueryProperty::processInstanceId());
252
        return $this;
253
    }
254
255
    public function orderByTime(): HistoricDetailQueryInterface
256
    {
257
        $this->orderBy(HistoricDetailQueryProperty::time());
258
        return $this;
259
    }
260
261
    public function orderByVariableName(): HistoricDetailQueryInterface
262
    {
263
        $this->orderBy(HistoricDetailQueryProperty::variableName());
264
        return $this;
265
    }
266
267
    public function orderByFormPropertyId(): HistoricDetailQueryInterface
268
    {
269
        $this->orderBy(HistoricDetailQueryProperty::variableName());
270
        return $this;
271
    }
272
273
    public function orderByVariableRevision(): HistoricDetailQueryInterface
274
    {
275
        $this->orderBy(HistoricDetailQueryProperty::variableRevision());
276
        return $this;
277
    }
278
279
    public function orderByVariableType(): HistoricDetailQueryInterface
280
    {
281
        $this->orderBy(HistoricDetailQueryProperty::variableType());
282
        return $this;
283
    }
284
285
    public function orderPartiallyByOccurrence(): HistoricDetailQueryInterface
286
    {
287
        $this->orderBy(HistoricDetailQueryProperty::sequenceCounter());
288
        return $this;
289
    }
290
291
    public function orderByTenantId(): HistoricDetailQueryInterface
292
    {
293
        return orderBy(HistoricDetailQueryProperty::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

293
        return /** @scrutinizer ignore-call */ orderBy(HistoricDetailQueryProperty::tenantId());
Loading history...
294
    }
295
296
    // getters and setters //////////////////////////////////////////////////////
297
298
    public function getProcessInstanceId(): string
299
    {
300
        return $this->processInstanceId;
301
    }
302
303
    /*public String getCaseInstanceId() {
304
        return caseInstanceId;
305
    }*/
306
307
    public function getExecutionId(): string
308
    {
309
        return $this->executionId;
310
    }
311
312
    /*public function getCaseExecutionId(): string
313
    {
314
      return caseExecutionId;
315
    }*/
316
317
    public function getTaskId(): string
318
    {
319
        return $this->taskId;
320
    }
321
322
    public function getActivityId(): string
323
    {
324
        return $this->activityId;
325
    }
326
327
    public function getType(): string
328
    {
329
        return $this->type;
330
    }
331
332
    public function getExcludeTaskRelated(): bool
333
    {
334
        return $this->excludeTaskRelated;
335
    }
336
337
    public function getDetailId(): string
338
    {
339
        return $this->detailId;
340
    }
341
342
    public function getProcessInstanceIds(): array
343
    {
344
        return $this->processInstanceIds;
345
    }
346
347
    public function getOccurredBefore(): string
348
    {
349
        return $this->occurredBefore;
350
    }
351
352
    public function getOccurredAfter(): string
353
    {
354
        return $this->occurredAfter;
355
    }
356
357
    public function isTenantIdSet(): bool
358
    {
359
        return $this->isTenantIdSet;
360
    }
361
362
    public function isInitial(): bool
363
    {
364
        return $this->initial;
365
    }
366
}
367