| Total Complexity | 110 |
| Total Lines | 502 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like JsonTaskQueryConverter 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 JsonTaskQueryConverter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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 = $object; |
||
| 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()); |
||
|
|
|||
| 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()); |
||
| 192 | JsonUtil::addField($json, self::CASE_DEFINITION_ID, $query->getCaseDefinitionId()); |
||
| 193 | JsonUtil::addField($json, self::CASE_DEFINITION_NAME, $query->getCaseDefinitionName()); |
||
| 194 | JsonUtil::addField($json, self::CASE_DEFINITION_NAME_LIKE, $query->getCaseDefinitionNameLike()); |
||
| 195 | //JsonUtil::addField($json, self::CASE_INSTANCE_ID, $query->getCaseInstanceId()); |
||
| 196 | JsonUtil::addField($json, self::CASE_INSTANCE_BUSINESS_KEY, $query->getCaseInstanceBusinessKey()); |
||
| 197 | JsonUtil::addField($json, self::CASE_INSTANCE_BUSINESS_KEY_LIKE, $query->getCaseInstanceBusinessKeyLike()); |
||
| 198 | JsonUtil::addField($json, self::CASE_EXECUTION_ID, $query->getCaseExecutionId()); |
||
| 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 |
||
| 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) |
||
| 510 | } |
||
| 511 | |||
| 512 | protected function addVariables(TaskQueryImpl $query, array $variables, bool $isTaskVariable, bool $isProcessVariable): void |
||
| 513 | { |
||
| 520 | } |
||
| 521 | } |
||
| 522 | } |
||
| 523 |
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.