Conditions | 14 |
Paths | 230 |
Total Lines | 97 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 | $output->writeln("The command is already running in another process."); |
||
43 | if($this->logger) { |
||
44 | $this->logger->warning("The command is already running in another process."); |
||
45 | } |
||
46 | return 0; |
||
47 | } |
||
48 | |||
49 | $jobs = $this->getCronJobs(); |
||
50 | |||
51 | /* |
||
52 | * Минимально допустимый период выполнения одной задачи |
||
53 | * при котором гарантируется выполнение всех задач |
||
54 | */ |
||
55 | $this->minAgentPeriod = (count($jobs) + 1) * EnvHelper::getBxCrontabPeriod(); |
||
56 | |||
57 | if(!empty($jobs)) { |
||
58 | |||
59 | foreach($jobs as $cmd => $job) { |
||
60 | |||
61 | if($this->isActualJob($job)) { |
||
62 | |||
63 | $job['status'] = self::EXEC_STATUS_WORK; |
||
64 | $this->updaateJob($cmd, $job); |
||
65 | |||
66 | $command = $this->getApplication()->find($cmd); |
||
67 | $cmdInput = new ArrayInput(['command' => $cmd]); |
||
68 | try { |
||
69 | |||
70 | $timeStart = microtime(true); |
||
71 | $returnCode = $command->run($cmdInput, $output); |
||
72 | |||
73 | if(!$returnCode) { |
||
74 | |||
75 | $job['status'] = self::EXEC_STATUS_SUCCESS; |
||
76 | |||
77 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
78 | if($this->logger) { |
||
79 | $this->logger->alert($msg); |
||
80 | } |
||
81 | $output->writeln(PHP_EOL . $msg); |
||
82 | |||
83 | } else { |
||
84 | |||
85 | $job['status'] = self::EXEC_STATUS_ERROR; |
||
86 | $job['error_code'] = $returnCode; |
||
87 | |||
88 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
89 | if($this->logger) { |
||
90 | $this->logger->alert($msg); |
||
91 | } |
||
92 | $output->writeln(PHP_EOL . $msg); |
||
93 | } |
||
94 | |||
95 | } catch (\Exception $e) { |
||
96 | |||
97 | $job['status'] = self::EXEC_STATUS_ERROR; |
||
98 | $job['error'] = $e->getMessage(); |
||
99 | |||
100 | |||
101 | if($this->logger) { |
||
102 | $this->logger->error($e, ['command' => $cmd]); |
||
103 | } |
||
104 | $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage()); |
||
105 | |||
106 | } finally { |
||
107 | |||
108 | $job['last_exec'] = time(); |
||
109 | $humanDate = new DateTime(); |
||
110 | $job['last_date_time'] = $humanDate->toString(); |
||
111 | $lock->release(); |
||
112 | } |
||
113 | |||
114 | $this->updaateJob($cmd, $job); |
||
115 | /* |
||
116 | * Let's do just one task |
||
117 | */ |
||
118 | break; |
||
119 | } |
||
120 | } // foreach($jobs as $cmd => $job) |
||
121 | } // if(!empty($jobs)) |
||
122 | |||
123 | $this->release(); |
||
124 | } |
||
244 | } |
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