| Conditions | 82 |
| Total Lines | 241 |
| Code Lines | 140 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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)) { |
||
| 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')); |
||
| 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); |
||
| 504 | $query->addExpression(substr($key, 0, strlen($key) - strlen("Expression")), $expression); |
||
| 505 | } |
||
| 506 | } |
||
| 507 | |||
| 508 | return $query; |
||
| 509 | } |
||
| 522 |