From 069b72f403a00e3133387b7918934b6d6dfbc5ce Mon Sep 17 00:00:00 2001 From: Alexandre Lemaire Date: Thu, 24 May 2018 13:38:44 -0400 Subject: [PATCH] Few small tweaks, using qualified function references. --- src/CirclicalAutoWire/Service/RouterService.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CirclicalAutoWire/Service/RouterService.php b/src/CirclicalAutoWire/Service/RouterService.php index 5b0028f..c540c30 100644 --- a/src/CirclicalAutoWire/Service/RouterService.php +++ b/src/CirclicalAutoWire/Service/RouterService.php @@ -16,19 +16,19 @@ */ final class RouterService { + public static $routesParsed = 0; + private $router; private $reader; - public static $routesParsed = 0; - private $productionMode; private $annotations; public function __construct(TreeRouteStack $router, bool $productionMode) { - AnnotationRegistry::registerAutoloadNamespace("CirclicalAutoWire\\Annotations", realpath(__DIR__ . "/../../")); + AnnotationRegistry::registerAutoloadNamespace("CirclicalAutoWire\\Annotations", \dirname(__DIR__, 2) . '/'); $this->router = $router; $this->reader = new AnnotationReader(); $this->productionMode = $productionMode; @@ -52,6 +52,8 @@ public function getAnnotations(): array * Parse a controller, storing results into the 'annotations' class variable * * @param string $controllerClass + * + * @throws \ReflectionException */ public function parseController(string $controllerClass) { @@ -63,7 +65,7 @@ public function parseController(string $controllerClass) /** @var \ReflectionMethod $method */ foreach ($class->getMethods() as $method) { - if ($method->getDeclaringClass()->getName() == $controllerClass) { + if ($method->getDeclaringClass()->getName() === $controllerClass) { $set = $this->reader->getMethodAnnotations($method); /** @var Route $routerAnnotation */ foreach ($set as $routerAnnotation) { @@ -106,7 +108,7 @@ public function compile(): array } $parentRoute = $routes[$baseRouteName]; - for ($i = 0; $i < count($routePath) - 1; $i++) { + for ($i = 0; $i < \count($routePath) - 1; $i++) { $parentRoute = $parentRoute->getChild($routePath[$i]); } $parentRoute->addChild(end($routePath), $annotatedRoute); @@ -124,7 +126,7 @@ public function compile(): array // Sort them Segment first, Literal last (for LIFO) and by length uasort($routeConfig, function (array $a, array $b) { if ($a['type'] === $b['type']) { - return strlen($a['options']['route']) - strlen($b['options']['route']); + return \strlen($a['options']['route']) - \strlen($b['options']['route']); } return -1 * ($a['type'] <=> $b['type']);