| Conditions | 16 |
| Paths | 234 |
| Total Lines | 106 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 27 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 28 | { |
||
| 29 | $logger = EnvHelper::getLogger('bx_cron'); |
||
| 30 | if($logger) { |
||
| 31 | $this->setLogger($logger); |
||
| 32 | } |
||
| 33 | |||
| 34 | if(EnvHelper::getSwitch('BX_CRONTAB_RUN', EnvHelper::SWITCH_STATE_OFF)) { |
||
| 35 | if($this->logger) { |
||
| 36 | $this->logger->alert('BxCron switch off'); |
||
| 37 | } |
||
| 38 | return 0; |
||
| 39 | } |
||
| 40 | |||
| 41 | if(!$this->lock()) { |
||
| 42 | $msg = 'The command is already running in another process.'; |
||
| 43 | $output->writeln($msg); |
||
| 44 | if($this->logger) { |
||
| 45 | $this->logger->warning($msg); |
||
| 46 | } |
||
| 47 | return 0; |
||
| 48 | } |
||
| 49 | |||
| 50 | if($sleepInterval = EnvHelper::checkSleepInterval()) { |
||
| 51 | $msg = sprintf("Sleep in interval %s", $sleepInterval); |
||
| 52 | $output->writeln($msg); |
||
| 53 | if($this->logger) { |
||
| 54 | $this->logger->warning($msg); |
||
| 55 | } |
||
| 56 | return 0; |
||
| 57 | } |
||
| 58 | |||
| 59 | $jobs = $this->getCronJobs(); |
||
| 60 | |||
| 61 | /* |
||
| 62 | * Минимально допустимый период выполнения одной задачи |
||
| 63 | * при котором гарантируется выполнение всех задач |
||
| 64 | */ |
||
| 65 | $this->minAgentPeriod = (count($jobs) + 1) * EnvHelper::getBxCrontabPeriod(); |
||
| 66 | |||
| 67 | if(!empty($jobs)) { |
||
| 68 | |||
| 69 | foreach($jobs as $cmd => $job) { |
||
| 70 | |||
| 71 | if($this->isActualJob($job)) { |
||
| 72 | |||
| 73 | $job['status'] = self::EXEC_STATUS_WORK; |
||
| 74 | $this->updaateJob($cmd, $job); |
||
| 75 | |||
| 76 | $command = $this->getApplication()->find($cmd); |
||
| 77 | $cmdInput = new ArrayInput(['command' => $cmd]); |
||
| 78 | try { |
||
| 79 | |||
| 80 | $timeStart = microtime(true); |
||
| 81 | $returnCode = $command->run($cmdInput, $output); |
||
| 82 | |||
| 83 | if(!$returnCode) { |
||
| 84 | |||
| 85 | $job['status'] = self::EXEC_STATUS_SUCCESS; |
||
| 86 | |||
| 87 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
| 88 | if($this->logger) { |
||
| 89 | $this->logger->alert($msg); |
||
| 90 | } |
||
| 91 | $output->writeln(PHP_EOL . $msg); |
||
| 92 | |||
| 93 | } else { |
||
| 94 | |||
| 95 | $job['status'] = self::EXEC_STATUS_ERROR; |
||
| 96 | $job['error_code'] = $returnCode; |
||
| 97 | |||
| 98 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
| 99 | if($this->logger) { |
||
| 100 | $this->logger->alert($msg); |
||
| 101 | } |
||
| 102 | $output->writeln(PHP_EOL . $msg); |
||
| 103 | } |
||
| 104 | |||
| 105 | } catch (\Exception $e) { |
||
| 106 | |||
| 107 | $job['status'] = self::EXEC_STATUS_ERROR; |
||
| 108 | $job['error'] = $e->getMessage(); |
||
| 109 | |||
| 110 | |||
| 111 | if($this->logger) { |
||
| 112 | $this->logger->error($e, ['command' => $cmd]); |
||
| 113 | } |
||
| 114 | $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage()); |
||
| 115 | |||
| 116 | } finally { |
||
| 117 | |||
| 118 | $job['last_exec'] = time(); |
||
| 119 | $humanDate = new DateTime(); |
||
| 120 | $job['last_date_time'] = $humanDate->toString(); |
||
| 121 | } |
||
| 122 | |||
| 123 | $this->updaateJob($cmd, $job); |
||
| 124 | /* |
||
| 125 | * Let's do just one task |
||
| 126 | */ |
||
| 127 | break; |
||
| 128 | } |
||
| 129 | } // foreach($jobs as $cmd => $job) |
||
| 130 | } // if(!empty($jobs)) |
||
| 131 | |||
| 132 | $this->release(); |
||
| 133 | } |
||
| 253 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths