diff --git a/system/Router/Attributes/Filter.php b/system/Router/Attributes/Filter.php index 130d2946f0dc..edba9452619e 100644 --- a/system/Router/Attributes/Filter.php +++ b/system/Router/Attributes/Filter.php @@ -38,6 +38,9 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] class Filter implements RouteAttributeInterface { + /** + * @param array $having + */ public function __construct( public string $by, public array $having = [], @@ -56,6 +59,9 @@ public function after(RequestInterface $request, ResponseInterface $response): ? return null; } + /** + * @return list + */ public function getFilters(): array { if ($this->having === []) { diff --git a/system/Router/Attributes/Restrict.php b/system/Router/Attributes/Restrict.php index 79344a7c6982..3bf250ab7966 100644 --- a/system/Router/Attributes/Restrict.php +++ b/system/Router/Attributes/Restrict.php @@ -42,6 +42,11 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] class Restrict implements RouteAttributeInterface { + /** + * @param list|string|null $environment + * @param list|string|null $hostname + * @param list|string|null $subdomain + */ public function __construct( public array|string|null $environment = null, public array|string|null $hostname = null, diff --git a/system/Router/AutoRouter.php b/system/Router/AutoRouter.php index 1033478c9e30..e887469b9037 100644 --- a/system/Router/AutoRouter.php +++ b/system/Router/AutoRouter.php @@ -55,14 +55,6 @@ public function __construct( ) { } - /** - * Attempts to match a URI path against Controllers and directories - * found in APPPATH/Controllers, to find a matching route. - * - * @param string $httpVerb HTTP verb like `GET`,`POST` - * - * @return array [directory_name, controller_name, controller_method, params] - */ public function getRoute(string $uri, string $httpVerb): array { $segments = explode('/', $uri); @@ -95,7 +87,7 @@ public function getRoute(string $uri, string $httpVerb): array throw PageNotFoundException::forPageNotFound(); } - /** @var array $params An array of params to the controller method. */ + /** @var list $params An array of params to the controller method. */ $params = []; if ($segments !== []) { @@ -177,11 +169,12 @@ public function setTranslateURIDashes(bool $val = false): self } /** - * Scans the controller directory, attempting to locate a controller matching the supplied uri $segments + * Scans the controller directory, attempting to locate a controller matching the supplied uri `$segments`. + * Returns an array of remaining uri segments that don't map onto a directory. * - * @param array $segments URI segments + * @param list $segments URI segments * - * @return array returns an array of remaining uri segments that don't map onto a directory + * @return list */ private function scanControllers(array $segments): array { diff --git a/system/Router/AutoRouterImproved.php b/system/Router/AutoRouterImproved.php index a00c04d265d7..c7dbf04efec5 100644 --- a/system/Router/AutoRouterImproved.php +++ b/system/Router/AutoRouterImproved.php @@ -63,12 +63,11 @@ final class AutoRouterImproved implements AutoRouterInterface * Map of URI segments and namespaces. * * The key is the first URI segment. The value is the controller namespace. - * E.g., - * [ - * 'blog' => 'Acme\Blog\Controllers', - * ] + * ``` + * ['blog' => 'Acme\Blog\Controllers'] + * ``` * - * @var array [ uri_segment => namespace ] + * @var array */ private array $moduleRoutes; @@ -133,6 +132,9 @@ public function __construct( $this->controller = $this->defaultController; } + /** + * @return list + */ private function createSegments(string $uri): array { $segments = explode('/', $uri); @@ -250,13 +252,6 @@ private function searchLastDefaultController(): bool return false; } - /** - * Finds controller, method and params from the URI. - * - * @param string $httpVerb HTTP verb like `GET`,`POST` - * - * @return array [directory_name, controller_name, controller_method, params] - */ public function getRoute(string $uri, string $httpVerb): array { $this->uri = $uri; diff --git a/system/Router/AutoRouterInterface.php b/system/Router/AutoRouterInterface.php index 7edec821dbfd..58f22393881e 100644 --- a/system/Router/AutoRouterInterface.php +++ b/system/Router/AutoRouterInterface.php @@ -19,9 +19,11 @@ interface AutoRouterInterface { /** - * Returns controller, method and params from the URI. + * Returns the directory name, controller name, controller method, and any parameters for the given URI and HTTP verb. * - * @return array [directory_name, controller_name, controller_method, params] + * @param string $httpVerb HTTP verb like `GET`,`POST` + * + * @return array{string|null, string, string, list} */ public function getRoute(string $uri, string $httpVerb): array; } diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 6dfb42286972..b5bd4ee76597 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -96,6 +96,8 @@ class RouteCollection implements RouteCollectionInterface /** * An array of files that would contain route definitions. + * + * @var list */ protected array $routeFiles = []; @@ -116,9 +118,7 @@ class RouteCollection implements RouteCollectionInterface /** * An array of all routes and their mappings. - * - * @var array - * + *``` * [ * verb => [ * routeKey(regex) => [ @@ -137,6 +137,9 @@ class RouteCollection implements RouteCollectionInterface * ], * ], * ] + * ``` + * + * @var array>> */ protected $routes = [ '*' => [], @@ -154,14 +157,11 @@ class RouteCollection implements RouteCollectionInterface /** * Array of routes names + * ``` + * [verb => [routeName => routeKey(regex)]] + * ``` * - * @var array - * - * [ - * verb => [ - * routeName => routeKey(regex) - * ], - * ] + * @var array> */ protected $routesNames = [ '*' => [], @@ -179,9 +179,7 @@ class RouteCollection implements RouteCollectionInterface /** * Array of routes options - * - * @var array - * + * ``` * [ * verb => [ * routeKey(regex) => [ @@ -189,6 +187,9 @@ class RouteCollection implements RouteCollectionInterface * ] * ], * ] + * ``` + * + * @var array>> */ protected $routesOptions = []; @@ -225,7 +226,7 @@ class RouteCollection implements RouteCollectionInterface * Stores copy of current options being * applied during creation. * - * @var array|null + * @var array|null */ protected $currentOptions; @@ -376,16 +377,6 @@ protected function discoverRoutes() $this->didDiscover = true; } - /** - * Registers a new constraint with the system. Constraints are used - * by the routes as placeholders for regular expressions to make defining - * the routes more human-friendly. - * - * You can pass an associative array as $placeholder, and have - * multiple placeholders added at once. - * - * @param array|string $placeholder - */ public function addPlaceholder($placeholder, ?string $pattern = null): RouteCollectionInterface { if (! is_array($placeholder)) { @@ -409,10 +400,6 @@ public function getPlaceholders(): array return $this->placeholders; } - /** - * Sets the default namespace to use for Controllers when no other - * namespace has been specified. - */ public function setDefaultNamespace(string $value): RouteCollectionInterface { $this->defaultNamespace = esc(strip_tags($value)); @@ -421,10 +408,6 @@ public function setDefaultNamespace(string $value): RouteCollectionInterface return $this; } - /** - * Sets the default controller to use when no other controller has been - * specified. - */ public function setDefaultController(string $value): RouteCollectionInterface { $this->defaultController = esc(strip_tags($value)); @@ -432,10 +415,6 @@ public function setDefaultController(string $value): RouteCollectionInterface return $this; } - /** - * Sets the default method to call on the controller when no other - * method has been set in the route. - */ public function setDefaultMethod(string $value): RouteCollectionInterface { $this->defaultMethod = esc(strip_tags($value)); @@ -443,13 +422,6 @@ public function setDefaultMethod(string $value): RouteCollectionInterface return $this; } - /** - * Tells the system whether to convert dashes in URI strings into - * underscores. In some search engines, including Google, dashes - * create more meaning and make it easier for the search engine to - * find words and meaning in the URI for better SEO. But it - * doesn't work well with PHP method names.... - */ public function setTranslateURIDashes(bool $value): RouteCollectionInterface { $this->translateURIDashes = $value; @@ -457,14 +429,6 @@ public function setTranslateURIDashes(bool $value): RouteCollectionInterface return $this; } - /** - * If TRUE, the system will attempt to match the URI against - * Controllers by matching each segment against folders/files - * in APPPATH/Controllers, when a match wasn't found against - * defined routes. - * - * If FALSE, will stop searching and do NO automatic routing. - */ public function setAutoRoute(bool $value): RouteCollectionInterface { $this->autoRoute = $value; @@ -472,15 +436,6 @@ public function setAutoRoute(bool $value): RouteCollectionInterface return $this; } - /** - * Sets the class/method that should be called if routing doesn't - * find a match. It can be either a closure or the controller/method - * name exactly like a route is defined: Users::index - * - * This setting is passed to the Router class and handled there. - * - * @param (callable(string): (ResponseInterface|string|void))|string|null $callable - */ public function set404Override($callable = null): RouteCollectionInterface { $this->override404 = $callable; @@ -488,12 +443,6 @@ public function set404Override($callable = null): RouteCollectionInterface return $this; } - /** - * Returns the 404 Override setting, which can be null, a closure - * or the controller/string. - * - * @return (Closure(string): (ResponseInterface|string|void))|string|null - */ public function get404Override() { return $this->override404; @@ -512,52 +461,31 @@ public function setDefaultConstraint(string $placeholder): RouteCollectionInterf return $this; } - /** - * Returns the name of the default controller. With Namespace. - */ public function getDefaultController(): string { return $this->defaultController; } - /** - * Returns the name of the default method to use within the controller. - */ public function getDefaultMethod(): string { return $this->defaultMethod; } - /** - * Returns the default namespace as set in the Routes config file. - */ public function getDefaultNamespace(): string { return $this->defaultNamespace; } - /** - * Returns the current value of the translateURIDashes setting. - */ public function shouldTranslateURIDashes(): bool { return $this->translateURIDashes; } - /** - * Returns the flag that tells whether to autoRoute URI against Controllers. - */ public function shouldAutoRoute(): bool { return $this->autoRoute; } - /** - * Returns the raw array of available routes. - * - * @param non-empty-string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. - * @param bool $includeWildcard Whether to include '*' routes. - */ public function getRoutes(?string $verb = null, bool $includeWildcard = true): array { if ((string) $verb === '') { @@ -598,13 +526,6 @@ public function getRoutes(?string $verb = null, bool $includeWildcard = true): a return $routes; } - /** - * Returns one or all routes options - * - * @param string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. - * - * @return array [key => value] - */ public function getRoutesOptions(?string $from = null, ?string $verb = null): array { $options = $this->loadRoutesOptions($verb); @@ -612,22 +533,11 @@ public function getRoutesOptions(?string $from = null, ?string $verb = null): ar return ((string) $from !== '') ? $options[$from] ?? [] : $options; } - /** - * Returns the current HTTP Verb being used. - */ public function getHTTPVerb(): string { return $this->HTTPVerb; } - /** - * Sets the current HTTP verb. - * Used primarily for testing. - * - * @param string $verb HTTP verb - * - * @return $this - */ public function setHTTPVerb(string $verb) { if ($verb !== '*' && $verb === strtolower($verb)) { @@ -651,6 +561,9 @@ public function setHTTPVerb(string $verb) * A shortcut method to add a number of routes at a single time. * It does not allow any options to be set on the route, or to * define the method used. + * + * @param array $routes + * @param array|null $options */ public function map(array $routes = [], ?array $options = null): RouteCollectionInterface { @@ -661,14 +574,6 @@ public function map(array $routes = [], ?array $options = null): RouteCollection return $this; } - /** - * Adds a single route to the collection. - * - * Example: - * $routes->add('news', 'Posts::index'); - * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to - */ public function add(string $from, $to, ?array $options = null): RouteCollectionInterface { $this->create('*', $from, $to, $options); @@ -708,11 +613,6 @@ public function addRedirect(string $from, string $to, int $status = 302) return $this; } - /** - * Determines if the route is a redirecting route. - * - * @param string $routeKey routeKey or route name - */ public function isRedirect(string $routeKey): bool { if (isset($this->routes['*'][$routeKey]['redirect'])) { @@ -730,11 +630,6 @@ public function isRedirect(string $routeKey): bool return false; } - /** - * Grabs the HTTP status code from a redirecting Route. - * - * @param string $routeKey routeKey or route name - */ public function getRedirectCode(string $routeKey): int { if (isset($this->routes['*'][$routeKey]['redirect'])) { @@ -762,8 +657,8 @@ public function getRedirectCode(string $routeKey): int * $route->resource('users'); * }); * - * @param string $name The name to group/prefix the routes with. - * @param array|(callable(self): void) ...$params + * @param string $name The name to group/prefix the routes with. + * @param array|(callable(self): void) ...$params * * @return void */ @@ -844,8 +739,8 @@ public function group(string $name, ...$params) * POST /photos/{id}/delete delete * POST /photos/{id} update * - * @param string $name The name of the resource/controller to route to. - * @param array|null $options A list of possible ways to customize the routing. + * @param string $name The name of the resource/controller to route to. + * @param array|null $options A list of possible ways to customize the routing. */ public function resource(string $name, ?array $options = null): RouteCollectionInterface { @@ -938,8 +833,8 @@ public function resource(string $name, ?array $options = null): RouteCollectionI * GET /photos/remove/{id} remove show a form to confirm deletion of a specific photo object * POST /photos/delete/{id} delete deleting the specified photo object * - * @param string $name The name of the controller to route to. - * @param array|null $options A list of possible ways to customize the routing. + * @param string $name The name of the controller to route to. + * @param array|null $options A list of possible ways to customize the routing. */ public function presenter(string $name, ?array $options = null): RouteCollectionInterface { @@ -1013,7 +908,9 @@ public function presenter(string $name, ?array $options = null): RouteCollection * Example: * $route->match( ['GET', 'POST'], 'users/(:num)', 'users/$1); * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param list $verbs + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function match(array $verbs = [], string $from = '', $to = '', ?array $options = null): RouteCollectionInterface { @@ -1045,7 +942,8 @@ public function match(array $verbs = [], string $from = '', $to = '', ?array $op /** * Specifies a route that is only available to GET requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function get(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1057,7 +955,8 @@ public function get(string $from, $to, ?array $options = null): RouteCollectionI /** * Specifies a route that is only available to POST requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function post(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1069,7 +968,8 @@ public function post(string $from, $to, ?array $options = null): RouteCollection /** * Specifies a route that is only available to PUT requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function put(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1081,7 +981,8 @@ public function put(string $from, $to, ?array $options = null): RouteCollectionI /** * Specifies a route that is only available to DELETE requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function delete(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1093,7 +994,8 @@ public function delete(string $from, $to, ?array $options = null): RouteCollecti /** * Specifies a route that is only available to HEAD requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function head(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1105,7 +1007,8 @@ public function head(string $from, $to, ?array $options = null): RouteCollection /** * Specifies a route that is only available to PATCH requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function patch(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1117,7 +1020,8 @@ public function patch(string $from, $to, ?array $options = null): RouteCollectio /** * Specifies a route that is only available to OPTIONS requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function options(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1129,7 +1033,8 @@ public function options(string $from, $to, ?array $options = null): RouteCollect /** * Specifies a route that is only available to command-line requests. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options */ public function cli(string $from, $to, ?array $options = null): RouteCollectionInterface { @@ -1141,6 +1046,8 @@ public function cli(string $from, $to, ?array $options = null): RouteCollectionI /** * Specifies a route that will only display a view. * Only works for GET requests. + * + * @param array|null $options */ public function view(string $from, string $view, ?array $options = null): RouteCollectionInterface { @@ -1170,25 +1077,6 @@ public function environment(string $env, Closure $callback): RouteCollectionInte return $this; } - /** - * Attempts to look up a route based on its destination. - * - * If a route exists: - * - * 'path/(:any)/(:any)' => 'Controller::method/$1/$2' - * - * This method allows you to know the Controller and method - * and get the route that leads to it. - * - * // Equals 'path/$param1/$param2' - * reverseRoute('Controller::method', $param1, $param2); - * - * @param string $search Route name or Controller::method - * @param int|string ...$params One or more parameters to be passed to the route. - * The last parameter allows you to set the locale. - * - * @return false|string The route (URI path relative to baseURL) or false if not found. - */ public function reverseRoute(string $search, ...$params) { if ($search === '') { @@ -1262,11 +1150,6 @@ protected function localizeRoute(string $route): string return strtr($route, ['{locale}' => service('request')->getLocale()]); } - /** - * Checks a route (using the "from") to see if it's filtered or not. - * - * @param string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. - */ public function isFiltered(string $search, ?string $verb = null): bool { $options = $this->loadRoutesOptions($verb); @@ -1274,21 +1157,6 @@ public function isFiltered(string $search, ?string $verb = null): bool return isset($options[$search]['filter']); } - /** - * Returns the filters that should be applied for a single route, along - * with any parameters it might have. Parameters are found by splitting - * the parameter name on a colon to separate the filter name from the parameter list, - * and the splitting the result on commas. So: - * - * 'role:admin,manager' - * - * has a filter of "role", with parameters of ['admin', 'manager']. - * - * @param string $search routeKey - * @param string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. - * - * @return list filter_name or filter_name:arguments like 'role:admin,manager' - */ public function getFiltersForRoute(string $search, ?string $verb = null): array { $options = $this->loadRoutesOptions($verb); @@ -1307,6 +1175,8 @@ public function getFiltersForRoute(string $search, ?string $verb = null): array /** * Given a * + * @param list|null $params + * * @throws RouterException * * @deprecated Unused. Now uses buildReverseRoute(). @@ -1345,8 +1215,8 @@ protected function fillRouteParams(string $from, ?array $params = null): string /** * Builds reverse route * - * @param array $params One or more parameters to be passed to the route. - * The last parameter allows you to set the locale. + * @param list $params One or more parameters to be passed to the route. + * The last parameter allows you to set the locale. */ protected function buildReverseRoute(string $from, array $params): string { @@ -1435,7 +1305,8 @@ private function replaceLocale(string $route, ?string $locale = null): string * the request method(s) that this route will work for. They can be separated * by a pipe character "|" if there is more than one. * - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to + * @param array|null $options * * @return void */ @@ -1582,6 +1453,9 @@ private function checkHostname($hostname): bool return strtolower($this->httpHost) === strtolower($hostname); } + /** + * @param array $to + */ private function processArrayCallableSyntax(string $from, array $to): string { // [classname, method] @@ -1797,9 +1671,6 @@ public function useSupportedLocalesOnly(bool $useOnly): self return $this; } - /** - * Get the flag that limit or not the routes with {locale} placeholder to App::$supportedLocales - */ public function shouldUseSupportedLocalesOnly(): bool { return $this->useSupportedLocalesOnly; diff --git a/system/Router/RouteCollectionInterface.php b/system/Router/RouteCollectionInterface.php index 10587d81ee4c..e3c83955e28f 100644 --- a/system/Router/RouteCollectionInterface.php +++ b/system/Router/RouteCollectionInterface.php @@ -28,9 +28,12 @@ interface RouteCollectionInterface /** * Adds a single route to the collection. * - * @param string $from The route path (with placeholders or regex) - * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to The route handler - * @param array|null $options The route options + * Example: + * $routes->add('news', 'Posts::index'); + * + * @param string $from The route path (with placeholders or regex) + * @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to The route handler + * @param array|null $options The route options * * @return RouteCollectionInterface */ @@ -44,8 +47,8 @@ public function add(string $from, $to, ?array $options = null); * You can pass an associative array as $placeholder, and have * multiple placeholders added at once. * - * @param array|string $placeholder - * @param string|null $pattern The regex pattern + * @param array|string $placeholder + * @param string|null $pattern The regex pattern * * @return RouteCollectionInterface */ @@ -177,6 +180,8 @@ public function shouldAutoRoute(); * * @param non-empty-string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. * @param bool $includeWildcard Whether to include '*' routes. + * + * @return array|(Closure(mixed...): (ResponseInterface|string|void))|string> */ public function getRoutes(?string $verb = null, bool $includeWildcard = true): array; @@ -192,6 +197,7 @@ public function getRoutesOptions(?string $from = null, ?string $verb = null): ar /** * Sets the current HTTP verb. + * Used primarily for testing. * * @param string $verb HTTP verb * @@ -219,8 +225,9 @@ public function getHTTPVerb(); * // Equals 'path/$param1/$param2' * reverseRoute('Controller::method', $param1, $param2); * - * @param string $search Named route or Controller::method - * @param int|string ...$params + * @param string $search Route name or Controller::method + * @param int|string ...$params One or more parameters to be passed to the route. + * The last parameter allows you to set the locale. * * @return false|string The route (URI path relative to baseURL) or false if not found. */ diff --git a/system/Router/Router.php b/system/Router/Router.php index c886bf45f396..6e5a4630832b 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -86,7 +86,7 @@ class Router implements RouterInterface * An array of binds that were collected * so they can be sent to closure routes. * - * @var array + * @var list */ protected $params = []; @@ -108,14 +108,14 @@ class Router implements RouterInterface /** * The route that was matched for this request. * - * @var array|null + * @var array{string, (callable(mixed...): (ResponseInterface|string|void))|string}|null */ protected $matchedRoute; /** * The options set for the matched route. * - * @var array|null + * @var array|null */ protected $matchedRouteOptions; @@ -346,7 +346,7 @@ public function directory(): string * Returns the routing information that was matched for this * request, if a route was defined. * - * @return array|null + * @return array{string, (callable(mixed...): (ResponseInterface|string|void))|string}|null */ public function getMatchedRoute() { @@ -356,7 +356,7 @@ public function getMatchedRoute() /** * Returns all options set for the matched route * - * @return array|null + * @return array|null */ public function getMatchedRouteOptions() { @@ -562,6 +562,8 @@ protected function checkRoutes(string $uri): bool /** * Replace string `$n` with `$matches[n]` value. + * + * @param list $matches */ private function replaceBackReferences(string $input, array $matches): string { @@ -595,9 +597,9 @@ public function autoRoute(string $uri) /** * Scans the controller directory, attempting to locate a controller matching the supplied uri $segments * - * @param array $segments URI segments + * @param list $segments URI segments * - * @return array returns an array of remaining uri segments that don't map onto a directory + * @return list Returns an array of remaining uri segments that don't map onto a directory * * @deprecated this function name does not properly describe its behavior so it has been deprecated * @@ -611,9 +613,9 @@ protected function validateRequest(array $segments): array /** * Scans the controller directory, attempting to locate a controller matching the supplied uri $segments * - * @param array $segments URI segments + * @param list $segments URI segments * - * @return array returns an array of remaining uri segments that don't map onto a directory + * @return list Returns an array of remaining uri segments that don't map onto a directory * * @deprecated Not used. Moved to AutoRouter class. */ diff --git a/system/Router/RouterInterface.php b/system/Router/RouterInterface.php index c50de86d43df..05dd2caf279e 100644 --- a/system/Router/RouterInterface.php +++ b/system/Router/RouterInterface.php @@ -55,7 +55,7 @@ public function methodName(); * during the parsing process as an array, ready to send to * instance->method(...$params). * - * @return array + * @return list */ public function params(); diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 6346697d206a..bf35a3f6fe63 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -196,13 +196,13 @@ public function testMatchIgnoresInvalidHTTPMethods(): void $this->assertSame([], $routes); } - public function testAddWorksWithArrayOFHTTPMethods(): void + public function testAddWorksWithArrayOfHTTPMethods(): void { service('request')->setMethod(Method::POST); $routes = $this->getCollector(); - $routes->add('home', 'controller', ['get', 'post']); + $routes->add('home', 'controller'); $expects = [ 'home' => '\controller', diff --git a/utils/phpstan-baseline/argument.type.neon b/utils/phpstan-baseline/argument.type.neon index 80cb40694994..cf3e3ef1668f 100644 --- a/utils/phpstan-baseline/argument.type.neon +++ b/utils/phpstan-baseline/argument.type.neon @@ -23,22 +23,22 @@ parameters: path: ../../system/Database/SQLite3/Builder.php - - message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: CodeIgniter\\HTTP\\ResponseInterface given\.$#' + message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: CodeIgniter\\HTTP\\ResponseInterface given\.$#' count: 1 path: ../../tests/system/CodeIgniterTest.php - - message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: \(CodeIgniter\\HTTP\\DownloadResponse\|null\) given\.$#' + message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: \(CodeIgniter\\HTTP\\DownloadResponse\|null\) given\.$#' count: 1 path: ../../tests/system/CodeIgniterTest.php - - message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: non\-falsy\-string given\.$#' + message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: non\-falsy\-string given\.$#' count: 1 path: ../../tests/system/CodeIgniterTest.php - - message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: void given\.$#' + message: '#^Parameter \#2 \$to of method CodeIgniter\\Router\\RouteCollection\:\:add\(\) expects array\\|\(Closure\(mixed \.\.\.\)\: \(CodeIgniter\\HTTP\\ResponseInterface\|string\|void\)\)\|string, Closure\(mixed\)\: void given\.$#' count: 1 path: ../../tests/system/CodeIgniterTest.php diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 57a1c5ee9257..e3c0dd86de6a 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1381 errors +# total 1313 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 518e931c13d8..e68d43283b54 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1129 errors +# total 1061 errors parameters: ignoreErrors: @@ -3287,346 +3287,6 @@ parameters: count: 1 path: ../../system/Publisher/Publisher.php - - - message: '#^Method CodeIgniter\\Router\\Attributes\\Filter\:\:__construct\(\) has parameter \$having with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Attributes/Filter.php - - - - message: '#^Method CodeIgniter\\Router\\Attributes\\Filter\:\:getFilters\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Attributes/Filter.php - - - - message: '#^Method CodeIgniter\\Router\\Attributes\\Restrict\:\:__construct\(\) has parameter \$environment with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Attributes/Restrict.php - - - - message: '#^Method CodeIgniter\\Router\\Attributes\\Restrict\:\:__construct\(\) has parameter \$hostname with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Attributes/Restrict.php - - - - message: '#^Method CodeIgniter\\Router\\Attributes\\Restrict\:\:__construct\(\) has parameter \$subdomain with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Attributes/Restrict.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouter\:\:getRoute\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouter.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouter\:\:scanControllers\(\) has parameter \$segments with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouter.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouter\:\:scanControllers\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouter.php - - - - message: '#^PHPDoc tag @var for variable \$params has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouter.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouterImproved\:\:createSegments\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouterImproved.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouterImproved\:\:getRoute\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouterImproved.php - - - - message: '#^Property CodeIgniter\\Router\\AutoRouterImproved\:\:\$moduleRoutes type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouterImproved.php - - - - message: '#^Method CodeIgniter\\Router\\AutoRouterInterface\:\:getRoute\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/AutoRouterInterface.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:addPlaceholder\(\) has parameter \$placeholder with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:add\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:add\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:buildReverseRoute\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:cli\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:cli\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:create\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:create\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:delete\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:delete\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:fillRouteParams\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:getRoutes\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:get\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:get\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:group\(\) has parameter \$params with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:head\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:head\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:map\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:map\(\) has parameter \$routes with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:match\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:match\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:match\(\) has parameter \$verbs with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:options\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:options\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:patch\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:patch\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:post\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:post\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:presenter\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:processArrayCallableSyntax\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:put\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:put\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:resource\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollection\:\:view\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Property CodeIgniter\\Router\\RouteCollection\:\:\$currentOptions type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Property CodeIgniter\\Router\\RouteCollection\:\:\$routeFiles type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Property CodeIgniter\\Router\\RouteCollection\:\:\$routes type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Property CodeIgniter\\Router\\RouteCollection\:\:\$routesNames type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Property CodeIgniter\\Router\\RouteCollection\:\:\$routesOptions type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollection.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionInterface\:\:addPlaceholder\(\) has parameter \$placeholder with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollectionInterface.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionInterface\:\:add\(\) has parameter \$options with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollectionInterface.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionInterface\:\:add\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollectionInterface.php - - - - message: '#^Method CodeIgniter\\Router\\RouteCollectionInterface\:\:getRoutes\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouteCollectionInterface.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:getMatchedRouteOptions\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:getMatchedRoute\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:params\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:replaceBackReferences\(\) has parameter \$matches with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:scanControllers\(\) has parameter \$segments with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:scanControllers\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:validateRequest\(\) has parameter \$segments with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\Router\:\:validateRequest\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Property CodeIgniter\\Router\\Router\:\:\$matchedRoute type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Property CodeIgniter\\Router\\Router\:\:\$matchedRouteOptions type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Property CodeIgniter\\Router\\Router\:\:\$params type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/Router.php - - - - message: '#^Method CodeIgniter\\Router\\RouterInterface\:\:params\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Router/RouterInterface.php - - message: '#^Method CodeIgniter\\Test\\Constraints\\SeeInDatabase\:\:__construct\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1