diff --git a/src/Exceptions/NotRoutableException.php b/src/Exceptions/NotRoutableException.php deleted file mode 100644 index bee462c..0000000 --- a/src/Exceptions/NotRoutableException.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Chevere\Router\Exceptions; - -use Chevere\Throwable\Exception; - -/** - * Exception thrown when a route can't be routed. - */ -final class NotRoutableException extends Exception -{ -} diff --git a/src/Router.php b/src/Router.php index 37f7165..0812920 100644 --- a/src/Router.php +++ b/src/Router.php @@ -14,15 +14,12 @@ namespace Chevere\Router; use Chevere\Message\Message; -use Chevere\Router\Exceptions\NotRoutableException; use Chevere\Router\Exceptions\WithoutEndpointsException; use Chevere\Router\Interfaces\IndexInterface; use Chevere\Router\Interfaces\RouteInterface; use Chevere\Router\Interfaces\RouterInterface; use Chevere\Router\Interfaces\RoutesInterface; use Chevere\Router\Parsers\StrictStd; -use Chevere\VariableSupport\Exceptions\UnableToStoreException; -use Chevere\VariableSupport\StorableVariable; use FastRoute\DataGenerator\GroupCountBased; use FastRoute\RouteCollector; @@ -43,7 +40,7 @@ public function __construct() public function withAddedRoute(string $group, RouteInterface $route): RouterInterface { - $this->assertRoute($route); + $this->assertHasEndpoints($route); $new = clone $this; $new->index = $new->index->withAddedRoute($route, $group); $new->routes = $new->routes->withAdded($route); @@ -73,19 +70,16 @@ public function routeCollector(): RouteCollector return $this->routeCollector; } - private function assertRoute(RouteInterface $route): void + private function assertHasEndpoints(RouteInterface $route): void { - try { - (new StorableVariable($route))->toExport(); - } catch (UnableToStoreException $e) { - throw new NotRoutableException(previous: $e); - } - if ($route->endpoints()->count() === 0) { - throw new WithoutEndpointsException( - (new Message("Route %name% (%path%) doesn't contain any endpoint.")) - ->withCode('%path%', $route->path()->__toString()) - ->withCode('%name%', $route->name()) - ); + if ($route->endpoints()->count() > 0) { + return; } + + throw new WithoutEndpointsException( + (new Message("Route %name% (%path%) doesn't contain any endpoint.")) + ->withCode('%path%', $route->path()->__toString()) + ->withCode('%name%', $route->name()) + ); } } diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 5255f98..c9a47fc 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -15,11 +15,9 @@ use Chevere\Http\Methods\GetMethod; use Chevere\Router\Endpoint; -use Chevere\Router\Exceptions\NotRoutableException; use Chevere\Router\Exceptions\WithoutEndpointsException; use function Chevere\Router\route; use Chevere\Router\Router; -use Chevere\Router\Tests\_resources\TestControllerNotExportable; use Chevere\Router\Tests\_resources\TestControllerWithParameters; use FastRoute\RouteCollector; use PHPUnit\Framework\TestCase; @@ -75,12 +73,4 @@ public function testConstructInvalidArgument(): void (new Router()) ->withAddedRoute('my-group', $route); } - - public function testNotExportable(): void - { - $route = route('/test', GET: new TestControllerNotExportable()); - $this->expectException(NotRoutableException::class); - (new Router()) - ->withAddedRoute('my-group', $route); - } }