Skip to content

Commit 6facc6d

Browse files
committed
refactor: Remover configuração não utilizada em estratégias de overflow e coordenador NoOp
1 parent 7ff769a commit 6facc6d

File tree

6 files changed

+41
-45
lines changed

6 files changed

+41
-45
lines changed

src/Http/Pool/Strategies/GracefulFallback.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
*/
1313
class GracefulFallback implements OverflowStrategy
1414
{
15-
/**
16-
* Configuration
17-
*/
18-
private array $config;
19-
2015
/**
2116
* Metrics
2217
*/
@@ -29,9 +24,10 @@ class GracefulFallback implements OverflowStrategy
2924
/**
3025
* Constructor
3126
*/
32-
public function __construct(array $config)
27+
public function __construct(array $config = [])
3328
{
34-
$this->config = $config;
29+
// Configuration not used in GracefulFallback - intentionally ignored
30+
unset($config); // Suppress unused parameter warning
3531
}
3632

3733
/**
@@ -111,12 +107,12 @@ private function createFallbackRequest(array $params): mixed
111107
*/
112108
private function createFallbackResponse(array $params): mixed
113109
{
114-
return Psr7Pool::borrowResponse(
110+
return Psr7Pool::getResponse(
115111
$params[0] ?? 200,
116112
$params[1] ?? [],
117113
$params[2] ?? null,
118114
$params[3] ?? '1.1',
119-
$params[4] ?? null
115+
$params[4] ?? ''
120116
);
121117
}
122118

src/Http/Pool/Strategies/SmartRecycling.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
*/
1010
class SmartRecycling implements OverflowStrategy
1111
{
12-
/**
13-
* Configuration
14-
*/
15-
private array $config;
16-
1712
/**
1813
* Recycling candidates
1914
*/
@@ -37,9 +32,10 @@ class SmartRecycling implements OverflowStrategy
3732
/**
3833
* Constructor
3934
*/
40-
public function __construct(array $config)
35+
public function __construct(array $config = [])
4136
{
42-
$this->config = $config;
37+
// Configuration not used in SmartRecycling - intentionally ignored
38+
unset($config); // Suppress unused parameter warning
4339
}
4440

4541
/**
@@ -329,14 +325,13 @@ private function getAverageObjectAge(): float
329325

330326
$now = microtime(true);
331327
$totalAge = 0;
332-
$count = 0;
328+
$count = count($this->objectLifecycles);
333329

334330
foreach ($this->objectLifecycles as $lifecycle) {
335331
$totalAge += $now - $lifecycle['created_at'];
336-
$count++;
337332
}
338333

339-
return $count > 0 ? $totalAge / $count : 0.0;
334+
return $totalAge / $count;
340335
}
341336

342337
/**
@@ -379,4 +374,12 @@ public function cleanup(): void
379374
}
380375
}
381376
}
377+
378+
/**
379+
* Get recycling candidates
380+
*/
381+
public function getRecycleCandidates(): array
382+
{
383+
return $this->recycleCandidates;
384+
}
382385
}

src/Middleware/RateLimiter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ private function checkTokenBucket(string $key): bool
228228
$bucket['last_refill'] = $now;
229229

230230
// Check if token available
231-
if ($bucket['tokens'] < 1) {
231+
if ((float) $bucket['tokens'] < 1) {
232232
$this->setInStorage($storageKey, $bucket);
233233
return false;
234234
}
235235

236236
// Consume token
237-
$bucket['tokens']--;
237+
$bucket['tokens'] = (float) $bucket['tokens'] - 1;
238238
$this->setInStorage($storageKey, $bucket);
239239

240240
return true;
@@ -365,7 +365,7 @@ private function getRemainingFixedWindow(string $key): int
365365

366366
$count = $this->getFromStorage($storageKey, 0);
367367
$count = is_numeric($count) ? (int) $count : 0;
368-
return max(0, $this->config['max_requests'] - $count);
368+
return (int) max(0, $this->config['max_requests'] - $count);
369369
}
370370

371371
/**
@@ -380,9 +380,9 @@ private function getRemainingSlidingWindow(string $key): int
380380
$history = $this->getFromStorage($storageKey, []);
381381
if (is_array($history)) {
382382
$history = array_filter($history, fn($timestamp) => $timestamp > $windowStart);
383-
return max(0, $this->config['max_requests'] - count($history));
383+
return (int) max(0, $this->config['max_requests'] - count($history));
384384
}
385-
return $this->config['max_requests'];
385+
return (int) $this->config['max_requests'];
386386
}
387387

388388
/**
@@ -410,9 +410,9 @@ private function getRemainingLeakyBucket(string $key): int
410410

411411
if (is_array($bucket) && isset($bucket['volume'])) {
412412
$volume = is_numeric($bucket['volume']) ? (float) $bucket['volume'] : 0;
413-
return max(0, $this->config['max_requests'] - (int) ceil($volume));
413+
return (int) max(0, $this->config['max_requests'] - (int) ceil($volume));
414414
}
415-
return $this->config['max_requests'];
415+
return (int) $this->config['max_requests'];
416416
}
417417

418418
/**

src/Middleware/TrafficClassifier.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ private function normalizePriority(mixed $priority): int
193193
return max(0, min(100, $priority));
194194
}
195195

196-
return match (strtolower((string) $priority)) {
196+
$priorityString = is_string($priority) ? $priority : (is_numeric($priority) ? (string) $priority : 'normal');
197+
return match (strtolower($priorityString)) {
197198
'system' => self::PRIORITY_SYSTEM,
198199
'critical' => self::PRIORITY_CRITICAL,
199200
'high' => self::PRIORITY_HIGH,
@@ -301,7 +302,7 @@ private function matchesPathPattern(Request $request, string $pattern): bool
301302
*/
302303
private function matchesHeader(Request $request, string $name, string $value): bool
303304
{
304-
$headerValue = $request->getHeaders()->get($name);
305+
$headerValue = $request->getHeadersObject()->get($name);
305306

306307
if ($headerValue === null) {
307308
return false;

src/Performance/HighPerformanceMode.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ public static function enable(
214214
self::initializeMemoryManagement();
215215

216216
if ($app !== null) {
217-
self::$app = $app;
218217
self::initializeTrafficManagement($app);
219218
self::initializeProtection($app);
220219
self::initializeMonitoring($app);
@@ -340,7 +339,7 @@ function ($request, $response, $next) {
340339
$requestId = uniqid('req_', true);
341340

342341
// Start monitoring
343-
self::$monitor->startRequest(
342+
self::$monitor?->startRequest(
344343
$requestId,
345344
[
346345
'path' => $request->pathCallable,
@@ -353,20 +352,20 @@ function ($request, $response, $next) {
353352
$result = $next($request, $response);
354353

355354
// End monitoring
356-
self::$monitor->endRequest($requestId, $response->getStatusCode());
355+
self::$monitor?->endRequest($requestId, $response->getStatusCode());
357356

358357
return $result;
359358
} catch (\Throwable $e) {
360359
// Record error
361-
self::$monitor->recordError(
360+
self::$monitor?->recordError(
362361
'exception',
363362
[
364363
'message' => $e->getMessage(),
365364
'code' => $e->getCode(),
366365
]
367366
);
368367

369-
self::$monitor->endRequest($requestId, 500);
368+
self::$monitor?->endRequest($requestId, 500);
370369

371370
throw $e;
372371
}
@@ -375,10 +374,12 @@ function ($request, $response, $next) {
375374
}
376375

377376
// Schedule periodic tasks
378-
self::schedulePeriodicTask(
379-
self::$currentConfig['monitoring']['export_interval'],
380-
[self::$monitor, 'export']
381-
);
377+
if (self::$monitor) {
378+
self::schedulePeriodicTask(
379+
self::$currentConfig['monitoring']['export_interval'],
380+
[self::$monitor, 'export']
381+
);
382+
}
382383
}
383384

384385
/**

src/Pool/Distributed/Coordinators/NoOpCoordinator.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
*/
1313
class NoOpCoordinator implements CoordinatorInterface
1414
{
15-
/**
16-
* Configuration
17-
*/
18-
private array $config;
19-
2015
/**
2116
* Constructor
2217
*/
23-
public function __construct(array $config)
18+
public function __construct(array $config = [])
2419
{
25-
$this->config = $config;
20+
// Configuration not used in NoOpCoordinator - intentionally ignored
21+
unset($config); // Suppress unused parameter warning
2622
}
2723

2824
/**
@@ -153,4 +149,3 @@ public function getGlobalPoolSize(): int
153149
return 0;
154150
}
155151
}
156-

0 commit comments

Comments
 (0)