Passed
Push — master ( a8eabf...729b2b )
by Ioannes
01:45
created
src/Bitrix/Loader.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
      */
11 11
     public function initializeBitrix() {
12 12
 
13
-        if($this->checkBitrix()) {
13
+        if ($this->checkBitrix()) {
14 14
 
15 15
             /**
16 16
              * Declare global legacy variables
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 
54 54
             $cliFile = getLocalPath('modules/' . $module['ID'] . '/cli.php');
55 55
 
56
-            if(!$cliFile) {
56
+            if (!$cliFile) {
57 57
                 continue;
58 58
             }
59 59
 
Please login to merge, or discard this patch.
src/BxCommand.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
         /** @var Command $annotation */
48 48
         $annotation = $this->getAnnotation(\App\BxConsole\Annotations\Command::class);
49 49
 
50
-        if($annotation) {
50
+        if ($annotation) {
51 51
             $this->setName($annotation->name);
52 52
             $this->setDescription($annotation->description);
53 53
             $this->setHelp($annotation->help);
Please login to merge, or discard this patch.
src/Application.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 
26 26
         $this->isBitrixLoaded = $loader->initializeBitrix();
27 27
 
28
-        if($this->isBitrixLoaded) {
29
-            foreach($loader->getModulesCommands() as $command) {
28
+        if ($this->isBitrixLoaded) {
29
+            foreach ($loader->getModulesCommands() as $command) {
30 30
                 $this->add($command);
31 31
             }
32 32
         }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
         $exitCode = parent::doRun($input, $output);
40 40
 
41
-        if($this->isBitrixLoaded) {
41
+        if ($this->isBitrixLoaded) {
42 42
             if ($this->getCommandName($input) === null) {
43 43
                 $output->writeln(PHP_EOL . sprintf('Using Bitrix <info>kernel v%s</info>.</info>', SM_VERSION),
44 44
                     OutputInterface::VERBOSITY_VERY_VERBOSE);
Please login to merge, or discard this patch.
src/EnvHelper.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
     public static function loadEnv() {
11 11
 
12 12
         $envFile = realpath(__DIR__ . '/../../../../.env');
13
-        if(!is_file($envFile)) {
13
+        if (!is_file($envFile)) {
14 14
             $envFile = realpath(__DIR__ . '/../../../../../.env');
15 15
         }
16
-        if(is_file($envFile)) {
16
+        if (is_file($envFile)) {
17 17
             try {
18 18
                 $env = new \Symfony\Component\Dotenv\Dotenv();
19 19
                 $env->load($envFile);
@@ -30,15 +30,15 @@  discard block
 block discarded – undo
30 30
 
31 31
         $_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__ . '/../../../../');
32 32
 
33
-        if(isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) {
33
+        if (isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) {
34 34
             $_SERVER['DOCUMENT_ROOT'] = $_ENV['APP_DOCUMENT_ROOT'];
35 35
             return $_SERVER['DOCUMENT_ROOT'];
36 36
         }
37 37
 
38 38
         $composerFile = realpath(__DIR__ . '/../../../../composer.json');
39
-        if(is_file($composerFile)) {
39
+        if (is_file($composerFile)) {
40 40
             $composerConfig = json_decode(file_get_contents($composerFile), true);
41
-            if(isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) {
41
+            if (isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) {
42 42
                 $_SERVER['DOCUMENT_ROOT'] = $composerConfig['extra']['document-root'];
43 43
                 return $_SERVER['DOCUMENT_ROOT'];
44 44
             }
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public static function getLogger($channel) {
55 55
 
56
-        if(isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) {
56
+        if (isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) {
57 57
             $logClass = $_ENV['APP_LOG_CLASS'];
58 58
             $log = new $logClass($channel);
59
-            if($log instanceof LoggerInterface) {
59
+            if ($log instanceof LoggerInterface) {
60 60
                 return $log;
61 61
             }
62 62
         }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function getCrontabFile() {
71 71
 
72
-        if(isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) {
72
+        if (isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) {
73 73
             return rtrim($_ENV['BX_CRONTAB_FOLDER'], "/") . '/bx_crontab.json';
74 74
         }
75 75
 
Please login to merge, or discard this patch.
src/Cron.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     protected function execute(InputInterface $input, OutputInterface $output)
39 39
     {
40 40
         $logger = EnvHelper::getLogger('bx_cron');
41
-        if($logger) {
41
+        if ($logger) {
42 42
             $this->setLogger($logger);
43 43
         }
44 44
 
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
          */
51 51
         $this->minAgentPeriod = (count($jobs) + 1) * self::BX_CRON_PERIOD;
52 52
 
53
-        if(!empty($jobs)) {
53
+        if (!empty($jobs)) {
54 54
 
55 55
             $lockStore = new FlockStore(pathinfo(EnvHelper::getCrontabFile(), PATHINFO_DIRNAME));
56 56
             $lockFactory = new LockFactory($lockStore);
57
-            if($this->logger) {
57
+            if ($this->logger) {
58 58
                 $lockFactory->setLogger($this->logger);
59 59
             }
60 60
 
61
-            foreach($jobs as $cmd => $job) {
61
+            foreach ($jobs as $cmd => $job) {
62 62
 
63
-                if($this->isActualJob($job)) {
63
+                if ($this->isActualJob($job)) {
64 64
 
65 65
                     $lock = $lockFactory->createLock($this->getLockName($cmd), self::EXEC_TIMEOUT);
66
-                    if($lock->acquire()) {
66
+                    if ($lock->acquire()) {
67 67
 
68 68
                         $job['status'] = self::EXEC_STATUS_WORK;
69 69
                         $this->updaateJob($cmd, $job);
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
                             $timeStart = microtime(true);
76 76
                             $returnCode = $command->run($cmdInput, $output);
77 77
 
78
-                            if(!$returnCode) {
78
+                            if (!$returnCode) {
79 79
 
80 80
                                 $job['status'] = self::EXEC_STATUS_SUCCESS;
81 81
 
82 82
                                 $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart);
83
-                                if($this->logger) {
83
+                                if ($this->logger) {
84 84
                                     $this->logger->alert($msg);
85 85
                                 }
86 86
                                 $output->writeln(PHP_EOL . $msg);
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
                                 $job['error_code'] = $returnCode;
92 92
 
93 93
                                 $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart);
94
-                                if($this->logger) {
94
+                                if ($this->logger) {
95 95
                                     $this->logger->alert($msg);
96 96
                                 }
97 97
                                 $output->writeln(PHP_EOL . $msg);
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
                             $job['error'] = $e->getMessage();
104 104
 
105 105
 
106
-                            if($this->logger) {
106
+                            if ($this->logger) {
107 107
                                 $this->logger->error($e, ['command' => $cmd]);
108 108
                             }
109 109
                             $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage());
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                         break;
124 124
 
125 125
                     } else {
126
-                        if($this->logger) {
126
+                        if ($this->logger) {
127 127
                             $this->logger->warning($cmd . " is locked");
128 128
                         }
129 129
                     }
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
 
140 140
     protected function isActualJob(&$job) {
141 141
 
142
-        if(isset($job['status']) && $job['status'] !== self::EXEC_STATUS_SUCCESS) {
142
+        if (isset($job['status']) && $job['status'] !== self::EXEC_STATUS_SUCCESS) {
143 143
             return false;
144 144
         }
145 145
 
146 146
         $period = intval($job['period']);
147 147
 
148
-        if($period > 0) {
149
-            if($period < $this->minAgentPeriod) {
148
+        if ($period > 0) {
149
+            if ($period < $this->minAgentPeriod) {
150 150
                 $job['orig_period'] = $period;
151 151
                 $period = $job['period'] = $this->minAgentPeriod;
152 152
             }
153
-            if(time() - $job['last_exec'] >= $period) {
153
+            if (time() - $job['last_exec'] >= $period) {
154 154
                 return true;
155 155
             }
156
-        } else if(!empty($job['times'])) {
156
+        } else if (!empty($job['times'])) {
157 157
             //TODO:
158 158
         }
159 159
 
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
         $commands = $app->all();
169 169
 
170 170
         $selfCommands = [];
171
-        foreach($commands as $command) {
171
+        foreach ($commands as $command) {
172 172
             /** @var BxCommand $command */
173
-            if($command instanceof BxCommand) {
173
+            if ($command instanceof BxCommand) {
174 174
                 $name = $command->getName();
175 175
                 $selfCommands[$name] = [
176 176
                     'object' => $command,
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 
181 181
         $agents = [];
182 182
         $reader = new AnnotationReader();
183
-        foreach($selfCommands as $cmd => $selfCommand) {
183
+        foreach ($selfCommands as $cmd => $selfCommand) {
184 184
             $reflectionClass = new \ReflectionClass($selfCommand['object']);
185 185
             $annotations = $reader->getClassAnnotations($reflectionClass);
186 186
 
187
-            foreach($annotations as $annotation) {
188
-                if($annotation instanceof Agent) {
187
+            foreach ($annotations as $annotation) {
188
+                if ($annotation instanceof Agent) {
189 189
                     $agents[$cmd] = $annotation->toArray();
190 190
                 }
191 191
             }
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 
194 194
         $crontab = $this->getCronTab();
195 195
 
196
-        if(is_array($crontab)) {
197
-            foreach($crontab as $cmd => $job) {
198
-                if(is_array($job) && isset($agents[$cmd])) {
196
+        if (is_array($crontab)) {
197
+            foreach ($crontab as $cmd => $job) {
198
+                if (is_array($job) && isset($agents[$cmd])) {
199 199
                     $agents[$cmd] = array_merge($job, $agents[$cmd]);
200 200
                 }
201 201
             }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         $fh = fopen($filename, 'c');
229 229
         if (flock($fh, LOCK_EX)) {
230 230
             ftruncate($fh, 0);
231
-            if(!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) {
231
+            if (!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) {
232 232
                 throw new \Exception('Unable to write BX_CRONTAB : ' . $filename);
233 233
             }
234 234
         }
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         $filename = EnvHelper::getCrontabFile();
247 247
 
248 248
         $fh = fopen($filename, 'r');
249
-        if(flock($fh, LOCK_SH)) {
249
+        if (flock($fh, LOCK_SH)) {
250 250
             $data = @fread($fh, filesize($filename));
251 251
             $cronTab = json_decode($data, true);
252 252
         }
Please login to merge, or discard this patch.