From bdd97938c2ac7f7719623280990a7451ae992e8c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 27 Feb 2026 12:37:58 +0000 Subject: [PATCH] Fix PHPStan analysis issues - Remove redundant is_string() check for severity option (already narrowed) - Replace method_exists() with instanceof for audit service getName() - Use iterator_to_array() for RouteCollection to fix foreach.nonIterable Co-authored-by: Nathan Langer --- src/Commands/WardenAuditCommand.php | 8 ++++---- src/Services/Audits/DebugModeAuditService.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Commands/WardenAuditCommand.php b/src/Commands/WardenAuditCommand.php index 71c1e21..9be3427 100644 --- a/src/Commands/WardenAuditCommand.php +++ b/src/Commands/WardenAuditCommand.php @@ -159,9 +159,7 @@ protected function processResults(array $allFindings, array $abandonedPackages, // Apply severity filtering if specified if ($this->option('severity')) { $severityOption = $this->option('severity'); - if (is_string($severityOption)) { - $allFindings = $this->filterBySeverity($allFindings, $severityOption); - } + $allFindings = $this->filterBySeverity($allFindings, (string) $severityOption); } // Handle abandoned packages @@ -253,7 +251,9 @@ protected function initializeAuditServices(): array */ protected function handleAuditFailure(object $service): void { - $serviceName = method_exists($service, 'getName') ? $service->getName() : 'Unknown service'; + $serviceName = $service instanceof \Dgtlss\Warden\Services\Audits\AbstractAuditService || $service instanceof CustomAuditWrapper + ? $service->getName() + : 'Unknown service'; $this->error($serviceName . ' audit failed to run.'); if ($service instanceof ComposerAuditService) { $findings = $service->getFindings(); diff --git a/src/Services/Audits/DebugModeAuditService.php b/src/Services/Audits/DebugModeAuditService.php index 69f3c0a..c298d31 100644 --- a/src/Services/Audits/DebugModeAuditService.php +++ b/src/Services/Audits/DebugModeAuditService.php @@ -108,9 +108,10 @@ private function getInstalledPackages(): array private function hasExposedTestingRoutes(): bool { $routeCollection = \Route::getRoutes(); + $routes = iterator_to_array($routeCollection, false); // Check debugbar routes separately as they're allowed when APP_DEBUG is true - foreach ($routeCollection as $route) { + foreach ($routes as $route) { $uri = $route->uri(); if (str_starts_with($uri, '_debugbar')) { // Only flag debugbar routes as exposed if APP_DEBUG is false and there's no protective middleware