From dd081da81cfce4d7ea5cf73711d7b3d6ea11d7c0 Mon Sep 17 00:00:00 2001 From: Funky Waddle Date: Sun, 15 Feb 2026 13:19:45 -0600 Subject: [PATCH] chore: resolve all PSR-12 line length warnings in src directory --- src/Commands/TestRouteCommand.php | 4 +- src/Router/ModuleLoader.php | 7 ++- src/Router/RouteGroup.php | 101 ++++++++++++++++++++++++++---- src/Router/RouteMatcher.php | 67 ++++++++++++-------- src/Router/Router.php | 26 ++++++-- 5 files changed, 159 insertions(+), 46 deletions(-) diff --git a/src/Commands/TestRouteCommand.php b/src/Commands/TestRouteCommand.php index 33443a0..f0e9390 100644 --- a/src/Commands/TestRouteCommand.php +++ b/src/Commands/TestRouteCommand.php @@ -288,7 +288,9 @@ class TestRouteCommand if ($result->isFound()) { echo "Match Found!" . PHP_EOL; - echo "Route: " . $result->getRoute()->getName() . " [" . $result->getRoute()->getMethod() . " " . $result->getRoute()->getPath() . "]" . PHP_EOL; + echo "Route: " . $result->getRoute()->getName() . " [" . + $result->getRoute()->getMethod() . " " . + $result->getRoute()->getPath() . "]" . PHP_EOL; echo "Parameters: " . json_encode($result->getParameters()) . PHP_EOL; exit(0); } else { diff --git a/src/Router/ModuleLoader.php b/src/Router/ModuleLoader.php index f5f1cbe..e8ab443 100644 --- a/src/Router/ModuleLoader.php +++ b/src/Router/ModuleLoader.php @@ -61,8 +61,11 @@ class ModuleLoader * @param string|null $moduleName Optional module name * @return void */ - private function loadModuleRoutes(string $routesFile, string|null $prefix = null, string|null $moduleName = null): void - { + private function loadModuleRoutes( + string $routesFile, + string|null $prefix = null, + string|null $moduleName = null + ): void { $moduleRoutes = require $routesFile; $options = []; diff --git a/src/Router/RouteGroup.php b/src/Router/RouteGroup.php index 94fb507..e24f776 100644 --- a/src/Router/RouteGroup.php +++ b/src/Router/RouteGroup.php @@ -41,7 +41,15 @@ class RouteGroup $defaults = $this->options['defaults'] ?? []; if ($this->router) { - return $this->router->registerCustomRoute('GET', $fullPath, $handler, $name, $middleware, $validation, $defaults); + return $this->router->registerCustomRoute( + 'GET', + $fullPath, + $handler, + $name, + $middleware, + $validation, + $defaults + ); } return new RouteDefinition('GET', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults); @@ -55,7 +63,15 @@ class RouteGroup $defaults = $this->options['defaults'] ?? []; if ($this->router) { - return $this->router->registerCustomRoute('POST', $fullPath, $handler, $name, $middleware, $validation, $defaults); + return $this->router->registerCustomRoute( + 'POST', + $fullPath, + $handler, + $name, + $middleware, + $validation, + $defaults + ); } return new RouteDefinition('POST', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults); @@ -69,7 +85,15 @@ class RouteGroup $defaults = $this->options['defaults'] ?? []; if ($this->router) { - return $this->router->registerCustomRoute('PUT', $fullPath, $handler, $name, $middleware, $validation, $defaults); + return $this->router->registerCustomRoute( + 'PUT', + $fullPath, + $handler, + $name, + $middleware, + $validation, + $defaults + ); } return new RouteDefinition('PUT', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults); @@ -83,7 +107,15 @@ class RouteGroup $defaults = $this->options['defaults'] ?? []; if ($this->router) { - return $this->router->registerCustomRoute('PATCH', $fullPath, $handler, $name, $middleware, $validation, $defaults); + return $this->router->registerCustomRoute( + 'PATCH', + $fullPath, + $handler, + $name, + $middleware, + $validation, + $defaults + ); } return new RouteDefinition('PATCH', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults); @@ -97,10 +129,27 @@ class RouteGroup $defaults = $this->options['defaults'] ?? []; if ($this->router) { - return $this->router->registerCustomRoute('DELETE', $fullPath, $handler, $name, $middleware, $validation, $defaults); + return $this->router->registerCustomRoute( + 'DELETE', + $fullPath, + $handler, + $name, + $middleware, + $validation, + $defaults + ); } - return new RouteDefinition('DELETE', $fullPath, $fullPath, $handler, $name, $middleware, $validation, $defaults); + return new RouteDefinition( + 'DELETE', + $fullPath, + $fullPath, + $handler, + $name, + $middleware, + $validation, + $defaults + ); } public function redirect(string $path, string $destination, int $status = 302): RouteDefinition @@ -111,10 +160,27 @@ class RouteGroup $defaults = $this->options['defaults'] ?? []; if ($this->router) { - return $this->router->registerCustomRoute('REDIRECT', $fullPath, $destination, null, $middleware, $validation, $defaults)->attr('status', $status); + return $this->router->registerCustomRoute( + 'REDIRECT', + $fullPath, + $destination, + null, + $middleware, + $validation, + $defaults + )->attr('status', $status); } - return (new RouteDefinition('REDIRECT', $fullPath, $fullPath, $destination, null, $middleware, $validation, $defaults))->attr('status', $status); + return (new RouteDefinition( + 'REDIRECT', + $fullPath, + $fullPath, + $destination, + null, + $middleware, + $validation, + $defaults + ))->attr('status', $status); } public function fallback(mixed $handler): self @@ -125,7 +191,13 @@ class RouteGroup $middleware = $this->options['middleware'] ?? []; if ($this->router) { - $this->router->registerCustomRoute('FALLBACK', $this->joinPaths($prefix, '/_fallback'), $handler, null, $middleware) + $this->router->registerCustomRoute( + 'FALLBACK', + $this->joinPaths($prefix, '/_fallback'), + $handler, + null, + $middleware + ) ->attr('_fallback', $handler) ->attr('_fallback_prefix', $this->normalizePath($prefix)); } @@ -133,8 +205,15 @@ class RouteGroup return $this; } - public function registerCustomRoute(string $method, string $path, mixed $handler, string|null $name = null, array $middleware = [], array $validation = [], array $defaults = []): RouteDefinition - { + public function registerCustomRoute( + string $method, + string $path, + mixed $handler, + string|null $name = null, + array $middleware = [], + array $validation = [], + array $defaults = [] + ): RouteDefinition { $fullPath = $this->buildFullPath($path); $mergedMiddleware = array_merge($this->options['middleware'] ?? [], $middleware); diff --git a/src/Router/RouteMatcher.php b/src/Router/RouteMatcher.php index f0335d4..ac82ee2 100644 --- a/src/Router/RouteMatcher.php +++ b/src/Router/RouteMatcher.php @@ -112,8 +112,14 @@ class RouteMatcher * @param array $attributes Extracted attributes * @return bool */ - private function isMatch(string $method, string $path, string $host, RouteDefinition $route, array &$attributes, ?string $overridePath = null): bool - { + private function isMatch( + string $method, + string $path, + string $host, + RouteDefinition $route, + array &$attributes, + ?string $overridePath = null + ): bool { $routeMethod = strtoupper($route->getMethod()); if ($routeMethod !== $method && $routeMethod !== 'REDIRECT') { return false; @@ -128,7 +134,9 @@ class RouteMatcher } } - $pattern = $overridePath ? $this->compilePatternFromPath($overridePath, $route) : $this->getPatternForRoute($route); + $pattern = $overridePath + ? $this->compilePatternFromPath($overridePath, $route) + : $this->getPatternForRoute($route); if (preg_match($pattern, $path, $matches)) { $attributes = array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY); @@ -175,33 +183,36 @@ class RouteMatcher $validation = $route->getValidation(); $defaults = $route->getDefaults(); - // Replace {{param?}} and {{param}} with regex - $pattern = preg_replace_callback('#/\{\{([a-zA-Z0-9_]+)(\?)?\}\}#', function ($matches) use ($validation, $defaults) { - $name = $matches[1]; - $optional = (isset($matches[2]) && $matches[2] === '?') || array_key_exists($name, $defaults); + $pattern = preg_replace_callback( + '#/\{\{([a-zA-Z0-9_]+)(\?)?\}\}#', + function ($matches) use ($validation, $defaults) { + $name = $matches[1]; + $optional = (isset($matches[2]) && $matches[2] === '?') || array_key_exists($name, $defaults); - $rules = $validation[$name] ?? []; - $regex = '[^/]+'; + $rules = $validation[$name] ?? []; + $regex = '[^/]+'; - // Validation rules support - foreach ((array)$rules as $rule) { - if ($rule === 'numeric' || $rule === 'int') { - $regex = '[0-9]+'; - } elseif ($rule === 'alpha') { - $regex = '[a-zA-Z]+'; - } elseif ($rule === 'alphanumeric') { - $regex = '[a-zA-Z0-9]+'; - } elseif (str_starts_with($rule, 'regex:')) { - $regex = substr($rule, 6); + // Validation rules support + foreach ((array)$rules as $rule) { + if ($rule === 'numeric' || $rule === 'int') { + $regex = '[0-9]+'; + } elseif ($rule === 'alpha') { + $regex = '[a-zA-Z]+'; + } elseif ($rule === 'alphanumeric') { + $regex = '[a-zA-Z0-9]+'; + } elseif (str_starts_with($rule, 'regex:')) { + $regex = substr($rule, 6); + } } - } - if ($optional) { - return '(?:/(?P<' . $name . '>' . $regex . '))?'; - } + if ($optional) { + return '(?:/(?P<' . $name . '>' . $regex . '))?'; + } - return '/(?P<' . $name . '>' . $regex . ')'; - }, $path); + return '/(?P<' . $name . '>' . $regex . ')'; + }, + $path + ); $pattern = str_replace('//', '/', $pattern); @@ -215,8 +226,10 @@ class RouteMatcher * @param array $attributes * @return RouteDefinition */ - private function applyAttributes(RouteDefinition $route, array $attributes): RouteDefinition - { + private function applyAttributes( + RouteDefinition $route, + array $attributes + ): RouteDefinition { $data = $route->toArray(); $data['attributes'] = array_merge($data['attributes'], $attributes); diff --git a/src/Router/Router.php b/src/Router/Router.php index 998e84c..d5ad9f9 100644 --- a/src/Router/Router.php +++ b/src/Router/Router.php @@ -49,13 +49,27 @@ class Router return $this->registerRoute('DELETE', $path, $handler, $name); } - public function registerCustomRoute(string $method, string $path, mixed $handler, string|null $name = null, array $middleware = [], array $validation = [], array $defaults = []): RouteDefinition - { + public function registerCustomRoute( + string $method, + string $path, + mixed $handler, + string|null $name = null, + array $middleware = [], + array $validation = [], + array $defaults = [] + ): RouteDefinition { return $this->registerRoute($method, $path, $handler, $name, $middleware, $validation, $defaults); } - private function registerRoute(string $method, string $path, mixed $handler, string|null $name = null, array $middleware = [], array $validation = [], array $defaults = []): RouteDefinition - { + private function registerRoute( + string $method, + string $path, + mixed $handler, + string|null $name = null, + array $middleware = [], + array $validation = [], + array $defaults = [] + ): RouteDefinition { $normalizedPath = $this->normalizePath($path); $routeDefinition = new RouteDefinition( $method, @@ -211,7 +225,9 @@ class Router } elseif ($isOptional[$index] === '?') { $path = str_replace($pattern, '', $path); } else { - throw new \InvalidArgumentException(sprintf('Missing required parameter "%s" for route URL generation', $name)); + throw new \InvalidArgumentException( + sprintf('Missing required parameter "%s" for route URL generation', $name) + ); } }