Skip to content

Commit a0031fa

Browse files
committed
fix: cs
1 parent 62ef303 commit a0031fa

File tree

7 files changed

+35
-34
lines changed

7 files changed

+35
-34
lines changed

src/Console/Commands/FrankenPhpWorkerStatusCommand.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,18 @@ private function checkWorkerModeStatus(): void
8484

8585
$workerStatus = Measure::getWorkerStatus();
8686

87-
if (!$workerStatus['worker_mode']) {
87+
if (! $workerStatus['worker_mode']) {
8888
$this->line(' ⚠️ Not running in FrankenPHP worker mode');
8989
$this->line('');
90+
9091
return;
9192
}
9293

93-
$this->line(" 🔄 Worker Mode: <info>Active</info>");
94+
$this->line(' 🔄 Worker Mode: <info>Active</info>');
9495
$this->line(" 🆔 Process ID: <info>{$workerStatus['pid']}</info>");
95-
$this->line(" 📊 Memory Usage: <info>" . $this->formatBytes($workerStatus['memory_usage']) . "</info>");
96-
$this->line(" 📈 Peak Memory: <info>" . $this->formatBytes($workerStatus['peak_memory']) . "</info>");
97-
$this->line(" 🎯 Current Span Recording: <info>" . ($workerStatus['current_span_recording'] ? 'Yes' : 'No') . "</info>");
96+
$this->line(' 📊 Memory Usage: <info>'.$this->formatBytes($workerStatus['memory_usage']).'</info>');
97+
$this->line(' 📈 Peak Memory: <info>'.$this->formatBytes($workerStatus['peak_memory']).'</info>');
98+
$this->line(' 🎯 Current Span Recording: <info>'.($workerStatus['current_span_recording'] ? 'Yes' : 'No').'</info>');
9899
$this->line(" 🔗 Trace ID: <info>{$workerStatus['trace_id']}</info>");
99100

100101
$this->line('');
@@ -128,7 +129,7 @@ private function checkOpenTelemetryIntegration(): void
128129
*/
129130
private function displayWorkerStats(): void
130131
{
131-
if (!class_exists(FrankenPhpWorkerWatcher::class)) {
132+
if (! class_exists(FrankenPhpWorkerWatcher::class)) {
132133
return;
133134
}
134135

@@ -138,14 +139,14 @@ private function displayWorkerStats(): void
138139
$stats = FrankenPhpWorkerWatcher::getWorkerStats();
139140

140141
$this->line(" 📈 Request Count: <info>{$stats['request_count']}</info>");
141-
$this->line(" 💾 Current Memory: <info>" . $this->formatBytes($stats['current_memory']) . "</info>");
142-
$this->line(" 📊 Peak Memory: <info>" . $this->formatBytes($stats['peak_memory']) . "</info>");
143-
$this->line(" 🔺 Memory Increase: <info>" . $this->formatBytes($stats['memory_increase']) . "</info>");
144-
$this->line(" 🏁 Initial Memory: <info>" . $this->formatBytes($stats['initial_memory']) . "</info>");
142+
$this->line(' 💾 Current Memory: <info>'.$this->formatBytes($stats['current_memory']).'</info>');
143+
$this->line(' 📊 Peak Memory: <info>'.$this->formatBytes($stats['peak_memory']).'</info>');
144+
$this->line(' 🔺 Memory Increase: <info>'.$this->formatBytes($stats['memory_increase']).'</info>');
145+
$this->line(' 🏁 Initial Memory: <info>'.$this->formatBytes($stats['initial_memory']).'</info>');
145146

146147
// 内存增长警告
147148
if ($stats['memory_increase'] > 50 * 1024 * 1024) { // 50MB
148-
$this->warn(" ⚠️ High memory increase detected!");
149+
$this->warn(' ⚠️ High memory increase detected!');
149150
}
150151

151152
} catch (\Throwable $e) {
@@ -167,8 +168,8 @@ private function displayMemoryUsage(): void
167168
$peakMemory = memory_get_peak_usage(true);
168169

169170
$this->line(" 📊 Memory Limit: <info>{$memoryLimit}</info>");
170-
$this->line(" 📈 Current Usage: <info>" . $this->formatBytes($currentMemory) . "</info>");
171-
$this->line(" 🔝 Peak Usage: <info>" . $this->formatBytes($peakMemory) . "</info>");
171+
$this->line(' 📈 Current Usage: <info>'.$this->formatBytes($currentMemory).'</info>');
172+
$this->line(' 🔝 Peak Usage: <info>'.$this->formatBytes($peakMemory).'</info>');
172173

173174
// 计算内存使用率
174175
if ($memoryLimit !== '-1') {
@@ -178,7 +179,7 @@ private function displayMemoryUsage(): void
178179
$this->line(" 📊 Usage Percentage: <info>{$usagePercent}%</info>");
179180

180181
if ($usagePercent > 80) {
181-
$this->warn(" ⚠️ High memory usage detected!");
182+
$this->warn(' ⚠️ High memory usage detected!');
182183
}
183184
}
184185
}
@@ -222,7 +223,7 @@ private function formatBytes(int $bytes): string
222223

223224
$bytes /= (1 << (10 * $pow));
224225

225-
return round($bytes, 2) . ' ' . $units[$pow];
226+
return round($bytes, 2).' '.$units[$pow];
226227
}
227228

228229
/**

src/Hooks/Illuminate/Http/Kernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function handleWorkerRequestStart(): void
9191
event('kernel.handling');
9292
}
9393
} catch (\Throwable $e) {
94-
error_log("FrankenPHP worker request start error: " . $e->getMessage());
94+
error_log('FrankenPHP worker request start error: '.$e->getMessage());
9595
}
9696
}
9797

@@ -109,7 +109,7 @@ private function handleWorkerRequestEnd(): void
109109
// 清理可能残留的资源
110110
$this->cleanupWorkerRequestResources();
111111
} catch (\Throwable $e) {
112-
error_log("FrankenPHP worker request end error: " . $e->getMessage());
112+
error_log('FrankenPHP worker request end error: '.$e->getMessage());
113113
}
114114
}
115115

@@ -143,7 +143,7 @@ private function cleanupWorkerRequestResources(): void
143143
// 清理可能的全局状态
144144
$this->resetGlobalState();
145145
} catch (\Throwable $e) {
146-
error_log("FrankenPHP worker cleanup error: " . $e->getMessage());
146+
error_log('FrankenPHP worker cleanup error: '.$e->getMessage());
147147
}
148148
}
149149

src/Support/Measure.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function isFrankenPhpWorkerMode(): bool
9494
*/
9595
public function cleanupWorkerState(): void
9696
{
97-
if (!$this->isFrankenPhpWorkerMode()) {
97+
if (! $this->isFrankenPhpWorkerMode()) {
9898
return;
9999
}
100100

@@ -119,7 +119,7 @@ public function cleanupWorkerState(): void
119119

120120
} catch (\Throwable $e) {
121121
// 静默处理清理错误
122-
error_log("OpenTelemetry worker cleanup error: " . $e->getMessage());
122+
error_log('OpenTelemetry worker cleanup error: '.$e->getMessage());
123123
}
124124
}
125125

@@ -128,7 +128,7 @@ public function cleanupWorkerState(): void
128128
*/
129129
public function getWorkerStatus(): array
130130
{
131-
if (!$this->isFrankenPhpWorkerMode()) {
131+
if (! $this->isFrankenPhpWorkerMode()) {
132132
return ['worker_mode' => false];
133133
}
134134

src/Watchers/FrankenPhpWorkerWatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Overtrue\LaravelOpenTelemetry\Watchers;
66

77
use Illuminate\Contracts\Foundation\Application;
8-
use OpenTelemetry\API\Globals;
98
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
109
use OpenTelemetry\API\Trace\SpanKind;
1110
use OpenTelemetry\Contrib\Instrumentation\Laravel\Watchers\Watcher;
@@ -18,6 +17,7 @@
1817
class FrankenPhpWorkerWatcher extends Watcher
1918
{
2019
private static int $requestCount = 0;
20+
2121
private static array $initialMemoryState = [];
2222

2323
public function __construct(
@@ -27,7 +27,7 @@ public function __construct(
2727
public function register(Application $app): void
2828
{
2929
// 只在 FrankenPHP worker 模式下注册
30-
if (!$this->isFrankenPhpWorkerMode()) {
30+
if (! $this->isFrankenPhpWorkerMode()) {
3131
return;
3232
}
3333

@@ -162,7 +162,7 @@ private function cleanupOpenTelemetryState(): void
162162

163163
} catch (\Throwable $e) {
164164
// 静默处理清理错误,避免影响正常请求
165-
error_log("OpenTelemetry cleanup error in FrankenPHP worker: " . $e->getMessage());
165+
error_log('OpenTelemetry cleanup error in FrankenPHP worker: '.$e->getMessage());
166166
}
167167
}
168168

tests/Hooks/Illuminate/Http/KernelTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function test_adds_trace_id_to_response_header()
2525
Measure::shouldReceive('traceId')->andReturn($expectedTraceId);
2626

2727
// Create hook - 在测试环境中直接实例化而不是通过 hook() 方法
28-
$hook = new Kernel();
28+
$hook = new Kernel;
2929

3030
// Create response
3131
$response = new Response;
@@ -48,7 +48,7 @@ public function test_does_not_add_header_when_config_is_null()
4848
config(['otel.response_trace_header_name' => null]);
4949

5050
// Create hook - 在测试环境中直接实例化
51-
$hook = new Kernel();
51+
$hook = new Kernel;
5252

5353
// Create response
5454
$response = new Response;
@@ -71,7 +71,7 @@ public function test_does_not_add_header_when_config_is_empty()
7171
config(['otel.response_trace_header_name' => '']);
7272

7373
// Create hook - 在测试环境中直接实例化
74-
$hook = new Kernel();
74+
$hook = new Kernel;
7575

7676
// Create response
7777
$response = new Response;
@@ -97,7 +97,7 @@ public function test_does_not_add_header_when_trace_id_is_empty()
9797
Measure::shouldReceive('traceId')->andReturn('');
9898

9999
// Create hook - 在测试环境中直接实例化
100-
$hook = new Kernel();
100+
$hook = new Kernel;
101101

102102
// Create response
103103
$response = new Response;
@@ -124,7 +124,7 @@ public function test_does_not_add_header_when_trace_id_is_all_zeros()
124124
Measure::shouldReceive('traceId')->andReturn($allZerosTraceId);
125125

126126
// Create hook - 在测试环境中直接实例化
127-
$hook = new Kernel();
127+
$hook = new Kernel;
128128

129129
// Create response
130130
$response = new Response;
@@ -150,7 +150,7 @@ public function test_handles_exception_gracefully()
150150
Measure::shouldReceive('traceId')->andThrow(new \Exception('Test exception'));
151151

152152
// Create hook - 在测试环境中直接实例化
153-
$hook = new Kernel();
153+
$hook = new Kernel;
154154

155155
// Create response
156156
$response = new Response;
@@ -177,7 +177,7 @@ public function test_uses_custom_header_name()
177177
Measure::shouldReceive('traceId')->andReturn($expectedTraceId);
178178

179179
// Create hook - 在测试环境中直接实例化
180-
$hook = new Kernel();
180+
$hook = new Kernel;
181181

182182
// Create response
183183
$response = new Response;

tests/OpenTelemetryServiceProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Illuminate\Http\Client\PendingRequest;
66
use Illuminate\Support\Facades\Log;
77
use Mockery;
8-
use Overtrue\LaravelOpenTelemetry\Console\Commands\TestCommand;
98
use Overtrue\LaravelOpenTelemetry\Console\Commands\FrankenPhpWorkerStatusCommand;
9+
use Overtrue\LaravelOpenTelemetry\Console\Commands\TestCommand;
1010
use Overtrue\LaravelOpenTelemetry\OpenTelemetryServiceProvider;
1111
use Overtrue\LaravelOpenTelemetry\Support\Measure;
1212

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
abstract class TestCase extends OrchestraTestCase
99
{
10-
protected function setUp(): void
10+
protected function setUp(): void
1111
{
1212
parent::setUp();
1313
}
@@ -56,7 +56,7 @@ protected function defineEnvironment($app)
5656
$app['config']->set('otel.enabled', true);
5757
}
5858

59-
protected function getEnvironmentSetUp($app): void
59+
protected function getEnvironmentSetUp($app): void
6060
{
6161
// Setup the application environment for testing
6262
config()->set('database.default', 'testing');

0 commit comments

Comments
 (0)