Skip to content

Commit 283e744

Browse files
committed
refactor: by rector
1 parent 329d4ea commit 283e744

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

system/Router/AutoRouterImproved.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,12 @@ public function getRoute(string $uri): array
238238
'Cannot access the default method "' . $this->method . '" with the method name URI path.'
239239
);
240240
}
241+
} elseif (method_exists($this->controller, $this->defaultMethod)) {
242+
// The default method is found.
243+
$this->method = $this->defaultMethod;
241244
} else {
242-
if (method_exists($this->controller, $this->defaultMethod)) {
243-
// The default method is found.
244-
$this->method = $this->defaultMethod;
245-
} else {
246-
// No method is found.
247-
throw PageNotFoundException::forControllerNotFound($this->controller, $method);
248-
}
245+
// No method is found.
246+
throw PageNotFoundException::forControllerNotFound($this->controller, $method);
249247
}
250248

251249
// Ensure the controller is not defined in routes.

tests/system/Router/AutoRouterImprovedTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function testAutoRouteFallbackToDefaultControllerOneParam()
221221
= $router->getRoute('subfolder/15');
222222

223223
$this->assertSame('Subfolder/', $directory);
224-
$this->assertSame('\CodeIgniter\Router\Controllers\Subfolder\Home', $controller);
224+
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Home::class, $controller);
225225
$this->assertSame('getIndex', $method);
226226
$this->assertSame(['15'], $params);
227227
}
@@ -234,7 +234,7 @@ public function testAutoRouteFallbackToDefaultControllerTwoParams()
234234
= $router->getRoute('subfolder/15/20');
235235

236236
$this->assertSame('Subfolder/', $directory);
237-
$this->assertSame('\CodeIgniter\Router\Controllers\Subfolder\Home', $controller);
237+
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Home::class, $controller);
238238
$this->assertSame('getIndex', $method);
239239
$this->assertSame(['15', '20'], $params);
240240
}
@@ -247,7 +247,7 @@ public function testAutoRouteFallbackToDefaultControllerNoParams()
247247
= $router->getRoute('subfolder');
248248

249249
$this->assertSame('Subfolder/', $directory);
250-
$this->assertSame('\CodeIgniter\Router\Controllers\Subfolder\Home', $controller);
250+
$this->assertSame('\\' . \CodeIgniter\Router\Controllers\Subfolder\Home::class, $controller);
251251
$this->assertSame('getIndex', $method);
252252
$this->assertSame([], $params);
253253
}

0 commit comments

Comments
 (0)