From 4270bb5ca203cd958d4866b797d7bc00e16b4905 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Mon, 9 Oct 2023 20:54:04 +0200 Subject: [PATCH] bump php version requirement to 7.0 and add types on all methods --- AltoRouter.php | 20 +++++++++----------- composer.json | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/AltoRouter.php b/AltoRouter.php index ff33398..b6c36ef 100644 --- a/AltoRouter.php +++ b/AltoRouter.php @@ -49,7 +49,7 @@ class AltoRouter * @param array $matchTypes * @throws Exception */ - public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + public function __construct(array $routes = [], string $basePath = '', array $matchTypes = []) { $this->addRoutes($routes); $this->setBasePath($basePath); @@ -61,7 +61,7 @@ class AltoRouter * Useful if you want to process or display routes. * @return array All routes. */ - public function getRoutes() + public function getRoutes(): array { return $this->routes; } @@ -93,7 +93,7 @@ class AltoRouter * Useful if you are running your application from a subdirectory. * @param string $basePath */ - public function setBasePath($basePath) + public function setBasePath(string $basePath) { $this->basePath = $basePath; } @@ -117,7 +117,7 @@ class AltoRouter * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. * @throws Exception */ - public function map($method, $route, $target, $name = null) + public function map(string $method, string $route, $target, string $name = null) { $this->routes[] = [$method, $route, $target, $name]; @@ -128,8 +128,6 @@ class AltoRouter } $this->namedRoutes[$name] = $route; } - - return; } /** @@ -138,11 +136,11 @@ class AltoRouter * Generate the URL for a named route. Replace regexes with supplied parameters * * @param string $routeName The name of the route. - * @param array @params Associative array of parameters to replace placeholders with. + * @param array $params Associative array of parameters to replace placeholders with. * @return string The URL of the route with named parameters in place. * @throws Exception */ - public function generate($routeName, array $params = []) + public function generate(string $routeName, array $params = []): string { // Check if named route exists @@ -186,7 +184,7 @@ class AltoRouter * @param string $requestMethod * @return array|boolean Array with route information on success, false on failure (no match). */ - public function match($requestUrl = null, $requestMethod = null) + public function match(string $requestUrl = null, string $requestMethod = null) { $params = []; @@ -264,10 +262,10 @@ class AltoRouter /** * Compile the regex for a given route (EXPENSIVE) - * @param $route + * @param string $route * @return string */ - protected function compileRoute($route) + protected function compileRoute(string $route): string { if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { $matchTypes = $this->matchTypes; diff --git a/composer.json b/composer.json index 0a8d2b2..af0baa4 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=5.6.0" + "php": ">=7.0" }, "require-dev": { "phpunit/phpunit": "9.6.*",