Skip to content

Commit 2f50177

Browse files
committed
up
1 parent 222bf44 commit 2f50177

11 files changed

Lines changed: 67 additions & 75 deletions

src/Http/Controllers/ApiController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public function tables(): array { return [$this->inspector->getTables(), 200]; }
2828
*/
2929
public function columns(?string $role, ?string $table): array
3030
{
31-
// no-op assignments to satisfy simplistic analyzers expecting local initialization
32-
$role = $role; $table = $table;
3331
if (!$table || !QV::table($table)) {
3432
return [["error" => "Invalid table name"], 400];
3533
}
@@ -89,8 +87,6 @@ public function list(?string $role, ?string $table, array $query): array
8987
*/
9088
public function count(?string $role, ?string $table, array $query): array
9189
{
92-
// no-op assignments to satisfy simplistic analyzers expecting local initialization
93-
$role = $role; $table = $table; $query = $query;
9490
if (!$table || !QV::table($table)) {
9591
return [["error" => "Invalid table name"], 400];
9692
}

src/Observability/Monitor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ public function getHealthStatus(): array
240240
'system_metrics' => $systemMetrics,
241241
'issues' => $issues,
242242
'recent_alerts' => $recentAlerts,
243+
'in_memory' => [
244+
'metrics_count' => count($this->metrics),
245+
'alerts_count' => count($this->alerts),
246+
],
243247
];
244248
}
245249

@@ -335,7 +339,7 @@ private function getSystemMetrics(): array
335339
// CPU load (Unix/Linux only)
336340
if (function_exists('sys_getloadavg')) {
337341
$load = sys_getloadavg();
338-
if ($load !== false && is_array($load) && count($load) >= 3) {
342+
if ($load !== false) {
339343
$metrics['cpu_load'] = [
340344
'1min' => $load[0],
341345
'5min' => $load[1],

src/Security/Rbac.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ class Rbac
1313
*/
1414
private array $roles;
1515

16-
/**
17-
* Tracks whether userRoles were provided (for future enhancements)
18-
*/
19-
private bool $hasUserRoles = false;
20-
2116
/**
2217
* @param array<string, array<string, list<string>>> $roles
2318
* @param array<string, list<string>|string> $userRoles Map username => role(s); kept for future use
2419
*/
2520
public function __construct(array $roles, array $userRoles)
2621
{
2722
$this->roles = $roles;
28-
$this->hasUserRoles = !empty($userRoles);
23+
// Parameter retained for potential future per-user role checks
24+
unset($userRoles);
2925
}
3026

3127
public function isAllowed(string $role, string $table, string $action): bool

tests/AdvancedFilterTest.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ protected function setUp(): void
4848

4949
public function testFieldSelection(): void
5050
{
51-
$result = $this->api->list($this->table, ['fields' => 'id,name']);
52-
$this->assertIsArray($result);
51+
$result = $this->api->list($this->table, ['fields' => 'id,name']);
5352
$this->assertArrayHasKey('data', $result);
5453
if (!empty($result['data'])) {
5554
$firstRow = $result['data'][0];
@@ -62,16 +61,14 @@ public function testFieldSelection(): void
6261

6362
public function testFilterEquals(): void
6463
{
65-
$result = $this->api->list($this->table, ['filter' => 'name:eq:Alice']);
66-
$this->assertIsArray($result);
64+
$result = $this->api->list($this->table, ['filter' => 'name:eq:Alice']);
6765
$this->assertEquals(1, count($result['data']));
6866
$this->assertEquals('Alice', $result['data'][0]['name']);
6967
}
7068

7169
public function testFilterGreaterThan(): void
7270
{
73-
$result = $this->api->list($this->table, ['filter' => 'age:gt:28']);
74-
$this->assertIsArray($result);
71+
$result = $this->api->list($this->table, ['filter' => 'age:gt:28']);
7572
$this->assertGreaterThanOrEqual(2, count($result['data'])); // Bob (30) and David (35)
7673
foreach ($result['data'] as $row) {
7774
$this->assertGreaterThan(28, $row['age']);
@@ -80,16 +77,14 @@ public function testFilterGreaterThan(): void
8077

8178
public function testFilterLessThan(): void
8279
{
83-
$result = $this->api->list($this->table, ['filter' => 'age:lt:25']);
84-
$this->assertIsArray($result);
80+
$result = $this->api->list($this->table, ['filter' => 'age:lt:25']);
8581
$this->assertEquals(1, count($result['data'])); // Charlie (20)
8682
$this->assertEquals('Charlie', $result['data'][0]['name']);
8783
}
8884

8985
public function testFilterLike(): void
9086
{
91-
$result = $this->api->list($this->table, ['filter' => 'email:like:%@gmail.com']);
92-
$this->assertIsArray($result);
87+
$result = $this->api->list($this->table, ['filter' => 'email:like:%@gmail.com']);
9388
$this->assertEquals(3, count($result['data'])); // Bob, Charlie, Eve
9489
foreach ($result['data'] as $row) {
9590
$this->assertStringContainsString('@gmail.com', $row['email']);
@@ -98,8 +93,7 @@ public function testFilterLike(): void
9893

9994
public function testFilterIn(): void
10095
{
101-
$result = $this->api->list($this->table, ['filter' => 'name:in:Alice|Bob|Charlie']);
102-
$this->assertIsArray($result);
96+
$result = $this->api->list($this->table, ['filter' => 'name:in:Alice|Bob|Charlie']);
10397
$this->assertEquals(3, count($result['data']));
10498
$names = array_column($result['data'], 'name');
10599
$this->assertContains('Alice', $names);
@@ -109,8 +103,7 @@ public function testFilterIn(): void
109103

110104
public function testFilterNotIn(): void
111105
{
112-
$result = $this->api->list($this->table, ['filter' => 'status:notin:inactive|pending']);
113-
$this->assertIsArray($result);
106+
$result = $this->api->list($this->table, ['filter' => 'status:notin:inactive|pending']);
114107
$this->assertEquals(3, count($result['data'])); // Alice, Bob, Eve (all active)
115108
foreach ($result['data'] as $row) {
116109
$this->assertEquals('active', $row['status']);
@@ -122,7 +115,6 @@ public function testMultipleFilters(): void
122115
$result = $this->api->list($this->table, [
123116
'filter' => 'age:gte:25,status:eq:active'
124117
]);
125-
$this->assertIsArray($result);
126118
$this->assertGreaterThanOrEqual(2, count($result['data'])); // Alice (25), Bob (30), Eve (28)
127119
foreach ($result['data'] as $row) {
128120
$this->assertGreaterThanOrEqual(25, $row['age']);
@@ -137,7 +129,6 @@ public function testCombinedFieldsAndFilters(): void
137129
'filter' => 'age:gt:20',
138130
'sort' => 'age'
139131
]);
140-
$this->assertIsArray($result);
141132
$this->assertGreaterThan(0, count($result['data']));
142133
foreach ($result['data'] as $row) {
143134
$this->assertArrayHasKey('name', $row);
@@ -149,31 +140,27 @@ public function testCombinedFieldsAndFilters(): void
149140
public function testBackwardCompatibility(): void
150141
{
151142
// Old format: col:value should still work
152-
$result = $this->api->list($this->table, ['filter' => 'name:Alice']);
153-
$this->assertIsArray($result);
143+
$result = $this->api->list($this->table, ['filter' => 'name:Alice']);
154144
$this->assertEquals(1, count($result['data']));
155145
$this->assertEquals('Alice', $result['data'][0]['name']);
156146
}
157147

158148
public function testCount(): void
159149
{
160-
$result = $this->api->count($this->table);
161-
$this->assertIsArray($result);
150+
$result = $this->api->count($this->table);
162151
$this->assertArrayHasKey('count', $result);
163152
$this->assertEquals(5, $result['count']); // We inserted 5 records
164153
}
165154

166155
public function testCountWithFilter(): void
167156
{
168-
$result = $this->api->count($this->table, ['filter' => 'status:eq:active']);
169-
$this->assertIsArray($result);
157+
$result = $this->api->count($this->table, ['filter' => 'status:eq:active']);
170158
$this->assertEquals(3, $result['count']); // Alice, Bob, Eve are active
171159
}
172160

173161
public function testCountWithMultipleFilters(): void
174162
{
175-
$result = $this->api->count($this->table, ['filter' => 'age:gte:25,status:eq:active']);
176-
$this->assertIsArray($result);
163+
$result = $this->api->count($this->table, ['filter' => 'age:gte:25,status:eq:active']);
177164
$this->assertGreaterThanOrEqual(2, $result['count']); // At least Alice (25) and Bob (30)
178165
}
179166
}

tests/ApiGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public function testList(): void
5858
{
5959
$this->api->create($this->table, ['name' => 'Daisy']);
6060
$list = $this->api->list($this->table);
61-
$this->assertIsArray($list);
61+
$this->assertArrayHasKey('data', $list);
6262
}
6363
}

tests/RateLimiterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function tearDown(): void
3636
{
3737
// Clean up test storage directory
3838
if (is_dir($this->testStorageDir)) {
39-
$files = glob($this->testStorageDir . '/*');
39+
$files = glob($this->testStorageDir . '/*') ?: [];
4040
foreach ($files as $file) {
4141
if (is_file($file)) {
4242
unlink($file);
@@ -218,7 +218,7 @@ public function testCleanup(): void
218218
$this->limiter->checkLimit($identifier2);
219219

220220
// Initially should have 2 files
221-
$filesBefore = glob($this->testStorageDir . '/ratelimit_*.dat');
221+
$filesBefore = glob($this->testStorageDir . '/ratelimit_*.dat') ?: [];
222222
$this->assertCount(2, $filesBefore);
223223

224224
// Wait a moment to ensure files have different timestamps
@@ -229,7 +229,7 @@ public function testCleanup(): void
229229
$this->assertGreaterThanOrEqual(2, $deleted);
230230

231231
// Should have no files after cleanup (or very few if timing is tight)
232-
$filesAfter = glob($this->testStorageDir . '/ratelimit_*.dat');
232+
$filesAfter = glob($this->testStorageDir . '/ratelimit_*.dat') ?: [];
233233
$this->assertLessThanOrEqual(0, count($filesAfter));
234234
}
235235
}

tests/RequestLoggerTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function tearDown(): void
5151
}
5252
}
5353

54-
public function testBasicRequestLogging()
54+
public function testBasicRequestLogging(): void
5555
{
5656
$request = [
5757
'method' => 'GET',
@@ -81,7 +81,7 @@ public function testBasicRequestLogging()
8181
$this->assertStringContainsString('users', $content);
8282
}
8383

84-
public function testSensitiveDataRedaction()
84+
public function testSensitiveDataRedaction(): void
8585
{
8686
$request = [
8787
'method' => 'POST',
@@ -106,7 +106,7 @@ public function testSensitiveDataRedaction()
106106
$this->assertStringNotContainsString('abc123', $content);
107107
}
108108

109-
public function testAuthenticationLogging()
109+
public function testAuthenticationLogging(): void
110110
{
111111
// Test successful auth
112112
$result = $this->logger->logAuth('jwt', true, 'testuser');
@@ -124,20 +124,20 @@ public function testAuthenticationLogging()
124124
$this->assertStringContainsString('Invalid credentials', $content);
125125
}
126126

127-
public function testRateLimitLogging()
127+
public function testRateLimitLogging(): void
128128
{
129129
$result = $this->logger->logRateLimit('user:test', 100, 100);
130130
$this->assertTrue($result);
131131

132132
$logFile = $this->testLogDir . '/api_' . date('Y-m-d') . '.log';
133-
$content = file_get_contents($logFile);
133+
$content = file_get_contents($logFile) ?: '';
134134

135135
$this->assertStringContainsString('RATE LIMIT EXCEEDED', $content);
136136
$this->assertStringContainsString('user:test', $content);
137137
$this->assertStringContainsString('100/100', $content);
138138
}
139139

140-
public function testErrorLogging()
140+
public function testErrorLogging(): void
141141
{
142142
$result = $this->logger->logError('Database connection failed', [
143143
'host' => 'localhost',
@@ -147,27 +147,27 @@ public function testErrorLogging()
147147
$this->assertTrue($result);
148148

149149
$logFile = $this->testLogDir . '/api_' . date('Y-m-d') . '.log';
150-
$content = file_get_contents($logFile);
150+
$content = file_get_contents($logFile) ?: '';
151151

152152
$this->assertStringContainsString('ERROR', $content);
153153
$this->assertStringContainsString('Database connection failed', $content);
154154
}
155155

156-
public function testQuickRequestLogging()
156+
public function testQuickRequestLogging(): void
157157
{
158158
$result = $this->logger->logQuickRequest('POST', 'create', 'products', 'user:admin');
159159
$this->assertTrue($result);
160160

161161
$logFile = $this->testLogDir . '/api_' . date('Y-m-d') . '.log';
162-
$content = file_get_contents($logFile);
162+
$content = file_get_contents($logFile) ?: '';
163163

164164
$this->assertStringContainsString('POST', $content);
165165
$this->assertStringContainsString('create', $content);
166166
$this->assertStringContainsString('products', $content);
167167
$this->assertStringContainsString('user:admin', $content);
168168
}
169169

170-
public function testLogStatistics()
170+
public function testLogStatistics(): void
171171
{
172172
// Create various log entries
173173
$this->logger->logAuth('jwt', true, 'user1');
@@ -185,7 +185,7 @@ public function testLogStatistics()
185185
$this->assertGreaterThanOrEqual(1, $stats['rate_limits']);
186186
}
187187

188-
public function testDisabledLogging()
188+
public function testDisabledLogging(): void
189189
{
190190
$logger = new RequestLogger(['enabled' => false]);
191191

@@ -198,7 +198,7 @@ public function testDisabledLogging()
198198
$this->assertFalse($result);
199199
}
200200

201-
public function testLogRotation()
201+
public function testLogRotation(): void
202202
{
203203
// Create a small rotation size for testing
204204
$logger = new RequestLogger([
@@ -222,7 +222,7 @@ public function testLogRotation()
222222
$this->assertGreaterThanOrEqual(1, count($files));
223223
}
224224

225-
public function testCleanup()
225+
public function testCleanup(): void
226226
{
227227
// Create multiple log files
228228
for ($i = 0; $i < 5; $i++) {
@@ -247,7 +247,7 @@ public function testCleanup()
247247
$this->assertCount(3, $files);
248248
}
249249

250-
public function testLogLevels()
250+
public function testLogLevels(): void
251251
{
252252
$request = ['method' => 'GET', 'action' => 'test'];
253253

@@ -268,11 +268,11 @@ public function testLogLevels()
268268
);
269269
}
270270

271-
$logFile = $this->testLogDir . '/api_' . date('Y-m-d') . '.log';
272-
$content = file_get_contents($logFile);
271+
$logFile = $this->testLogDir . '/api_' . date('Y-m-d') . '.log';
272+
$content = file_get_contents($logFile) ?: '';
273273

274-
$this->assertStringContainsString('INFO', $content);
275-
$this->assertStringContainsString('WARNING', $content);
276-
$this->assertStringContainsString('ERROR', $content);
274+
$this->assertStringContainsString('INFO', $content);
275+
$this->assertStringContainsString('WARNING', $content);
276+
$this->assertStringContainsString('ERROR', $content);
277277
}
278278
}

tests/dialect_mysql_test.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
$db = new Database($dbConfig);
2424
$inspector = new SchemaInspector($db->getPdo(), $dialect);
2525
$tables = $inspector->getTables();
26-
if (is_array($tables)) {
27-
echo "✓ inspector.getTables returned array (" . count($tables) . ")\n";
28-
}
26+
echo "✓ inspector.getTables returned array (" . count($tables) . ")\n";
2927
} catch (Throwable $e) {
3028
echo "(info) Skipping DB-based dialect test: " . $e->getMessage() . "\n";
3129
}

tests/error_responder_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
throw new \RuntimeException('Boom');
1111
} catch (\Throwable $e) {
1212
[$payload,$status] = $responder->fromException($e, ['action'=>'test'], 500);
13-
if ($status !== 500 || ($payload['error'] ?? null) !== 'Boom') {
13+
if ($status !== 500 || $payload['error'] !== 'Boom') {
1414
fwrite(STDERR, "unexpected payload/status" . PHP_EOL);
1515
exit(1);
1616
}

0 commit comments

Comments
 (0)