hydephp / develop

The HydePHP Source Code Monorepo
https://hydephp.com
MIT License
12 stars 6 forks source link

Simplify Routes facade methods #1743

Open caendesilva opened 3 weeks ago

caendesilva commented 3 weeks ago

Wondering if we should take more steps to normalize the API, and match to Laravel. I'm not sure if there is ever really a reason to want a null return here, I think if you don't want to catch an exception, it's better to use Routes::exists to check first. See https://github.com/hydephp/develop/pull/591 which was closed due to similar motivations

Originally posted by @caendesilva in https://github.com/hydephp/develop/issues/1731#issuecomment-2196324574

caendesilva commented 3 weeks ago

The current methods as follows:

public static function get(string $routeKey): ?Route
{
    return static::getFacadeRoot()->get($routeKey);
}

/** @throws \Hyde\Framework\Exceptions\RouteNotFoundException */
public static function getOrFail(string $routeKey): Route
{
    return static::getFacadeRoot()->getRoute($routeKey);
}

Could be merged and simplified like this:

public static function get(string $routeKey): Route
{
    return static::getFacadeRoot()->getRoute($routeKey);
}

Considering this is quite a BC break for quite a small thing, we would need to carefully consider this