Test Failed
Push — main ( f1b82a...d2d042 )
by Bingo
06:24
created

JsonTaskQueryConverter::toJsonObject()   C

Complexity

Conditions 12
Paths 64

Size

Total Lines 114
Code Lines 93

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 93
c 1
b 0
f 0
dl 0
loc 114
rs 5.726
cc 12
nc 64
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Jabe\Engine\Impl\Json;
4
5
use Jabe\Engine\Impl\{
6
    QueryOperator,
7
    QueryOrderingProperty,
8
    TaskQueryImpl,
9
    TaskQueryVariableValue
10
};
11
use Jabe\Engine\Impl\Persistence\Entity\SuspensionState;
12
use Jabe\Engine\Impl\Util\JsonUtil;
13
use Jabe\Engine\Task\{
14
    DelegationState,
15
    TaskQueryInterface
16
};
17
18
class JsonTaskQueryConverter extends JsonObjectConverter
19
{
20
    public const ID = "id";
21
    public const TASK_ID = "taskId";
22
    public const TASK_ID_IN = "taskIdIn";
23
    public const NAME = "name";
24
    public const NAME_NOT_EQUAL = "nameNotEqual";
25
    public const NAME_LIKE = "nameLike";
26
    public const NAME_NOT_LIKE = "nameNotLike";
27
    public const DESCRIPTION = "description";
28
    public const DESCRIPTION_LIKE = "descriptionLike";
29
    public const PRIORITY = "priority";
30
    public const MIN_PRIORITY = "minPriority";
31
    public const MAX_PRIORITY = "maxPriority";
32
    public const ASSIGNEE = "assignee";
33
    public const ASSIGNEE_LIKE = "assigneeLike";
34
    public const ASSIGNEE_IN = "assigneeIn";
35
    public const ASSIGNEE_NOT_IN = "assigneeNotIn";
36
    public const INVOLVED_USER = "involvedUser";
37
    public const OWNER = "owner";
38
    public const UNASSIGNED = "unassigned";
39
    public const ASSIGNED = "assigned";
40
    public const DELEGATION_STATE = "delegationState";
41
    public const CANDIDATE_USER = "candidateUser";
42
    public const CANDIDATE_GROUP = "candidateGroup";
43
    public const CANDIDATE_GROUPS = "candidateGroups";
44
    public const WITH_CANDIDATE_GROUPS = "withCandidateGroups";
45
    public const WITHOUT_CANDIDATE_GROUPS = "withoutCandidateGroups";
46
    public const WITH_CANDIDATE_USERS = "withCandidateUsers";
47
    public const WITHOUT_CANDIDATE_USERS = "withoutCandidateUsers";
48
    public const INCLUDE_ASSIGNED_TASKS = "includeAssignedTasks";
49
    public const INSTANCE_ID = "instanceId";
50
    public const PROCESS_INSTANCE_ID = "processInstanceId";
51
    public const PROCESS_INSTANCE_ID_IN = "processInstanceIdIn";
52
    public const EXECUTION_ID = "executionId";
53
    public const ACTIVITY_INSTANCE_ID_IN = "activityInstanceIdIn";
54
    public const CREATED = "created";
55
    public const CREATED_BEFORE = "createdBefore";
56
    public const CREATED_AFTER = "createdAfter";
57
    public const UPDATED_AFTER = "updatedAfter";
58
    public const KEY = "key";
59
    public const KEYS = "keys";
60
    public const KEY_LIKE = "keyLike";
61
    public const PARENT_TASK_ID = "parentTaskId";
62
    public const PROCESS_DEFINITION_KEY = "processDefinitionKey";
63
    public const PROCESS_DEFINITION_KEYS = "processDefinitionKeys";
64
    public const PROCESS_DEFINITION_ID = "processDefinitionId";
65
    public const PROCESS_DEFINITION_NAME = "processDefinitionName";
66
    public const PROCESS_DEFINITION_NAME_LIKE = "processDefinitionNameLike";
67
    public const PROCESS_INSTANCE_BUSINESS_KEY = "processInstanceBusinessKey";
68
    public const PROCESS_INSTANCE_BUSINESS_KEYS = "processInstanceBusinessKeys";
69
    public const PROCESS_INSTANCE_BUSINESS_KEY_LIKE = "processInstanceBusinessKeyLike";
70
    public const DUE = "due";
71
    public const DUE_DATE = "dueDate";
72
    public const DUE_BEFORE = "dueBefore";
73
    public const DUE_AFTER = "dueAfter";
74
    public const WITHOUT_DUE_DATE = "withoutDueDate";
75
    public const FOLLOW_UP = "followUp";
76
    public const FOLLOW_UP_DATE = "followUpDate";
77
    public const FOLLOW_UP_BEFORE = "followUpBefore";
78
    public const FOLLOW_UP_NULL_ACCEPTED = "followUpNullAccepted";
79
    public const FOLLOW_UP_AFTER = "followUpAfter";
80
    public const EXCLUDE_SUBTASKS = "excludeSubtasks";
81
    /*public const CASE_DEFINITION_KEY = "caseDefinitionKey";
82
    public const CASE_DEFINITION_ID = "caseDefinitionId";
83
    public const CASE_DEFINITION_NAME = "caseDefinitionName";
84
    public const CASE_DEFINITION_NAME_LIKE = "caseDefinitionNameLike";
85
    public const CASE_INSTANCE_ID = "caseInstanceId";
86
    public const CASE_INSTANCE_BUSINESS_KEY = "caseInstanceBusinessKey";
87
    public const CASE_INSTANCE_BUSINESS_KEY_LIKE = "caseInstanceBusinessKeyLike";
88
    public const CASE_EXECUTION_ID = "caseExecutionId";*/
89
    public const ACTIVE = "active";
90
    public const SUSPENDED = "suspended";
91
    public const PROCESS_VARIABLES = "processVariables";
92
    public const TASK_VARIABLES = "taskVariables";
93
    //public const CASE_INSTANCE_VARIABLES = "caseInstanceVariables";
94
    public const TENANT_IDS = "tenantIds";
95
    public const WITHOUT_TENANT_ID = "withoutTenantId";
96
    public const ORDERING_PROPERTIES = "orderingProperties";
97
    public const OR_QUERIES = "orQueries";
98
99
    //public const ORDER_BY = "orderBy";
100
101
    protected static $variableValueConverter;// = new JsonTaskQueryVariableValueConverter();
102
103
    public static function variableValueConverter(): JsonTaskQueryVariableValueConverter
104
    {
105
        if (self::$variableValueConverter === null) {
106
            self::$variableValueConverter = new JsonTaskQueryVariableValueConverter();
107
        }
108
        return self::$variableValueConverter;
109
    }
110
111
    public function toJsonObject(/*TaskQueryInterface*/$object, bool $isOrQueryActive = false): ?\stdClass
112
    {
113
        $json = JsonUtil::createObject();
114
        $query = $taskQuery;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $taskQuery seems to be never defined.
Loading history...
115
        JsonUtil::addField($json, self::TASK_ID, $query->getTaskId());
116
        JsonUtil::addArrayField($json, self::TASK_ID_IN, $query->getTaskIdIn());
117
        JsonUtil::addField($json, self::NAME, $query->getName());
118
        JsonUtil::addField($json, self::NAME_NOT_EQUAL, $query->getNameNotEqual());
119
        JsonUtil::addField($json, self::NAME_LIKE, $query->getNameLike());
120
        JsonUtil::addField($json, self::NAME_NOT_LIKE, $query->getNameNotLike());
121
        JsonUtil::addField($json, self::DESCRIPTION, $query->getDescription());
122
        JsonUtil::addField($json, self::DESCRIPTION_LIKE, $query->getDescriptionLike());
123
        JsonUtil::addField($json, self::PRIORITY, $query->getPriority());
124
        JsonUtil::addField($json, self::MIN_PRIORITY, $query->getMinPriority());
125
        JsonUtil::addField($json, self::MAX_PRIORITY, $query->getMaxPriority());
126
        JsonUtil::addField($json, self::ASSIGNEE, $query->getAssignee());
127
128
        if ($query->getAssigneeIn() != null) {
129
            JsonUtil::addArrayField(
130
                $json,
131
                self::ASSIGNEE_IN,
132
                $query->getAssigneeIn()
133
            );
134
        }
135
136
        if ($query->getAssigneeNotIn() != null) {
137
            JsonUtil::addArrayField(
138
                $json,
139
                self::ASSIGNEE_NOT_IN,
140
                $query->getAssigneeNotIn()
141
            );
142
        }
143
144
        JsonUtil::addField($json, self::ASSIGNEE_LIKE, $query->getAssigneeLike());
145
        JsonUtil::addField($json, self::INVOLVED_USER, $query->getInvolvedUser());
146
        JsonUtil::addField($json, self::OWNER, $query->getOwner());
147
        JsonUtil::addDefaultField($json, self::UNASSIGNED, false, $query->isUnassigned());
0 ignored issues
show
Bug introduced by
The method addDefaultField() does not exist on Jabe\Engine\Impl\Util\JsonUtil. ( Ignorable by Annotation )

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

147
        JsonUtil::/** @scrutinizer ignore-call */ 
148
                  addDefaultField($json, self::UNASSIGNED, false, $query->isUnassigned());

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...
148
        JsonUtil::addDefaultField($json, self::ASSIGNED, false, $query->isAssigned());
149
        JsonUtil::addField($json, self::DELEGATION_STATE, $query->getDelegationStateString());
150
        JsonUtil::addField($json, self::CANDIDATE_USER, $query->getCandidateUser());
151
        JsonUtil::addField($json, self::CANDIDATE_GROUP, $query->getCandidateGroup());
152
        JsonUtil::addListField($json, self::CANDIDATE_GROUPS, $query->getCandidateGroupsInternal());
153
        JsonUtil::addDefaultField($json, self::WITH_CANDIDATE_GROUPS, false, $query->isWithCandidateGroups());
154
        JsonUtil::addDefaultField($json, self::WITHOUT_CANDIDATE_GROUPS, false, $query->isWithoutCandidateGroups());
155
        JsonUtil::addDefaultField($json, self::WITH_CANDIDATE_USERS, false, $query->isWithCandidateUsers());
156
        JsonUtil::addDefaultField($json, self::WITHOUT_CANDIDATE_USERS, false, $query->isWithoutCandidateUsers());
157
        JsonUtil::addField($json, self::INCLUDE_ASSIGNED_TASKS, $query->isIncludeAssignedTasksInternal());
158
        JsonUtil::addField($json, self::PROCESS_INSTANCE_ID, $query->getProcessInstanceId());
159
        if ($query->getProcessInstanceIdIn() != null) {
160
            JsonUtil::addArrayField($json, self::PROCESS_INSTANCE_ID_IN, $query->getProcessInstanceIdIn());
161
        }
162
        JsonUtil::addField($json, self::EXECUTION_ID, $query->getExecutionId());
163
        JsonUtil::addArrayField($json, self::ACTIVITY_INSTANCE_ID_IN, $query->getActivityInstanceIdIn());
164
        JsonUtil::addDateField($json, self::CREATED, $query->getCreateTime());
165
        JsonUtil::addDateField($json, self::CREATED_BEFORE, $query->getCreateTimeBefore());
166
        JsonUtil::addDateField($json, self::CREATED_AFTER, $query->getCreateTimeAfter());
167
        JsonUtil::addDateField($json, self::UPDATED_AFTER, $query->getUpdatedAfter());
168
        JsonUtil::addField($json, self::KEY, $query->getKey());
169
        JsonUtil::addArrayField($json, self::KEYS, $query->getKeys());
170
        JsonUtil::addField($json, self::KEY_LIKE, $query->getKeyLike());
171
        JsonUtil::addField($json, self::PARENT_TASK_ID, $query->getParentTaskId());
172
        JsonUtil::addField($json, self::PROCESS_DEFINITION_KEY, $query->getProcessDefinitionKey());
173
        JsonUtil::addArrayField($json, self::PROCESS_DEFINITION_KEYS, $query->getProcessDefinitionKeys());
174
        JsonUtil::addField($json, self::PROCESS_DEFINITION_ID, $query->getProcessDefinitionId());
175
        JsonUtil::addField($json, self::PROCESS_DEFINITION_NAME, $query->getProcessDefinitionName());
176
        JsonUtil::addField($json, self::PROCESS_DEFINITION_NAME_LIKE, $query->getProcessDefinitionNameLike());
177
        JsonUtil::addField($json, self::PROCESS_INSTANCE_BUSINESS_KEY, $query->getProcessInstanceBusinessKey());
178
        JsonUtil::addArrayField($json, self::PROCESS_INSTANCE_BUSINESS_KEYS, $query->getProcessInstanceBusinessKeys());
179
        JsonUtil::addField($json, self::PROCESS_INSTANCE_BUSINESS_KEY_LIKE, $query->getProcessInstanceBusinessKeyLike());
180
        $this->addVariablesFields($json, $query->getVariables());
181
        JsonUtil::addDateField($json, self::DUE, $query->getDueDate());
182
        JsonUtil::addDateField($json, self::DUE_BEFORE, $query->getDueBefore());
183
        JsonUtil::addDateField($json, self::DUE_AFTER, $query->getDueAfter());
184
        JsonUtil::addDefaultField($json, self::WITHOUT_DUE_DATE, false, $query->isWithoutDueDate());
185
        JsonUtil::addDateField($json, self::FOLLOW_UP, $query->getFollowUpDate());
186
        JsonUtil::addDateField($json, self::FOLLOW_UP_BEFORE, $query->getFollowUpBefore());
187
        JsonUtil::addDefaultField($json, self::FOLLOW_UP_NULL_ACCEPTED, false, $query->isFollowUpNullAccepted());
188
        JsonUtil::addDateField($json, self::FOLLOW_UP_AFTER, $query->getFollowUpAfter());
189
        JsonUtil::addDefaultField($json, self::EXCLUDE_SUBTASKS, false, $query->isExcludeSubtasks());
190
        $this->addSuspensionStateField($json, $query->getSuspensionState());
191
        JsonUtil::addField($json, self::CASE_DEFINITION_KEY, $query->getCaseDefinitionKey());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...er::CASE_DEFINITION_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
192
        JsonUtil::addField($json, self::CASE_DEFINITION_ID, $query->getCaseDefinitionId());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...ter::CASE_DEFINITION_ID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
193
        JsonUtil::addField($json, self::CASE_DEFINITION_NAME, $query->getCaseDefinitionName());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...r::CASE_DEFINITION_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
194
        JsonUtil::addField($json, self::CASE_DEFINITION_NAME_LIKE, $query->getCaseDefinitionNameLike());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...SE_DEFINITION_NAME_LIKE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
195
        JsonUtil::addField($json, self::CASE_INSTANCE_ID, $query->getCaseInstanceId());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...erter::CASE_INSTANCE_ID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
196
        JsonUtil::addField($json, self::CASE_INSTANCE_BUSINESS_KEY, $query->getCaseInstanceBusinessKey());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...E_INSTANCE_BUSINESS_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
197
        JsonUtil::addField($json, self::CASE_INSTANCE_BUSINESS_KEY_LIKE, $query->getCaseInstanceBusinessKeyLike());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...TANCE_BUSINESS_KEY_LIKE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
198
        JsonUtil::addField($json, self::CASE_EXECUTION_ID, $query->getCaseExecutionId());
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\Js...rter::CASE_EXECUTION_ID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
199
        $this->addTenantIdFields($json, $query);
200
201
        if (count($query->getQueries()) > 1 && !$isOrQueryActive) {
202
            $orQueries = JsonUtil::createArray();
203
204
            foreach ($query->getQueries() as $orQuery) {
205
                if ($orQuery != null && $orQuery->isOrQueryActive()) {
206
                    $orQueries[] = $this->toJsonObject($orQuery, true);
207
                }
208
            }
209
            JsonUtil::addField($json, self::OR_QUERIES, $orQueries);
210
        }
211
212
        if ($query->getOrderingProperties() != null && !empty($query->getOrderingProperties())) {
213
            JsonUtil::addField(
214
                $json,
215
                self::ORDERING_PROPERTIES,
216
                JsonQueryOrderingPropertyConverter::arrayConverter()->toJsonArray($query->getOrderingProperties())
217
            );
218
        }
219
220
        // expressions
221
        foreach ($query->getExpressions() as $key => $value) {
222
            JsonUtil::addField($json, $key . "Expression", $value);
223
        }
224
        return $json;
225
    }
226
227
    protected function addSuspensionStateField($jsonObject, SuspensionState $suspensionState = null): void
228
    {
229
        if ($suspensionState != null) {
230
            if ($suspensionState->equals(SuspensionState::active())) {
231
                JsonUtil::addField($jsonObject, self::ACTIVE, true);
232
            } elseif ($suspensionState->equals(SuspensionState::suspended())) {
233
                JsonUtil::addField($jsonObject, self::SUSPENDED, true);
234
            }
235
        }
236
    }
237
238
    protected function addTenantIdFields($jsonObject, TaskQueryImpl $query): void
239
    {
240
        if ($query->getTenantIds() != null) {
241
            JsonUtil::addArrayField($jsonObject, self::TENANT_IDS, $query->getTenantIds());
242
        }
243
        if ($query->isWithoutTenantId()) {
244
            JsonUtil::addField($jsonObject, self::WITHOUT_TENANT_ID, true);
245
        }
246
    }
247
248
    protected function addVariablesFields($jsonObject, array $variables): void
249
    {
250
        foreach ($variables as $variable) {
251
            if ($variable->isProcessInstanceVariable()) {
252
                $this->addVariable($jsonObject, self::PROCESS_VARIABLES, $variable);
253
            } elseif ($variable->isLocal()) {
254
                $this->addVariable($jsonObject, self::TASK_VARIABLES, $variable);
255
            } else {
256
                //$this->addVariable($jsonObject, self::CASE_INSTANCE_VARIABLES, $variable);
257
            }
258
        }
259
    }
260
261
    protected function addVariable($jsonObject, string $variableType, TaskQueryVariableValue $variable): void
262
    {
263
        $variables = JsonUtil::getArray($jsonObject, $variableType);
264
        JsonUtil::addElement($variables, self::variableValueConverter(), $variable);
265
        JsonUtil::addField($jsonObject, $variableType, $variables);
266
    }
267
268
    public function toObject(\stdClass $jsonString, bool $isOrQuery = false)
269
    {
270
        $query = new TaskQueryImpl();
271
        if ($isOrQuery) {
272
            $query->setOrQueryActive();
273
        }
274
        if (property_exists($json, self::OR_QUERIES)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $json seems to be never defined.
Loading history...
275
            foreach (JsonUtil::getArray($json, self::OR_QUERIES) as $jsonElement) {
276
                $query->addOrQuery($this->toObject(JsonUtil::getObject($jsonElement), true));
277
            }
278
        }
279
        if (property_exists($json, self::TASK_ID)) {
280
            $query->taskId(JsonUtil::getString($json, self::TASK_ID));
281
        }
282
        if (property_exists($json, self::TASK_ID_IN)) {
283
            $query->taskIdIn(JsonUtil::getArray($json, self::TASK_ID_IN));
284
        }
285
        if (property_exists($json, self::NAME)) {
286
            $query->taskName(JsonUtil::getString($json, self::NAME));
287
        }
288
        if (property_exists($json, self::NAME_NOT_EQUAL)) {
289
            $query->taskNameNotEqual(JsonUtil::getString($json, self::NAME_NOT_EQUAL));
290
        }
291
        if (property_exists($json, self::NAME_LIKE)) {
292
            $query->taskNameLike(JsonUtil::getString($json, self::NAME_LIKE));
293
        }
294
        if (property_exists($json, self::NAME_NOT_LIKE)) {
295
            $query->taskNameNotLike(JsonUtil::getString($json, self::NAME_NOT_LIKE));
296
        }
297
        if (property_exists($json, self::DESCRIPTION)) {
298
            $query->taskDescription(JsonUtil::getString($json, self::DESCRIPTION));
299
        }
300
        if (property_exists($json, self::DESCRIPTION_LIKE)) {
301
            $query->taskDescriptionLike(JsonUtil::getString($json, self::DESCRIPTION_LIKE));
302
        }
303
        if (property_exists($json, self::PRIORITY)) {
304
            $query->taskPriority(JsonUtil::getInt($json, self::PRIORITY));
305
        }
306
        if (property_exists($json, self::MIN_PRIORITY)) {
307
            $query->taskMinPriority(JsonUtil::getInt($json, self::MIN_PRIORITY));
308
        }
309
        if (property_exists($json, self::MAX_PRIORITY)) {
310
            $query->taskMaxPriority(JsonUtil::getInt($json, self::MAX_PRIORITY));
311
        }
312
        if (property_exists($json, self::ASSIGNEE)) {
313
            $query->taskAssignee(JsonUtil::getString($json, self::ASSIGNEE));
314
        }
315
        if (property_exists($json, self::ASSIGNEE_LIKE)) {
316
            $query->taskAssigneeLike(JsonUtil::getString($json, self::ASSIGNEE_LIKE));
317
        }
318
        if (property_exists($json, self::ASSIGNEE_IN)) {
319
            $query->taskAssigneeIn(JsonUtil::getArray($json, self::ASSIGNEE_IN));
320
        }
321
        if (property_exists($json, self::ASSIGNEE_NOT_IN)) {
322
            $query->taskAssigneeNotIn(JsonUtil::getArray($json, self::ASSIGNEE_NOT_IN));
323
        }
324
        if (property_exists($json, self::INVOLVED_USER)) {
325
            $query->taskInvolvedUser(JsonUtil::getString($json, self::INVOLVED_USER));
326
        }
327
        if (property_exists($json, self::OWNER)) {
328
            $query->taskOwner(JsonUtil::getString($json, self::OWNER));
329
        }
330
        if (property_exists($json, self::ASSIGNED) && JsonUtil::getBoolean($json, self::ASSIGNED)) {
331
            $query->taskAssigned();
332
        }
333
        if (property_exists($json, self::UNASSIGNED) && JsonUtil::getBoolean($json, self::UNASSIGNED)) {
334
            $query->taskUnassigned();
335
        }
336
        if (property_exists($json, self::DELEGATION_STATE)) {
337
            $query->taskDelegationState(constant("DelegationState::" . JsonUtil::getString($json, self::DELEGATION_STATE)));
338
        }
339
        if (property_exists($json, self::CANDIDATE_USER)) {
340
            $query->taskCandidateUser(JsonUtil::getString($json, self::CANDIDATE_USER));
341
        }
342
        if (property_exists($json, self::CANDIDATE_GROUP)) {
343
            $query->taskCandidateGroup(JsonUtil::getString($json, self::CANDIDATE_GROUP));
344
        }
345
        if (property_exists($json, self::CANDIDATE_GROUPS) && !property_exists($json, self::CANDIDATE_USER) && !property_exists($json, self::CANDIDATE_GROUP)) {
346
            $query->taskCandidateGroupIn(JsonUtil::getArray($json, self::CANDIDATE_GROUPS));
347
        }
348
        if (property_exists($json, self::WITH_CANDIDATE_GROUPS) && JsonUtil::getBoolean($json, self::WITH_CANDIDATE_GROUPS)) {
349
            $query->withCandidateGroups();
350
        }
351
        if (property_exists($json, self::WITHOUT_CANDIDATE_GROUPS) && JsonUtil::getBoolean($json, self::WITHOUT_CANDIDATE_GROUPS)) {
352
            $query->withoutCandidateGroups();
353
        }
354
        if (property_exists($json, self::WITH_CANDIDATE_USERS) && JsonUtil::getBoolean($json, self::WITH_CANDIDATE_USERS)) {
355
            $query->withCandidateUsers();
356
        }
357
        if (property_exists($json, self::WITHOUT_CANDIDATE_USERS) && JsonUtil::getBoolean($json, self::WITHOUT_CANDIDATE_USERS)) {
358
            $query->withoutCandidateUsers();
359
        }
360
        if (property_exists($json, self::INCLUDE_ASSIGNED_TASKS) && JsonUtil::getBoolean($json, self::INCLUDE_ASSIGNED_TASKS)) {
361
            $query->includeAssignedTasksInternal();
362
        }
363
        if (property_exists($json, self::PROCESS_INSTANCE_ID)) {
364
            $query->processInstanceId(JsonUtil::getString($json, self::PROCESS_INSTANCE_ID));
365
        }
366
        if (property_exists($json, self::PROCESS_INSTANCE_ID_IN)) {
367
            $query->processInstanceIdIn(JsonUtil::getArray($json, self::PROCESS_INSTANCE_ID_IN));
368
        }
369
        if (property_exists($json, self::EXECUTION_ID)) {
370
            $query->executionId(JsonUtil::getString($json, self::EXECUTION_ID));
371
        }
372
        if (property_exists($json, self::ACTIVITY_INSTANCE_ID_IN)) {
373
            $query->activityInstanceIdIn(JsonUtil::getArray($json, self::ACTIVITY_INSTANCE_ID_IN));
374
        }
375
        if (property_exists($json, self::CREATED)) {
376
            $query->taskCreatedOn((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::CREATED))->format('c'));
377
        }
378
        if (property_exists($json, self::CREATED_BEFORE)) {
379
            $query->taskCreatedBefore((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::CREATED_BEFORE))->format('c'));
380
        }
381
        if (property_exists($json, self::CREATED_AFTER)) {
382
            $query->taskCreatedAfter((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::CREATED_AFTER))->format('c'));
383
        }
384
        if (property_exists($json, self::UPDATED_AFTER)) {
385
            $query->taskUpdatedAfter((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::UPDATED_AFTER))->format('c'));
0 ignored issues
show
Bug introduced by
The method taskUpdatedAfter() does not exist on Jabe\Engine\Impl\TaskQueryImpl. ( Ignorable by Annotation )

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

385
            $query->/** @scrutinizer ignore-call */ 
386
                    taskUpdatedAfter((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::UPDATED_AFTER))->format('c'));

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...
386
        }
387
        if (property_exists($json, self::KEY)) {
388
            $query->taskDefinitionKey(JsonUtil::getString($json, self::KEY));
389
        }
390
        if (property_exists($json, self::KEYS)) {
391
            $query->taskDefinitionKeyIn(JsonUtil::getArray($json, self::KEYS));
392
        }
393
        if (property_exists($json, self::KEY_LIKE)) {
394
            $query->taskDefinitionKeyLike(JsonUtil::getString($json, self::KEY_LIKE));
395
        }
396
        if (property_exists($json, self::PARENT_TASK_ID)) {
397
            $query->taskParentTaskId(JsonUtil::getString($json, self::PARENT_TASK_ID));
398
        }
399
        if (property_exists($json, self::PROCESS_DEFINITION_KEY)) {
400
            $query->processDefinitionKey(JsonUtil::getString($json, self::PROCESS_DEFINITION_KEY));
401
        }
402
        if (property_exists($json, self::PROCESS_DEFINITION_KEYS)) {
403
            $query->processDefinitionKeyIn(JsonUtil::getArray($json, self::PROCESS_DEFINITION_KEYS));
404
        }
405
        if (property_exists($json, self::PROCESS_DEFINITION_ID)) {
406
            $query->processDefinitionId(JsonUtil::getString($json, self::PROCESS_DEFINITION_ID));
407
        }
408
        if (property_exists($json, self::PROCESS_DEFINITION_NAME)) {
409
            $query->processDefinitionName(JsonUtil::getString($json, self::PROCESS_DEFINITION_NAME));
410
        }
411
        if (property_exists($json, self::PROCESS_DEFINITION_NAME_LIKE)) {
412
            $query->processDefinitionNameLike(JsonUtil::getString($json, self::PROCESS_DEFINITION_NAME_LIKE));
413
        }
414
        if (property_exists($json, self::PROCESS_INSTANCE_BUSINESS_KEY)) {
415
            $query->processInstanceBusinessKey(JsonUtil::getString($json, self::PROCESS_INSTANCE_BUSINESS_KEY));
416
        }
417
        if (property_exists($json, self::PROCESS_INSTANCE_BUSINESS_KEYS)) {
418
            $query->processInstanceBusinessKeyIn(JsonUtil::getArray($json, self::PROCESS_INSTANCE_BUSINESS_KEYS));
419
        }
420
        if (property_exists($json, self::PROCESS_INSTANCE_BUSINESS_KEY_LIKE)) {
421
            $query->processInstanceBusinessKeyLike(JsonUtil::getString($json, self::PROCESS_INSTANCE_BUSINESS_KEY_LIKE));
422
        }
423
        if (property_exists($json, self::TASK_VARIABLES)) {
424
            $this->addVariables($query, JsonUtil::getArray($json, self::TASK_VARIABLES), true, false);
425
        }
426
        if (property_exists($json, self::PROCESS_VARIABLES)) {
427
            $this->addVariables($query, JsonUtil::getArray($json, self::PROCESS_VARIABLES), false, true);
428
        }
429
        /*if (property_exists($json, self::CASE_INSTANCE_VARIABLES)) {
430
            addVariables(query, JsonUtil::getArray($json, self::CASE_INSTANCE_VARIABLES), false, false);
431
        }*/
432
        if (property_exists($json, self::DUE)) {
433
            $query->dueDate((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::DUE))->format('c'));
434
        }
435
        if (property_exists($json, self::DUE_BEFORE)) {
436
            $query->dueBefore((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::DUE_BEFORE))->format('c'));
437
        }
438
        if (property_exists($json, self::DUE_AFTER)) {
439
            $query->dueAfter((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::DUE_AFTER))->format('c'));
440
        }
441
        if (property_exists($json, self::WITHOUT_DUE_DATE)) {
442
            $query->withoutDueDate();
443
        }
444
        if (property_exists($json, self::FOLLOW_UP)) {
445
            $query->followUpDate((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::FOLLOW_UP))->format('c'));
446
        }
447
        if (property_exists($json, self::FOLLOW_UP_BEFORE)) {
448
            $query->followUpBefore((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::FOLLOW_UP_BEFORE))->format('c'));
449
        }
450
        if (property_exists($json, self::FOLLOW_UP_AFTER)) {
451
            $query->followUpAfter((new \DateTime())->setTimestamp(JsonUtil::getLong($json, self::FOLLOW_UP_AFTER))->format('c'));
452
        }
453
        if (property_exists($json, self::FOLLOW_UP_NULL_ACCEPTED)) {
454
            $query->setFollowUpNullAccepted(JsonUtil::getBoolean($json, self::FOLLOW_UP_NULL_ACCEPTED));
455
        }
456
        if (property_exists($json, self::EXCLUDE_SUBTASKS) && JsonUtil::getBoolean($json, self::EXCLUDE_SUBTASKS)) {
457
            $query->excludeSubtasks();
458
        }
459
        if (property_exists($json, self::SUSPENDED) && JsonUtil::getBoolean($json, self::SUSPENDED)) {
460
            $query->suspended();
461
        }
462
        if (property_exists($json, self::ACTIVE) && JsonUtil::getBoolean($json, self::ACTIVE)) {
463
            $query->active();
464
        }
465
        /*if (property_exists($json, self::CASE_DEFINITION_KEY)) {
466
            $query->caseDefinitionKey(JsonUtil::getString($json, self::CASE_DEFINITION_KEY));
467
        }
468
        if (property_exists($json, self::CASE_DEFINITION_ID)) {
469
            $query->caseDefinitionId(JsonUtil::getString($json, self::CASE_DEFINITION_ID));
470
        }
471
        if (property_exists($json, self::CASE_DEFINITION_NAME)) {
472
            $query->caseDefinitionName(JsonUtil::getString($json, self::CASE_DEFINITION_NAME));
473
        }
474
        if (property_exists($json, self::CASE_DEFINITION_NAME_LIKE)) {
475
            $query->caseDefinitionNameLike(JsonUtil::getString($json, self::CASE_DEFINITION_NAME_LIKE));
476
        }
477
        if (property_exists($json, self::CASE_INSTANCE_ID)) {
478
            $query->caseInstanceId(JsonUtil::getString($json, self::CASE_INSTANCE_ID));
479
        }
480
        if (property_exists($json, self::CASE_INSTANCE_BUSINESS_KEY)) {
481
            $query->caseInstanceBusinessKey(JsonUtil::getString($json, self::CASE_INSTANCE_BUSINESS_KEY));
482
        }
483
        if (property_exists($json, self::CASE_INSTANCE_BUSINESS_KEY_LIKE)) {
484
            $query->caseInstanceBusinessKeyLike(JsonUtil::getString($json, self::CASE_INSTANCE_BUSINESS_KEY_LIKE));
485
        }
486
        if (property_exists($json, self::CASE_EXECUTION_ID)) {
487
            $query->caseExecutionId(JsonUtil::getString($json, self::CASE_EXECUTION_ID));
488
        }*/
489
        if (property_exists($json, self::TENANT_IDS)) {
490
            $query->tenantIdIn(JsonUtil::getArray($json, self::TENANT_IDS));
491
        }
492
        if (property_exists($json, self::WITHOUT_TENANT_ID)) {
493
            $query->withoutTenantId();
494
        }
495
        if (property_exists($json, self::ORDERING_PROPERTIES)) {
496
            $jsonArray = JsonUtil::getArray($json, self::ORDERING_PROPERTIES);
497
            $query->setOrderingProperties(JsonQueryOrderingPropertyConverter::arrayConverter()->toObject($jsonArray));
498
        }
499
500
        // expressions
501
        foreach ($json as $key => $value) {
502
            if (str_ends_with($key, "Expression")) {
503
                $expression = JsonUtil::getString($json, self::key);
0 ignored issues
show
Bug introduced by
The constant Jabe\Engine\Impl\Json\JsonTaskQueryConverter::key was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
504
                $query->addExpression(substr($key, 0, strlen($key) - strlen("Expression")), $expression);
505
            }
506
        }
507
508
        return $query;
509
    }
510
511
    protected function addVariables(TaskQueryImpl $query, array $variables, bool $isTaskVariable, bool $isProcessVariable): void
512
    {
513
        foreach ($variables as $variable) {
514
            $variableObj = JsonUtil::getObject($variable);
515
            $name = JsonUtil::getString($variableObj, self::NAME);
516
            $rawValue = JsonUtil::getRawObject($variableObj, "value");
0 ignored issues
show
Bug introduced by
The method getRawObject() does not exist on Jabe\Engine\Impl\Util\JsonUtil. Did you maybe mean getObject()? ( Ignorable by Annotation )

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

516
            /** @scrutinizer ignore-call */ 
517
            $rawValue = JsonUtil::getRawObject($variableObj, "value");

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...
517
            $operator = constant("QueryOperator::", JsonUtil::getString($variableObj, "operator"));
0 ignored issues
show
Unused Code introduced by
The call to constant() has too many arguments starting with Jabe\Engine\Impl\Util\Js...ariableObj, 'operator'). ( Ignorable by Annotation )

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

517
            $operator = /** @scrutinizer ignore-call */ constant("QueryOperator::", JsonUtil::getString($variableObj, "operator"));

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...
518
            $query->addVariable($name, $rawValue, $operator, $isTaskVariable, $isProcessVariable);
519
        }
520
    }
521
}
522