/**
  * @param Task $task
  * @param Workflow $workflow
  * @return TaskProcessNotFound
  */
 public static function of(Task $task, Workflow $workflow)
 {
     return new self(sprintf("Workflow %s (%s) has no process defined which has task %s on its task list", $workflow->name(), $workflow->workflowId()->toString(), $task->id()->toString()));
 }
 /**
  * @param Workflow $workflow
  * @return StartTaskIsAlreadyDefined
  */
 public static function forWorkflow(Workflow $workflow)
 {
     return new self(sprintf('Workflow %s already has a start task', $workflow->name()));
 }
 /**
  * @param int $desiredReleaseNumber
  * @param Workflow $workflow
  * @return WorkflowReleaseAlreadyExists
  */
 public static function withReleaseNumber($desiredReleaseNumber, Workflow $workflow)
 {
     return new self(sprintf('A workflow release for workflow %s (%s) with the release number %s already exists', $workflow->name(), $workflow->workflowId()->toString(), $desiredReleaseNumber));
 }
 /**
  * @param Workflow $workflow
  * @throws \RuntimeException
  * @return void
  */
 public function writeToProcessingConfig(Workflow $workflow)
 {
     $processNum = count($workflow->processList());
     if ($processNum == 0) {
         $this->commandBus->dispatch(RemoveProcessConfig::ofProcessTriggeredByMessage($workflow->startMessage()->messageName(), $this->processingConfigLocation));
         return;
     }
     $processDefinitions = $this->processingConfig->getProcessDefinitions();
     if ($processNum == 1) {
         $processConfig = $this->translateToProcessingProcess($workflow->processList()[0]);
         $processConfig['name'] = $workflow->name();
         if (isset($processDefinitions[$workflow->startMessage()->messageName()])) {
             $this->commandBus->dispatch(ChangeProcessConfig::ofProcessTriggeredByMessage($workflow->startMessage()->messageName(), $processConfig, $this->processingConfigLocation));
         } else {
             $this->commandBus->dispatch(AddNewProcessToConfig::fromDefinition($processConfig['name'], $processConfig['process_type'], $workflow->startMessage()->messageName(), $processConfig['tasks'], $this->processingConfigLocation));
         }
     } else {
         throw new \RuntimeException("Handling of more than process per workflow is not supported yet!");
     }
 }