Passed
Push — master ( b89e50...0fa850 )
by Biao
03:23
created
src/Swoole/Process/CustomProcessTrait.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
     public function addCustomProcesses(Server $swoole, $processPrefix, array $processes, array $laravelConfig)
13 13
     {
14
-        $pidfile = dirname($swoole->setting['pid_file']) . '/' . $this->customProcessPidFile;
14
+        $pidfile = dirname($swoole->setting['pid_file']).'/'.$this->customProcessPidFile;
15 15
         if (file_exists($pidfile)) {
16 16
             unlink($pidfile);
17 17
         }
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
                 continue;
27 27
             }
28 28
             $processClass = $item['class'];
29
-            $restartInterval = isset($item['restart_interval']) ? (int)$item['restart_interval'] : 5;
30
-            $callback = function (Process $worker) use ($pidfile, $swoole, $processPrefix, $processClass, $restartInterval, $name, $laravelConfig) {
31
-                file_put_contents($pidfile, $worker->pid . "\n", FILE_APPEND | LOCK_EX);
29
+            $restartInterval = isset($item['restart_interval']) ? (int) $item['restart_interval'] : 5;
30
+            $callback = function(Process $worker) use ($pidfile, $swoole, $processPrefix, $processClass, $restartInterval, $name, $laravelConfig) {
31
+                file_put_contents($pidfile, $worker->pid."\n", FILE_APPEND | LOCK_EX);
32 32
                 $this->initLaravel($laravelConfig, $swoole);
33 33
                 if (!isset(class_implements($processClass)[CustomProcessInterface::class])) {
34 34
                     throw new \InvalidArgumentException(
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
                 /**@var CustomProcessInterface $processClass */
43 43
                 $this->setProcessTitle(sprintf('%s laravels: %s process', $processPrefix, $name));
44 44
 
45
-                Process::signal(SIGUSR1, function ($signo) use ($name, $processClass, $worker, $pidfile, $swoole) {
45
+                Process::signal(SIGUSR1, function($signo) use ($name, $processClass, $worker, $pidfile, $swoole) {
46 46
                     $this->info(sprintf('Reloading %s process[PID=%d].', $name, $worker->pid));
47 47
                     $processClass::onReload($swoole, $worker);
48 48
                 });
49 49
 
50 50
                 if (method_exists($processClass, 'onStop')) {
51
-                    Process::signal(SIGTERM, function ($signo) use ($name, $processClass, $worker, $pidfile, $swoole) {
51
+                    Process::signal(SIGTERM, function($signo) use ($name, $processClass, $worker, $pidfile, $swoole) {
52 52
                         $this->info(sprintf('Stopping %s process[PID=%d].', $name, $worker->pid));
53 53
                         $processClass::onStop($swoole, $worker);
54 54
                     });
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 for ($i = 0; $i < $item['num']; $i++) {
73 73
                     $process = $this->makeProcess($callback, $item);
74 74
                     $swoole->addProcess($process);
75
-                    $processList[$name . $i] = $process;
75
+                    $processList[$name.$i] = $process;
76 76
                 }
77 77
             } else {  // For single process
78 78
                 $process = $this->makeProcess($callback, $item);
Please login to merge, or discard this patch.
src/Components/Prometheus/PrometheusExporter.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
                 'value' => $apcSmaInfo['avail_mem'],
156 156
             ],
157 157
         ];
158
-        foreach (new \APCuIterator('/^' . $this->config['apcu_key_prefix'] . $this->config['apcu_key_separator'] . '/') as $item) {
158
+        foreach (new \APCuIterator('/^'.$this->config['apcu_key_prefix'].$this->config['apcu_key_separator'].'/') as $item) {
159 159
             $value = apcu_fetch($item['key'], $success);
160 160
             if (!$success) {
161 161
                 continue;
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
         $metrics = array_merge($this->getSystemLoadAvgMetrics(), $this->getSwooleMetrics(), $this->getApcuMetrics());
182 182
         $lines = [];
183 183
         foreach ($metrics as $metric) {
184
-            $lines[] = "# HELP " . $metric['name'] . " {$metric['help']}";
185
-            $lines[] = "# TYPE " . $metric['name'] . " {$metric['type']}";
184
+            $lines[] = "# HELP ".$metric['name']." {$metric['help']}";
185
+            $lines[] = "# TYPE ".$metric['name']." {$metric['type']}";
186 186
 
187 187
             $metricLabels = isset($metric['labels']) ? $metric['labels'] : [];
188 188
             $labels = ['{'];
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             }
194 194
             $labels[] = '}';
195 195
             $labelStr = implode('', $labels);
196
-            $lines[] = $metric['name'] . "$labelStr {$metric['value']}";
196
+            $lines[] = $metric['name']."$labelStr {$metric['value']}";
197 197
         }
198 198
         return implode("\n", $lines);
199 199
     }
Please login to merge, or discard this patch.
src/Components/Apollo/Client.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
             $this->clientIp = current(swoole_get_local_ip()) ?: gethostname();
42 42
         }
43 43
         if (isset($settings['pull_timeout'])) {
44
-            $this->pullTimeout = (int)$settings['pull_timeout'];
44
+            $this->pullTimeout = (int) $settings['pull_timeout'];
45 45
         }
46 46
         if (isset($settings['backup_old_env'])) {
47
-            $this->backupOldEnv = (bool)$settings['backup_old_env'];
47
+            $this->backupOldEnv = (bool) $settings['backup_old_env'];
48 48
         }
49 49
     }
50 50
 
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
         $settings = [
74 74
             'server'         => getenv('APOLLO_SERVER'),
75 75
             'app_id'         => getenv('APOLLO_APP_ID'),
76
-            'cluster'        => ($cluster = (string)getenv('APOLLO_CLUSTER')) !== '' ? $cluster : null,
77
-            'namespaces'     => ($namespaces = (string)getenv('APOLLO_NAMESPACES')) !== '' ? explode(',', $namespaces) : null,
78
-            'client_ip'      => ($clientIp = (string)getenv('APOLLO_CLIENT_IP')) !== '' ? $clientIp : null,
79
-            'pull_timeout'   => ($pullTimeout = (int)getenv('APOLLO_PULL_TIMEOUT')) > 0 ? $pullTimeout : null,
80
-            'backup_old_env' => ($backupOldEnv = (bool)getenv('APOLLO_BACKUP_OLD_ENV')) ? $backupOldEnv : null,
76
+            'cluster'        => ($cluster = (string) getenv('APOLLO_CLUSTER')) !== '' ? $cluster : null,
77
+            'namespaces'     => ($namespaces = (string) getenv('APOLLO_NAMESPACES')) !== '' ? explode(',', $namespaces) : null,
78
+            'client_ip'      => ($clientIp = (string) getenv('APOLLO_CLIENT_IP')) !== '' ? $clientIp : null,
79
+            'pull_timeout'   => ($pullTimeout = (int) getenv('APOLLO_PULL_TIMEOUT')) > 0 ? $pullTimeout : null,
80
+            'backup_old_env' => ($backupOldEnv = (bool) getenv('APOLLO_BACKUP_OLD_ENV')) ? $backupOldEnv : null,
81 81
         ];
82 82
         return new static($settings);
83 83
     }
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
             'cluster'        => isset($options['apollo-cluster']) && $options['apollo-cluster'] !== '' ? $options['apollo-cluster'] : null,
94 94
             'namespaces'     => !empty($options['apollo-namespaces']) ? $options['apollo-namespaces'] : null,
95 95
             'client_ip'      => isset($options['apollo-client-ip']) && $options['apollo-client-ip'] !== '' ? $options['apollo-client-ip'] : null,
96
-            'pull_timeout'   => isset($options['apollo-pull-timeout']) ? (int)$options['apollo-pull-timeout'] : null,
97
-            'backup_old_env' => isset($options['apollo-backup-old-env']) ? (bool)$options['apollo-backup-old-env'] : null,
96
+            'pull_timeout'   => isset($options['apollo-pull-timeout']) ? (int) $options['apollo-pull-timeout'] : null,
97
+            'backup_old_env' => isset($options['apollo-backup-old-env']) ? (bool) $options['apollo-backup-old-env'] : null,
98 98
         ];
99 99
         return new static($settings);
100 100
     }
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $configs = [];
117 117
         $uri = sprintf('%s/configs/%s/%s/', $this->server, $this->appId, $this->cluster);
118 118
         foreach ($namespaces as $namespace) {
119
-            $url = $uri . $namespace . '?' . http_build_query([
119
+            $url = $uri.$namespace.'?'.http_build_query([
120 120
                     'releaseKey' => $withReleaseKey && isset($this->releaseKeys[$namespace]) ? $this->releaseKeys[$namespace] : null,
121 121
                     'ip'         => $this->clientIp,
122 122
                 ]);
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
         $all = $this->pullAll(false, $options);
147 147
         if (count($all) !== count($this->namespaces)) {
148 148
             $lackNamespaces = array_diff($this->namespaces, array_keys($all));
149
-            throw new \RuntimeException('Missing Apollo configurations for namespaces ' . implode(',', $lackNamespaces));
149
+            throw new \RuntimeException('Missing Apollo configurations for namespaces '.implode(',', $lackNamespaces));
150 150
         }
151 151
         $configs = [];
152 152
         foreach ($all as $namespace => $config) {
153
-            $configs[] = '# Namespace: ' . $config['namespaceName'];
153
+            $configs[] = '# Namespace: '.$config['namespaceName'];
154 154
             ksort($config['configurations']);
155 155
             foreach ($config['configurations'] as $key => $value) {
156 156
                 $configs[] = sprintf('%s=%s', $key, $value);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             throw new \RuntimeException('Empty Apollo configuration list');
161 161
         }
162 162
         if ($this->backupOldEnv && file_exists($filepath)) {
163
-            rename($filepath, $filepath . '.' . date('YmdHis'));
163
+            rename($filepath, $filepath.'.'.date('YmdHis'));
164 164
         }
165 165
         $fileContent = implode(PHP_EOL, $configs);
166 166
         if (Context::inCoroutine()) {
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
                 if (!empty($this->notifications) && current($this->notifications)['notificationId'] !== -1) { // Ignore the first pull
201 201
                     $callback($notifications);
202 202
                 }
203
-                array_walk($notifications, function (&$notification) {
203
+                array_walk($notifications, function(&$notification) {
204 204
                     unset($notification['messages']);
205 205
                 });
206 206
                 $this->notifications = array_merge($this->notifications, array_column($notifications, null, 'namespaceName'));
Please login to merge, or discard this patch.
src/Components/Prometheus/PrometheusCollectorProcess.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
         $taskWorkerNum = isset($swoole->setting['task_worker_num']) ? $swoole->setting['task_worker_num'] : 0;
21 21
         $totalNum = $workerNum + $taskWorkerNum - 1;
22 22
         $workerIds = range(0, $totalNum);
23
-        $runJob = function () use ($swoole, $workerIds, $collector) {
23
+        $runJob = function() use ($swoole, $workerIds, $collector) {
24 24
             foreach ($workerIds as $workerId) {
25 25
                 $swoole->sendMessage($collector, $workerId);
26 26
             }
Please login to merge, or discard this patch.
src/Components/Prometheus/PrometheusServiceProvider.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,22 +13,22 @@
 block discarded – undo
13 13
     public function boot()
14 14
     {
15 15
         $this->publishes([
16
-            __DIR__ . '/../../../config/prometheus.php' => base_path('config/prometheus.php'),
16
+            __DIR__.'/../../../config/prometheus.php' => base_path('config/prometheus.php'),
17 17
         ]);
18 18
     }
19 19
 
20 20
     public function register()
21 21
     {
22 22
         $this->mergeConfigFrom(
23
-            __DIR__ . '/../../../config/prometheus.php', 'prometheus'
23
+            __DIR__.'/../../../config/prometheus.php', 'prometheus'
24 24
         );
25
-        $this->app->singleton(HttpRequestCollector::class, function ($app) {
25
+        $this->app->singleton(HttpRequestCollector::class, function($app) {
26 26
             return new HttpRequestCollector($app['config']->get('prometheus'));
27 27
         });
28
-        $this->app->singleton(SwooleWorkerCollector::class, function ($app) {
28
+        $this->app->singleton(SwooleWorkerCollector::class, function($app) {
29 29
             return new SwooleWorkerCollector($app['config']->get('prometheus'));
30 30
         });
31
-        $this->app->singleton(PrometheusExporter::class, function ($app) {
31
+        $this->app->singleton(PrometheusExporter::class, function($app) {
32 32
             return new PrometheusExporter($app['config']->get('prometheus'));
33 33
         });
34 34
     }
Please login to merge, or discard this patch.