Skip to content

Commit

Permalink
bump php version requirement to 7.0 and add types on all methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Oct 9, 2023
1 parent 77a2e14 commit 4270bb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions AltoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -61,7 +61,7 @@ public function __construct(array $routes = [], $basePath = '', array $matchType
* Useful if you want to process or display routes.
* @return array All routes.
*/
public function getRoutes()
public function getRoutes(): array
{
return $this->routes;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function addRoutes($routes)
* 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;
}
Expand All @@ -117,7 +117,7 @@ public function addMatchTypes(array $matchTypes)
* @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];
Expand All @@ -128,8 +128,6 @@ public function map($method, $route, $target, $name = null)
}
$this->namedRoutes[$name] = $route;
}

return;
}

/**
Expand All @@ -138,11 +136,11 @@ public function map($method, $route, $target, $name = null)
* 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
Expand Down Expand Up @@ -186,7 +184,7 @@ public function generate($routeName, array $params = [])
* @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 = [];
Expand Down Expand Up @@ -264,10 +262,10 @@ public function match($requestUrl = null, $requestMethod = null)

/**
* 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;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "9.6.*",
Expand Down

0 comments on commit 4270bb5

Please sign in to comment.