From 3fec5814c75b709f2d36cdd4a47e8ab6c9e8ec4e Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 24 Sep 2024 17:21:29 -0400 Subject: [PATCH] refactor(router): readability and type hints Signed-off-by: Josh --- lib/private/Route/Router.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index 7ec2aac021caa..e42d6750fdfcd 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -79,7 +79,7 @@ public function __construct( * * @return string[] */ - public function getRoutingFiles() { + public function getRoutingFiles(): string[] { if ($this->routingFiles === null) { $this->routingFiles = []; foreach (\OC_APP::getEnabledApps() as $app) { @@ -102,7 +102,7 @@ public function getRoutingFiles() { * * @param null|string $app */ - public function loadRoutes($app = null) { + public function loadRoutes(?string $app = null): ?string { if (is_string($app)) { $app = $this->appManager->cleanAppId($app); } @@ -183,7 +183,7 @@ public function loadRoutes($app = null) { * @param string $name * @return \Symfony\Component\Routing\RouteCollection */ - protected function getCollection($name) { + protected function getCollection(string $name): \Symfony\Component\Routing\RouteCollection { if (!isset($this->collections[$name])) { $this->collections[$name] = new RouteCollection(); } @@ -196,7 +196,7 @@ protected function getCollection($name) { * @param string $name Name of the collection to use. * @return void */ - public function useCollection($name) { + public function useCollection(string $name): void { $this->collection = $this->getCollection($name); $this->collectionName = $name; } @@ -206,7 +206,7 @@ public function useCollection($name) { * * @return string the collection name */ - public function getCurrentCollection() { + public function getCurrentCollection(): string { return $this->collectionName; } @@ -220,10 +220,7 @@ public function getCurrentCollection() { * @param array $requirements An array of requirements for parameters (regexes) * @return \OC\Route\Route */ - public function create($name, - $pattern, - array $defaults = [], - array $requirements = []) { + public function create(string $name, string $pattern, array $defaults = [], array $requirements = []): \OC\Route\Route { $route = new Route($pattern, $defaults, $requirements); $this->collection->add($name, $route); return $route; @@ -294,7 +291,7 @@ public function findMatchingRoute(string $url): array { * @throws \Exception * @return void */ - public function match($url) { + public function match(string $url): void { $parameters = $this->findMatchingRoute($url); $this->eventLogger->start('route:run', 'Run route'); @@ -328,7 +325,7 @@ public function match($url) { * @return \Symfony\Component\Routing\Generator\UrlGenerator * */ - public function getGenerator() { + public function getGenerator(): \Symfony\Component\Routing\Generator\UrlGenerator { if ($this->generator !== null) { return $this->generator; } @@ -344,9 +341,7 @@ public function getGenerator() { * @param bool $absolute * @return string */ - public function generate($name, - $parameters = [], - $absolute = false) { + public function generate(string $name, array $parameters = [], bool $absolute = false): string { $referenceType = UrlGenerator::ABSOLUTE_URL; if ($absolute === false) { $referenceType = UrlGenerator::ABSOLUTE_PATH; @@ -482,7 +477,7 @@ private function getAttributeRoutes(string $app): array { * @param string $file the route file location to include * @param string $appName */ - private function requireRouteFile($file, $appName) { + private function requireRouteFile(string $file, string $appName): void { $this->setupRoutes(include_once $file, $appName); } @@ -498,7 +493,7 @@ private function requireRouteFile($file, $appName) { * @param array $routes the application routes * @param string $appName the name of the app. */ - private function setupRoutes($routes, $appName) { + private function setupRoutes(array $routes, string $appName): void { if (is_array($routes)) { $routeParser = new RouteParser(); @@ -511,7 +506,7 @@ private function setupRoutes($routes, $appName) { } } - private function getApplicationClass(string $appName) { + private function getApplicationClass(string $appName): mixed { $appNameSpace = App::buildAppNamespace($appName); $applicationClassName = $appNameSpace . '\\AppInfo\\Application';