Skip to content

Commit

Permalink
Few small tweaks, using qualified function references.
Browse files Browse the repository at this point in the history
  • Loading branch information
Saeven committed May 24, 2018
1 parent 051e351 commit 069b72f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/CirclicalAutoWire/Service/RouterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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']);
Expand Down

0 comments on commit 069b72f

Please sign in to comment.