44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
final class RouteInventoryCheckCommand extends Command
|
|
{
|
|
protected $signature = 'app:route-inventory-check {--path=storage/app/generated/api-route-inventory.json}';
|
|
protected $description = 'Check generated route inventory for governance metadata gaps.';
|
|
|
|
public function handle(): int
|
|
{
|
|
$path = base_path((string) $this->option('path'));
|
|
if (! is_file($path)) {
|
|
$this->error('Route inventory missing. Run php artisan api:route-inventory first.');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$rows = json_decode(file_get_contents($path) ?: '[]', true) ?: [];
|
|
$failures = [];
|
|
foreach ($rows as $row) {
|
|
$uri = (string) ($row['uri'] ?? '');
|
|
$methods = $row['methods'] ?? [];
|
|
$mutation = count(array_intersect($methods, ['POST', 'PUT', 'PATCH', 'DELETE'])) > 0;
|
|
if (($row['module'] ?? 'unknown') === 'unknown') {
|
|
$failures[] = $uri.' is missing module classification.';
|
|
}
|
|
if ($mutation && empty($row['auth_required'])) {
|
|
$failures[] = $uri.' is a mutation route without auth metadata.';
|
|
}
|
|
if (str_contains($uri, 'islamic-sunday-school') && ! str_contains(json_encode($row['middleware'] ?? []), 'domain.profile')) {
|
|
$failures[] = $uri.' is an extension route without domain profile middleware.';
|
|
}
|
|
}
|
|
|
|
foreach ($failures as $failure) {
|
|
$this->error($failure);
|
|
}
|
|
|
|
return $failures === [] ? self::SUCCESS : self::FAILURE;
|
|
}
|
|
}
|