From 5bc9a72e363626ea1b27acdf566e90e3590bddb5 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 24 Jan 2024 18:45:36 +0300 Subject: [PATCH] Add URL arguments' psalm type in `UrlGeneratorInterface` (#229) * Add URL arguments' psalm type in `UrlGeneratorInterface` * improve --- CHANGELOG.md | 1 + src/UrlGeneratorInterface.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eafa70..1af9672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Chg #207: Replace two `RouteCollectorInterface` methods `addRoute()` and `addGroup()` to single `addRoute()` (@vjik) - Enh #202: Add support for `psr/http-message` version `^2.0` (@vjik) - Chg #222: Make `Route`, `Group` and `MatchingResult` dispatcher-independent (@rustamwin, @vjik) +- Enh #229: Add URL arguments' psalm type in `UrlGeneratorInterface` (@vjik) ## 3.0.0 February 17, 2023 diff --git a/src/UrlGeneratorInterface.php b/src/UrlGeneratorInterface.php index 214e891..94c3045 100644 --- a/src/UrlGeneratorInterface.php +++ b/src/UrlGeneratorInterface.php @@ -8,6 +8,8 @@ /** * `UrlGeneratorInterface` allows generating URL given route name, arguments, and query parameters. + * + * @psalm-type UrlArgumentsType = array */ interface UrlGeneratorInterface { @@ -15,12 +17,14 @@ interface UrlGeneratorInterface * Generates URL from named route, arguments, and query parameters. * * @param string $name Name of the route. - * @param array $arguments Argument-value set. + * @param array $arguments Argument-value set. * @param array $queryParameters Parameter-value set. * * @throws RouteNotFoundException In case there is no route with the name specified. * * @return string URL generated. + * + * @psalm-param UrlArgumentsType $arguments */ public function generate(string $name, array $arguments = [], array $queryParameters = []): string; @@ -28,7 +32,7 @@ public function generate(string $name, array $arguments = [], array $queryParame * Generates absolute URL from named route, arguments, and query parameters. * * @param string $name Name of the route. - * @param array $arguments Argument-value set. + * @param array $arguments Argument-value set. * @param array $queryParameters Parameter-value set. * @param string|null $scheme Host scheme. * @param string|null $host Host for manual setup. @@ -36,6 +40,8 @@ public function generate(string $name, array $arguments = [], array $queryParame * @throws RouteNotFoundException In case there is no route with the name specified. * * @return string URL generated. + * + * @psalm-param UrlArgumentsType $arguments */ public function generateAbsolute( string $name, @@ -48,11 +54,12 @@ public function generateAbsolute( /** * Generate URL from the current route replacing some of its arguments with values specified. * - * @param array $replacedArguments New argument values indexed by replaced argument - * names. + * @param array $replacedArguments New argument values indexed by replaced argument names. * @param array $queryParameters Parameter-value set. * @param string|null $fallbackRouteName Name of a route that should be used if current route. * can not be determined. + * + * @psalm-param UrlArgumentsType $replacedArguments */ public function generateFromCurrent( array $replacedArguments,