Conditions | 13 |
Paths | 450 |
Total Lines | 90 |
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 |
||
38 | protected function execute(InputInterface $input, OutputInterface $output) |
||
39 | { |
||
40 | $logger = EnvHelper::getLogger('bx_cron'); |
||
41 | if($logger) { |
||
42 | $this->setLogger($logger); |
||
43 | } |
||
44 | |||
45 | $jobs = $this->getCronJobs(); |
||
46 | |||
47 | /* |
||
48 | * Минимально допустимый период выполнения одной задачи |
||
49 | * при котором гарантируется выполнение всех задач |
||
50 | */ |
||
51 | $this->minAgentPeriod = (count($jobs) + 1) * self::BX_CRON_PERIOD; |
||
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 | $job['status'] = self::EXEC_STATUS_WORK; |
||
69 | $this->updaateJob($cmd, $job); |
||
70 | |||
71 | $command = $this->getApplication()->find($cmd); |
||
72 | $cmdInput = new ArrayInput(['command' => $cmd]); |
||
73 | try { |
||
74 | |||
75 | $timeStart = microtime(true); |
||
76 | $returnCode = $command->run($cmdInput, $output); |
||
77 | |||
78 | if(!$returnCode) { |
||
79 | |||
80 | $job['status'] = self::EXEC_STATUS_SUCCESS; |
||
81 | |||
82 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
83 | if($this->logger) { |
||
84 | $this->logger->alert($msg); |
||
85 | } |
||
86 | $output->writeln(PHP_EOL . $msg); |
||
87 | |||
88 | } else { |
||
89 | |||
90 | $job['status'] = self::EXEC_STATUS_ERROR; |
||
91 | $job['error_code'] = $returnCode; |
||
92 | |||
93 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
||
94 | if($this->logger) { |
||
95 | $this->logger->alert($msg); |
||
96 | } |
||
97 | $output->writeln(PHP_EOL . $msg); |
||
98 | } |
||
99 | |||
100 | } catch (\Exception $e) { |
||
101 | |||
102 | $job['status'] = self::EXEC_STATUS_ERROR; |
||
103 | $job['error'] = $e->getMessage(); |
||
104 | |||
105 | |||
106 | if($this->logger) { |
||
107 | $this->logger->error($e, ['command' => $cmd]); |
||
108 | } |
||
109 | $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage()); |
||
110 | |||
111 | } finally { |
||
112 | |||
113 | $job['last_exec'] = time(); |
||
114 | $humanDate = new DateTime(); |
||
115 | $job['last_date_time'] = $humanDate->toString(); |
||
116 | $lock->release(); |
||
117 | } |
||
118 | |||
119 | $this->updaateJob($cmd, $job); |
||
120 | /* |
||
121 | * Let's do just one task |
||
122 | */ |
||
123 | break; |
||
124 | |||
125 | } else { |
||
126 | if($this->logger) { |
||
127 | $this->logger->warning($cmd . " is locked"); |
||
128 | } |
||
258 | } |
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