| Conditions | 11 |
| Paths | 10 |
| Total Lines | 47 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 88 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 89 | { |
||
| 90 | foreach ($this->systemTasks as $systemKey => $systemTask) { |
||
| 91 | if (!$systemTask['enabled']) { |
||
| 92 | if ($task = $this->taskRepository->findBySystemKey($systemKey)) { |
||
| 93 | $task->setInterval($task->getInterval(), $task->getFirstExecution(), new \DateTime()); |
||
| 94 | |||
| 95 | if ($execution = $this->taskExecutionRepository->findPending($task)) { |
||
| 96 | $this->taskExecutionRepository->remove($execution); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($task = $this->taskRepository->findBySystemKey($systemKey)) { |
||
| 104 | if ($task->getHandlerClass() !== $systemTask['handler_class'] |
||
| 105 | || $task->getWorkload() !== $systemTask['workload'] |
||
| 106 | ) { |
||
| 107 | throw new \InvalidArgumentException( |
||
| 108 | sprintf('No update of handle-class or workload is supported for system-task "%s".', $systemKey) |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($task->getInterval() !== $systemTask['cron_expression']) { |
||
| 113 | $task->setInterval(CronExpression::factory($systemTask['cron_expression'])); |
||
| 114 | |||
| 115 | if ($execution = $this->taskExecutionRepository->findPending($task)) { |
||
| 116 | $this->taskExecutionRepository->remove($execution); |
||
| 117 | } |
||
| 118 | |||
| 119 | $this->scheduler->scheduleTasks(); |
||
| 120 | } |
||
| 121 | |||
| 122 | continue; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** @var TaskBuilder $builder */ |
||
| 126 | $builder = $this->scheduler->createTask($systemTask['handler_class'], $systemTask['workload']); |
||
| 127 | $builder->setSystemKey($systemKey); |
||
| 128 | if ($systemTask['cron_expression']) { |
||
| 129 | $builder->cron($systemTask['cron_expression']); |
||
| 130 | } |
||
| 131 | |||
| 132 | $builder->schedule(); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 144 |