| Total Complexity | 83 |
| Total Lines | 447 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like RuntimeServiceImpl 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 RuntimeServiceImpl, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 76 | class RuntimeServiceImpl extends ServiceImpl implements RuntimeServiceInterface |
||
| 77 | { |
||
| 78 | public function startProcessInstanceByKey(string $processDefinitionKey, string $businessKey = null, array $variables = []): ProcessInstance |
||
| 79 | { |
||
| 80 | $res = $this->createProcessInstanceByKey($processDefinitionKey); |
||
| 81 | if ($businessKey !== null) { |
||
| 82 | $res->businessKey($businessKey); |
||
| 83 | } |
||
| 84 | if (!empty($variables)) { |
||
| 85 | $res->setVariables($variables); |
||
| 86 | } |
||
| 87 | return $res->execute(); |
||
|
|
|||
| 88 | } |
||
| 89 | |||
| 90 | public function startProcessInstanceById(string $processDefinitionId, string $businessKey = null, array $variables = []): ProcessInstanceInterface |
||
| 91 | { |
||
| 92 | $res = $this->createProcessInstanceById($processDefinitionId); |
||
| 93 | if ($businessKey !== null) { |
||
| 94 | $res->businessKey($businessKey); |
||
| 95 | } |
||
| 96 | if (!empty($variables)) { |
||
| 97 | $res->setVariables($variables); |
||
| 98 | } |
||
| 99 | return $res->execute(); |
||
| 100 | } |
||
| 101 | |||
| 102 | public function deleteProcessInstancesAsync( |
||
| 103 | array $processInstanceIds, |
||
| 104 | ProcessInstanceQueryInterface $processInstanceQuery = null, |
||
| 105 | HistoricProcessInstanceQueryInterface $historicProcessInstanceQuery = null, |
||
| 106 | string $deleteReason = null, |
||
| 107 | bool $skipCustomListeners = false, |
||
| 108 | bool $skipSubprocesses = false |
||
| 109 | ): BatchInterface { |
||
| 110 | return $this->commandExecutor->execute( |
||
| 111 | new DeleteProcessInstanceBatchCmd( |
||
| 112 | $processInstanceIds, |
||
| 113 | $processInstanceQuery, |
||
| 114 | $historicProcessInstanceQuery, |
||
| 115 | $deleteReason, |
||
| 116 | $skipCustomListeners, |
||
| 117 | $skipSubprocesses |
||
| 118 | ) |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function deleteProcessInstance( |
||
| 123 | string $processInstanceId, |
||
| 124 | string $deleteReason = null, |
||
| 125 | bool $skipCustomListeners = false, |
||
| 126 | bool $skipIoMappings = false, |
||
| 127 | bool $externallyTerminated = false, |
||
| 128 | bool $skipSubprocesses = false |
||
| 129 | ): void { |
||
| 130 | $this->commandExecutor->execute(new DeleteProcessInstanceCmd($processInstanceId, $deleteReason, $skipCustomListeners, $externallyTerminated, $skipIoMappings, $skipSubprocesses, true)); |
||
| 131 | } |
||
| 132 | |||
| 133 | public function deleteProcessInstanceIfExists(string $processInstanceId, string $deleteReason = null, bool $skipCustomListeners = false, bool $externallyTerminated = false, bool $skipIoMappings = false, bool $skipSubprocesses = false): void |
||
| 134 | { |
||
| 135 | $this->commandExecutor->execute(new DeleteProcessInstanceCmd($processInstanceId, $deleteReason, $skipCustomListeners, $externallyTerminated, $skipIoMappings, $skipSubprocesses, false)); |
||
| 136 | } |
||
| 137 | |||
| 138 | public function deleteProcessInstances( |
||
| 139 | array $processInstanceIds, |
||
| 140 | string $deleteReason = null, |
||
| 141 | bool $skipCustomListeners = false, |
||
| 142 | bool $externallyTerminated = false, |
||
| 143 | bool $skipSubprocesses = false |
||
| 144 | ): void { |
||
| 145 | $this->commandExecutor->execute(new DeleteProcessInstancesCmd($processInstanceIds, $deleteReason, $skipCustomListeners, $externallyTerminated, $skipSubprocesses, true)); |
||
| 146 | } |
||
| 147 | |||
| 148 | public function deleteProcessInstancesIfExists(array $processInstanceIds, string $deleteReason = null, bool $skipCustomListeners = false, bool $externallyTerminated = false, bool $skipSubprocesses = false): void |
||
| 149 | { |
||
| 150 | $this->commandExecutor->execute(new DeleteProcessInstancesCmd($processInstanceIds, $deleteReason, $skipCustomListeners, $externallyTerminated, $skipSubprocesses, false)); |
||
| 151 | } |
||
| 152 | |||
| 153 | public function createExecutionQuery(): ExecutionQueryInterface |
||
| 154 | { |
||
| 155 | return new ExecutionQueryImpl($this->commandExecutor); |
||
| 156 | } |
||
| 157 | |||
| 158 | public function createNativeExecutionQuery(): NativeExecutionQueryInterface |
||
| 159 | { |
||
| 160 | return new NativeExecutionQueryImpl($this->commandExecutor); |
||
| 161 | } |
||
| 162 | |||
| 163 | public function createNativeProcessInstanceQuery(): NativeProcessInstanceQueryInterface |
||
| 164 | { |
||
| 165 | return new NativeProcessInstanceQueryImpl($this->commandExecutor); |
||
| 166 | } |
||
| 167 | |||
| 168 | public function createIncidentQuery(): IncidentQueryInterface |
||
| 169 | { |
||
| 170 | return new IncidentQueryImpl($this->commandExecutor); |
||
| 171 | } |
||
| 172 | |||
| 173 | public function createEventSubscriptionQuery(): EventSubscriptionQueryInterface |
||
| 174 | { |
||
| 175 | return new EventSubscriptionQueryImpl($this->commandExecutor); |
||
| 176 | } |
||
| 177 | |||
| 178 | public function createVariableInstanceQuery(): VariableInstanceQueryInterface |
||
| 179 | { |
||
| 180 | return new VariableInstanceQueryImpl($this->commandExecutor); |
||
| 181 | } |
||
| 182 | |||
| 183 | public function getVariables(string $executionId, array $variableNames = []): VariableMapInterface |
||
| 184 | { |
||
| 185 | return $this->getVariablesTyped($executionId, $variableNames); |
||
| 186 | } |
||
| 187 | |||
| 188 | public function getVariablesLocal(string $executionId, array $variableNames = []): VariableMapInterface |
||
| 189 | { |
||
| 190 | return $this->getVariablesLocalTyped($executionId, $variableNames); |
||
| 191 | } |
||
| 192 | |||
| 193 | public function getVariablesLocalTyped(string $executionId, array $variableNames = [], bool $deserializeValues = true): VariableMapInterface |
||
| 194 | { |
||
| 195 | return $this->commandExecutor->execute(new GetExecutionVariablesCmd($executionId, $variableNames, true, $deserializeValues)); |
||
| 196 | } |
||
| 197 | |||
| 198 | public function getVariablesTyped(string $executionId, array $variableNames = [], bool $deserializeValues = true): VariableMapInterface |
||
| 199 | { |
||
| 200 | return $this->commandExecutor->execute(new GetExecutionVariablesCmd($executionId, $variableNames, false, $deserializeValues)); |
||
| 201 | } |
||
| 202 | |||
| 203 | public function getVariable(string $executionId, string $variableName) |
||
| 204 | { |
||
| 205 | return $this->commandExecutor->execute(new GetExecutionVariableCmd($executionId, $variableName, false)); |
||
| 206 | } |
||
| 207 | |||
| 208 | public function getVariableTyped(string $executionId, string $variableName, bool $deserializeValue = true): ?TypedValueInterface |
||
| 211 | } |
||
| 212 | |||
| 213 | public function getVariableLocalTyped(string $executionId, string $variableName, bool $deserializeValue = true): ?TypedValueInterface |
||
| 214 | { |
||
| 215 | return $this->commandExecutor->execute(new GetExecutionVariableTypedCmd($executionId, $variableName, true, $deserializeValue)); |
||
| 216 | } |
||
| 217 | |||
| 218 | public function getVariableLocal(string $executionId, string $variableName) |
||
| 219 | { |
||
| 220 | return $this->commandExecutor->execute(new GetExecutionVariableCmd($executionId, $variableName, true)); |
||
| 221 | } |
||
| 222 | |||
| 223 | public function setVariable(string $executionId, string $variableName, $value): void |
||
| 224 | { |
||
| 225 | EnsureUtil::ensureNotNull("variableName", "variableName", $variableName); |
||
| 226 | $variables = []; |
||
| 227 | $variables[$variableName] = $value; |
||
| 228 | $this->setVariables($executionId, $variables); |
||
| 229 | } |
||
| 230 | |||
| 231 | public function setVariableLocal(string $executionId, string $variableName, $value): void |
||
| 232 | { |
||
| 233 | EnsureUtil::ensureNotNull("variableName", "variableName", $variableName); |
||
| 234 | $variables = []; |
||
| 235 | $variables[$variableName] = $value; |
||
| 236 | $this->setVariablesLocal($executionId, $variables); |
||
| 237 | } |
||
| 238 | |||
| 239 | public function setVariables(string $executionId, array $variables = []): void |
||
| 240 | { |
||
| 241 | $this->doSetVariables($executionId, $variables, false); |
||
| 242 | } |
||
| 243 | |||
| 244 | public function setVariablesLocal(string $executionId, array $variables = []): void |
||
| 245 | { |
||
| 246 | $this->doSetVariables($executionId, $variables, true); |
||
| 247 | } |
||
| 248 | |||
| 249 | private function doSetVariables(string $executionId, array $variables, bool $local): void |
||
| 250 | { |
||
| 251 | try { |
||
| 252 | $this->commandExecutor->execute(new SetExecutionVariablesCmd($executionId, $variables, $local)); |
||
| 253 | } catch (ProcessEngineException $ex) { |
||
| 254 | if (ExceptionUtil::checkValueTooLongException($ex)) { |
||
| 255 | throw new BadUserRequestException("Variable value is too long", $ex); |
||
| 256 | } |
||
| 257 | throw $ex; |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | public function setVariablesAsync( |
||
| 262 | array $processInstanceIds, |
||
| 263 | ProcessInstanceQueryInterface $processInstanceQuery = null, |
||
| 264 | HistoricProcessInstanceQuery $historicProcessInstanceQuery = null, |
||
| 265 | array $variables = [] |
||
| 266 | ): BatchInterface { |
||
| 267 | return $this->commandExecutor->execute(new SetVariablesToProcessInstancesBatchCmd( |
||
| 268 | $processInstanceIds, |
||
| 269 | $processInstanceQuery, |
||
| 270 | $historicProcessInstanceQuery, |
||
| 271 | $variables |
||
| 272 | )); |
||
| 273 | } |
||
| 274 | |||
| 275 | public function removeVariable(string $executionId, string $variableName): void |
||
| 276 | { |
||
| 277 | $variableNames = []; |
||
| 278 | $variableNames[] = $variableName; |
||
| 279 | $this->commandExecutor->execute(new RemoveExecutionVariablesCmd($executionId, $variableNames, false)); |
||
| 280 | } |
||
| 281 | |||
| 282 | public function removeVariableLocal(string $executionId, string $variableName): void |
||
| 283 | { |
||
| 284 | $variableNames = []; |
||
| 285 | $variableNames[] = $variableName; |
||
| 286 | $this->commandExecutor->execute(new RemoveExecutionVariablesCmd($executionId, $variableNames, true)); |
||
| 287 | } |
||
| 288 | |||
| 289 | public function removeVariables(string $executionId, array $variableNames = []): void |
||
| 290 | { |
||
| 291 | $this->commandExecutor->execute(new RemoveExecutionVariablesCmd($executionId, $variableNames, false)); |
||
| 292 | } |
||
| 293 | |||
| 294 | public function removeVariablesLocal(string $executionId, array $variableNames): void |
||
| 295 | { |
||
| 296 | $this->commandExecutor->execute(new RemoveExecutionVariablesCmd($executionId, $variableNames, true)); |
||
| 297 | } |
||
| 298 | |||
| 299 | public function updateVariables(string $executionId, array $modifications = [], array $deletions = []): void |
||
| 300 | { |
||
| 301 | $this->doUpdateVariables($executionId, $modifications, $deletions, false); |
||
| 302 | } |
||
| 303 | |||
| 304 | public function updateVariablesLocal(string $executionId, array $modifications = [], array $deletions = []): void |
||
| 305 | { |
||
| 306 | $this->doUpdateVariables($executionId, $modifications, $deletions, true); |
||
| 307 | } |
||
| 308 | |||
| 309 | private function doUpdateVariables(string $executionId, array $modifications, array $deletions, bool $local): void |
||
| 310 | { |
||
| 311 | try { |
||
| 312 | $this->commandExecutor->execute(new PatchExecutionVariablesCmd($executionId, $modifications, $deletions, $local)); |
||
| 313 | } catch (ProcessEngineException $ex) { |
||
| 314 | if (ExceptionUtil::checkValueTooLongException($ex)) { |
||
| 315 | throw new BadUserRequestException("Variable value is too long", $ex); |
||
| 316 | } |
||
| 317 | throw $ex; |
||
| 318 | } |
||
| 319 | } |
||
| 320 | |||
| 321 | public function signal(string $executionId, string $signalName = null, $signalData = null, array $processVariables = []): void |
||
| 322 | { |
||
| 323 | $this->commandExecutor->execute(new SignalCmd($executionId, $signalName, $signalData, $processVariables)); |
||
| 324 | } |
||
| 325 | |||
| 326 | public function createProcessInstanceQuery(): ProcessInstanceQueryInterface |
||
| 327 | { |
||
| 328 | return new ProcessInstanceQueryImpl($this->commandExecutor); |
||
| 329 | } |
||
| 330 | |||
| 331 | public function getActiveActivityIds(string $executionId): array |
||
| 332 | { |
||
| 333 | return $this->commandExecutor->execute(new FindActiveActivityIdsCmd($executionId)); |
||
| 334 | } |
||
| 335 | |||
| 336 | public function getActivityInstance(string $processInstanceId): ActivityInstanceInterface |
||
| 337 | { |
||
| 338 | return $this->commandExecutor->execute(new GetActivityInstanceCmd($processInstanceId)); |
||
| 339 | } |
||
| 340 | |||
| 341 | public function getFormInstanceById(string $processDefinitionId): FormDataInterface |
||
| 342 | { |
||
| 343 | return $this->commandExecutor->execute(new GetStartFormCmd($processDefinitionId)); |
||
| 344 | } |
||
| 345 | |||
| 346 | public function suspendProcessInstanceById(string $processInstanceId): void |
||
| 347 | { |
||
| 348 | $this->updateProcessInstanceSuspensionState() |
||
| 349 | ->byProcessInstanceId($processInstanceId) |
||
| 350 | ->suspend(); |
||
| 351 | } |
||
| 352 | |||
| 353 | public function suspendProcessInstanceByProcessDefinitionId(string $processDefinitionId): void |
||
| 354 | { |
||
| 355 | $this->updateProcessInstanceSuspensionState() |
||
| 356 | ->byProcessDefinitionId($processDefinitionId) |
||
| 357 | ->suspend(); |
||
| 358 | } |
||
| 359 | |||
| 360 | public function suspendProcessInstanceByProcessDefinitionKey(string $processDefinitionKey): void |
||
| 361 | { |
||
| 362 | $this->updateProcessInstanceSuspensionState() |
||
| 363 | ->byProcessDefinitionKey($processDefinitionKey) |
||
| 364 | ->suspend(); |
||
| 365 | } |
||
| 366 | |||
| 367 | public function activateProcessInstanceById(string $processInstanceId): void |
||
| 368 | { |
||
| 369 | $this->updateProcessInstanceSuspensionState() |
||
| 370 | ->byProcessInstanceId($processInstanceId) |
||
| 371 | ->activate(); |
||
| 372 | } |
||
| 373 | |||
| 374 | public function activateProcessInstanceByProcessDefinitionId(string $processDefinitionId): void |
||
| 375 | { |
||
| 376 | $this->updateProcessInstanceSuspensionState() |
||
| 377 | ->byProcessDefinitionId($processDefinitionId) |
||
| 378 | ->activate(); |
||
| 379 | } |
||
| 380 | |||
| 381 | public function activateProcessInstanceByProcessDefinitionKey(string $processDefinitionKey): void |
||
| 382 | { |
||
| 383 | $this->updateProcessInstanceSuspensionState() |
||
| 384 | ->byProcessDefinitionKey($processDefinitionKey) |
||
| 385 | ->activate(); |
||
| 386 | } |
||
| 387 | |||
| 388 | public function updateProcessInstanceSuspensionState(): UpdateProcessInstanceSuspensionStateSelectBuilderInterface |
||
| 389 | { |
||
| 390 | return new UpdateProcessInstanceSuspensionStateBuilderImpl($this->commandExecutor); |
||
| 391 | } |
||
| 392 | |||
| 393 | public function startProcessInstanceByMessage(string $messageName, string $businessKey = null, array $processVariables = []): ProcessInstanceInterface |
||
| 394 | { |
||
| 395 | $res = $this->createMessageCorrelation($messageName); |
||
| 396 | if ($businessKey !== null) { |
||
| 397 | $res->processInstanceBusinessKey($businessKey); |
||
| 398 | } |
||
| 399 | if (!empty($processVariables)) { |
||
| 400 | $res->setVariables($processVariables); |
||
| 401 | } |
||
| 402 | $res->correlateStartMessage(); |
||
| 403 | } |
||
| 404 | |||
| 405 | public function startProcessInstanceByMessageAndProcessDefinitionId(string $messageName, string $processDefinitionId, string $businessKey = null, array $processVariables = []): ProcessInstanceInterface |
||
| 406 | { |
||
| 407 | $res = $this->createMessageCorrelation($messageName)->processDefinitionId($processDefinitionId); |
||
| 408 | if ($businessKey !== null) { |
||
| 409 | $res->processInstanceBusinessKey($businessKey); |
||
| 410 | } |
||
| 411 | if (!empty($processVariables)) { |
||
| 412 | $res->setVariables($processVariables); |
||
| 413 | } |
||
| 414 | $res->correlateStartMessage(); |
||
| 415 | } |
||
| 416 | |||
| 417 | public function signalEventReceived(string $signalName, string $executionId = null, array $processVariables = []): void |
||
| 418 | { |
||
| 419 | $res = $this->createSignalEvent($signalName); |
||
| 420 | if ($executionId !== null) { |
||
| 421 | $res->executionId($executionId); |
||
| 422 | } |
||
| 423 | if (!empty($processVariables)) { |
||
| 424 | $res->setVariables($processVariables); |
||
| 425 | } |
||
| 426 | $res->send(); |
||
| 427 | } |
||
| 428 | |||
| 429 | public function createSignalEvent(string $signalName): SignalEventReceivedBuilderInterface |
||
| 430 | { |
||
| 431 | return new SignalEventReceivedBuilderImpl($this->commandExecutor, $signalName); |
||
| 432 | } |
||
| 433 | |||
| 434 | public function messageEventReceived(string $messageName, string $executionId, array $processVariables = []): void |
||
| 435 | { |
||
| 436 | EnsureUtil::ensureNotNull("messageName", "messageName", $messageName); |
||
| 437 | $this->commandExecutor->execute(new MessageEventReceivedCmd($messageName, $executionId, $processVariables)); |
||
| 438 | } |
||
| 439 | |||
| 440 | public function createMessageCorrelation(string $messageName): MessageCorrelationBuilderInterface |
||
| 441 | { |
||
| 442 | return new MessageCorrelationBuilderImpl($this->commandExecutor, $messageName); |
||
| 443 | } |
||
| 444 | |||
| 445 | public function correlateMessage(string $messageName, string $businessKey = null, array $correlationKeys = null, array $processVariables = null): void |
||
| 446 | { |
||
| 447 | $res = $this->createMessageCorrelation($messageName); |
||
| 448 | if ($businessKey !== null) { |
||
| 449 | $res->processInstanceBusinessKey($businessKey); |
||
| 450 | } |
||
| 451 | if (!empty($correlationKeys)) { |
||
| 452 | $res->processInstanceVariablesEqual($correlationKeys); |
||
| 453 | } |
||
| 454 | if (!empty($processVariables)) { |
||
| 455 | $res->setVariables($processVariables); |
||
| 456 | } |
||
| 457 | $res->correlate(); |
||
| 458 | } |
||
| 459 | |||
| 460 | public function createMessageCorrelationAsync(string $messageName): MessageCorrelationAsyncBuilder |
||
| 461 | { |
||
| 462 | return new MessageCorrelationAsyncBuilderImpl($this->commandExecutor, $messageName); |
||
| 463 | } |
||
| 464 | |||
| 465 | public function createProcessInstanceModification(string $processInstanceId): ProcessInstanceModificationBuilderInterface |
||
| 466 | { |
||
| 467 | return new ProcessInstanceModificationBuilderImpl($this->commandExecutor, $processInstanceId); |
||
| 468 | } |
||
| 469 | |||
| 470 | public function createProcessInstanceById(string $processDefinitionId): ProcessInstantiationBuilderInterface |
||
| 471 | { |
||
| 472 | return ProcessInstantiationBuilderImpl::createProcessInstanceById($this->commandExecutor, $processDefinitionId); |
||
| 473 | } |
||
| 474 | |||
| 475 | public function createProcessInstanceByKey(string $processDefinitionKey): ProcessInstantiationBuilderInterface |
||
| 476 | { |
||
| 477 | return ProcessInstantiationBuilderImpl::createProcessInstanceByKey($this->commandExecutor, $processDefinitionKey); |
||
| 478 | } |
||
| 479 | |||
| 480 | public function createMigrationPlan(string $sourceProcessDefinitionId, string $targetProcessDefinitionId): MigrationPlanBuilderInterface |
||
| 481 | { |
||
| 482 | return new MigrationPlanBuilderImpl($this->commandExecutor, $sourceProcessDefinitionId, $targetProcessDefinitionId); |
||
| 483 | } |
||
| 484 | |||
| 485 | public function newMigration(MigrationPlanInterface $migrationPlan): MigrationPlanExecutionBuilderInterface |
||
| 486 | { |
||
| 487 | return new MigrationPlanExecutionBuilderImpl($this->commandExecutor, $migrationPlan); |
||
| 488 | } |
||
| 489 | |||
| 490 | public function createModification(string $processDefinitionId): ModificationBuilderInterface |
||
| 491 | { |
||
| 492 | return new ModificationBuilderImpl($this->commandExecutor, $processDefinitionId); |
||
| 493 | } |
||
| 494 | |||
| 495 | public function restartProcessInstances(string $processDefinitionId): RestartProcessInstanceBuilderInterface |
||
| 496 | { |
||
| 497 | return new RestartProcessInstanceBuilderImpl($this->commandExecutor, $processDefinitionId); |
||
| 498 | } |
||
| 499 | |||
| 500 | public function createIncident(string $incidentType, string $executionId, string $configuration, string $message = null): IncidentInterface |
||
| 501 | { |
||
| 502 | return $this->commandExecutor->execute(new CreateIncidentCmd($incidentType, $executionId, $configuration, $message)); |
||
| 503 | } |
||
| 504 | |||
| 505 | public function resolveIncident(string $incidentId): void |
||
| 506 | { |
||
| 507 | $this->commandExecutor->execute(new ResolveIncidentCmd($incidentId)); |
||
| 508 | } |
||
| 509 | |||
| 510 | public function setAnnotationForIncidentById(string $incidentId, string $annotation): void |
||
| 511 | { |
||
| 512 | $this->commandExecutor->execute(new SetAnnotationForIncidentCmd($incidentId, $annotation)); |
||
| 513 | } |
||
| 514 | |||
| 515 | public function clearAnnotationForIncidentById(string $incidentId): void |
||
| 516 | { |
||
| 517 | $this->commandExecutor->execute(new SetAnnotationForIncidentCmd($incidentId, null)); |
||
| 518 | } |
||
| 519 | |||
| 520 | public function createConditionEvaluation(): ConditionEvaluationBuilderInterface |
||
| 523 | } |
||
| 524 | } |
||
| 525 |