Skip to content

Commit

Permalink
refactor(router): readability and type hints
Browse files Browse the repository at this point in the history
Signed-off-by: Josh <josh.t.richards@gmail.com>
  • Loading branch information
joshtrichards authored Sep 24, 2024
1 parent 7406869 commit 3fec581
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
*
* @return string[]
*/
public function getRoutingFiles() {
public function getRoutingFiles(): string[] {

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected '[', expecting ';' or '{' on line 82
if ($this->routingFiles === null) {
$this->routingFiles = [];
foreach (\OC_APP::getEnabledApps() as $app) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
Expand All @@ -206,7 +206,7 @@ public function useCollection($name) {
*
* @return string the collection name
*/
public function getCurrentCollection() {
public function getCurrentCollection(): string {
return $this->collectionName;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();

Expand All @@ -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';
Expand Down

0 comments on commit 3fec581

Please sign in to comment.