| @@ -36,7 +36,7 @@ | ||
| 36 | 36 |      { | 
| 37 | 37 |          if (count($uriParameters) > 0) { | 
| 38 | 38 |              foreach ($uriParameters as $key => $value) { | 
| 39 | -                $pattern = preg_replace('/{'.$key.'(.*?)}/msi', $value, $pattern); | |
| 39 | +                $pattern = preg_replace('/{' . $key . '(.*?)}/msi', $value, $pattern); | |
| 40 | 40 | } | 
| 41 | 41 | } | 
| 42 | 42 | return $pattern; | 
| @@ -39,7 +39,7 @@ discard block | ||
| 39 | 39 | |
| 40 | 40 | private static $dispatchResults = [ | 
| 41 | 41 | FastRoute\Dispatcher::METHOD_NOT_ALLOWED => 405, | 
| 42 | - FastRoute\Dispatcher::FOUND => 200 , | |
| 42 | + FastRoute\Dispatcher::FOUND => 200, | |
| 43 | 43 | FastRoute\Dispatcher::NOT_FOUND => 404 | 
| 44 | 44 | ]; | 
| 45 | 45 | |
| @@ -97,10 +97,10 @@ discard block | ||
| 97 | 97 | */ | 
| 98 | 98 | private function addRoutes(FastRoute\RouteCollector $route) : void | 
| 99 | 99 |      { | 
| 100 | - $routeIndex=0; | |
| 100 | + $routeIndex = 0; | |
| 101 | 101 |          foreach ($this->routes as $definedRoute) { | 
| 102 | 102 | $definedRoute[3] = $definedRoute[3] ?? $this->defaultReturnType; | 
| 103 | - $routeName = 'routeClosure'.$routeIndex; | |
| 103 | + $routeName = 'routeClosure' . $routeIndex; | |
| 104 | 104 | $route->addRoute(strtoupper($definedRoute[0]), $definedRoute[1], $routeName); | 
| 105 | 105 | $routeIndex++; | 
| 106 | 106 | } | 
| @@ -108,12 +108,12 @@ discard block | ||
| 108 | 108 | |
| 109 | 109 | private function setRouteClosures() : void | 
| 110 | 110 |      { | 
| 111 | - $routeIndex=0; | |
| 111 | + $routeIndex = 0; | |
| 112 | 112 |          foreach ($this->routes as $definedRoute) { | 
| 113 | 113 | $definedRoute[3] = $definedRoute[3] ?? $this->defaultReturnType; | 
| 114 | - $routeName = 'routeClosure'.$routeIndex; | |
| 115 | -            $this->routerClosures[$routeName]= function ($uriArguments) use ($definedRoute) { | |
| 116 | - $returnType = ($definedRoute[3] >=1 && $definedRoute[3] <=7) ? $definedRoute[3] | |
| 114 | + $routeName = 'routeClosure' . $routeIndex; | |
| 115 | +            $this->routerClosures[$routeName] = function($uriArguments) use ($definedRoute) { | |
| 116 | + $returnType = ($definedRoute[3] >= 1 && $definedRoute[3] <= 7) ? $definedRoute[3] | |
| 117 | 117 | : $this->defaultReturnType; | 
| 118 | 118 | return [ | 
| 119 | 119 | 'status' => 200, | 
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 |      { | 
| 139 | 139 |          if ($routeInfo[0] === FastRoute\Dispatcher::FOUND) { | 
| 140 | 140 | [$dispatcher, $handler, $vars] = $routeInfo; | 
| 141 | - $routeParameters = $this->routerClosures[$handler]($vars); | |
| 141 | + $routeParameters = $this->routerClosures[$handler]($vars); | |
| 142 | 142 | return new Route( | 
| 143 | 143 | $routeParameters['requestMethod'], | 
| 144 | 144 | $routeParameters['pattern'], | 
| @@ -43,6 +43,9 @@ discard block | ||
| 43 | 43 | FastRoute\Dispatcher::NOT_FOUND => 404 | 
| 44 | 44 | ]; | 
| 45 | 45 | |
| 46 | + /** | |
| 47 | + * @param null|string $cacheFile | |
| 48 | + */ | |
| 46 | 49 | public function __construct(array $routes, int $defaultReturnType, ?string $cacheFile) | 
| 47 | 50 |      { | 
| 48 | 51 | $this->routes = $routes; | 
| @@ -71,6 +74,9 @@ discard block | ||
| 71 | 74 | return new FastRoute\Dispatcher\GroupCountBased($routeCollector->getData()); | 
| 72 | 75 | } | 
| 73 | 76 | |
| 77 | + /** | |
| 78 | + * @param FastRoute\RouteCollector $routeCollector | |
| 79 | + */ | |
| 74 | 80 | private function createCachedRoute($routeCollector) : void | 
| 75 | 81 |      { | 
| 76 | 82 |          if ($this->cacheFile !== null && !file_exists($this->cacheFile)) { | 
| @@ -153,6 +153,9 @@ | ||
| 153 | 153 | return $requestPath; | 
| 154 | 154 | } | 
| 155 | 155 | |
| 156 | + /** | |
| 157 | + * @param string $requestMethods | |
| 158 | + */ | |
| 156 | 159 | public function add( | 
| 157 | 160 | $requestMethods, | 
| 158 | 161 | string $route, | 
| @@ -10,7 +10,7 @@ discard block | ||
| 10 | 10 | * @link https://github.com/selamiphp/router | 
| 11 | 11 | */ | 
| 12 | 12 | |
| 13 | -declare(strict_types = 1); | |
| 13 | +declare(strict_types=1); | |
| 14 | 14 | |
| 15 | 15 | namespace Selami\Router; | 
| 16 | 16 | |
| @@ -116,7 +116,7 @@ discard block | ||
| 116 | 116 | } | 
| 117 | 117 | $this->method = $method; | 
| 118 | 118 | $this->requestedPath = rtrim($requestedPath, '/'); | 
| 119 | - $this->defaultReturnType = ($defaultReturnType >=1 && $defaultReturnType <=7) ? $defaultReturnType : self::HTML; | |
| 119 | + $this->defaultReturnType = ($defaultReturnType >= 1 && $defaultReturnType <= 7) ? $defaultReturnType : self::HTML; | |
| 120 | 120 | } | 
| 121 | 121 | |
| 122 | 122 | public static function createWithServerRequestInterface(int $defaultReturnType, ServerRequestInterface $request) | 
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | return $new; | 
| 139 | 139 | } | 
| 140 | 140 | |
| 141 | - public function withCacheFile(?string $fileName=null) : self | |
| 141 | + public function withCacheFile(?string $fileName = null) : self | |
| 142 | 142 |      { | 
| 143 | 143 | $new = clone $this; | 
| 144 | 144 | $new->cacheFile = $fileName; | 
| @@ -196,7 +196,7 @@ discard block | ||
| 196 | 196 |          if ($returnType === null) { | 
| 197 | 197 | return $this->defaultReturnType; | 
| 198 | 198 | } | 
| 199 | - return ($returnType >=1 && $returnType <=7) ? $returnType : self::HTML; | |
| 199 | + return ($returnType >= 1 && $returnType <= 7) ? $returnType : self::HTML; | |
| 200 | 200 | } | 
| 201 | 201 | |
| 202 | 202 | private function checkRequestMethodIsValid(string $requestMethod) : void |