Conditions | 13 |
Paths | 442 |
Total Lines | 93 |
Code Lines | 50 |
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 |
||
36 | protected function execute(InputInterface $input, OutputInterface $output) |
||
37 | { |
||
38 | $logger = EnvHelper::getLogger('bx_cron'); |
||
39 | if($logger) { |
||
40 | $this->setLogger($logger); |
||
41 | } |
||
42 | |||
43 | $jobs = $this->getCronJobs(); |
||
44 | |||
45 | /* |
||
46 | * Минимально допустимый период выполнения одной задачи |
||
47 | * при котором гарантируется выполнение всех задач |
||
48 | */ |
||
49 | $this->minAgentPeriod = (count($jobs) + 1) * self::BX_CRON_PERIOD; |
||
50 | |||
51 | $workedJobs = []; |
||
52 | |||
53 | if(!empty($jobs)) { |
||
54 | |||
55 | $lockStore = new FlockStore(pathinfo(EnvHelper::getCrontabFile(), PATHINFO_DIRNAME)); |
||
56 | $lockFactory = new LockFactory($lockStore); |
||
57 | if($this->logger) { |
||
58 | $lockFactory->setLogger($this->logger); |
||
59 | } |
||
60 | |||
61 | foreach($jobs as $cmd => $job) { |
||
62 | |||
63 | if($this->isActualJob($job)) { |
||
64 | |||
65 | $lock = $lockFactory->createLock($this->getLockName($cmd), self::EXEC_TIMEOUT); |
||
66 | if($lock->acquire()) { |
||
67 | |||
68 | $workedJobs[$cmd] = $job; |
||
69 | |||
70 | $command = $this->getApplication()->find($cmd); |
||
71 | $cmdInput = new ArrayInput(['command' => $cmd]); |
||
72 | try { |
||
73 | |||
74 | $timeStart = microtime(true); |
||
75 | $returnCode = $command->run($cmdInput, $output); |
||
76 | |||
77 | if(!$returnCode) { |
||
78 | |||
79 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_SUCCESS; |
||
80 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
81 | if($this->logger) { |
||
82 | $this->logger->alert($msg); |
||
83 | } |
||
84 | $output->writeln(PHP_EOL . $msg); |
||
85 | |||
86 | } else { |
||
87 | |||
88 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_ERROR; |
||
89 | $workedJobs[$cmd]['error_code'] = $returnCode; |
||
90 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
91 | if($this->logger) { |
||
92 | $this->logger->alert($msg); |
||
93 | } |
||
94 | $output->writeln(PHP_EOL . $msg); |
||
95 | } |
||
96 | |||
97 | } catch (\Exception $e) { |
||
98 | |||
99 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_ERROR; |
||
100 | $workedJobs[$cmd]['error'] = $e->getMessage(); |
||
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 | $workedJobs[$cmd]['last_exec'] = time(); |
||
109 | $humanDate = new DateTime(); |
||
110 | $workedJobs[$cmd]['last_date_time'] = $humanDate->toString(); |
||
111 | $lock->release(); |
||
112 | } |
||
113 | |||
114 | /* |
||
115 | * Выполняем только одну задачу |
||
116 | */ |
||
117 | break; |
||
118 | |||
119 | } else { |
||
120 | if($this->logger) { |
||
121 | $this->logger->warning($cmd . " is locked"); |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | |||
128 | $this->updateCronTab($workedJobs); |
||
129 | } |
||
245 | } |
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