Merge pull request #524 from skipperbent/v4-cleanup

[CLEANUP] Cleaned up code
This commit is contained in:
Simon Sessingø
2021-03-29 00:07:12 +02:00
committed by GitHub
16 changed files with 72 additions and 72 deletions
+2 -2
View File
@@ -291,7 +291,7 @@ class Request
* Will try to find first header from list of headers. * Will try to find first header from list of headers.
* *
* @param array $headers * @param array $headers
* @param null $defaultValue * @param mixed|null $defaultValue
* @return mixed|null * @return mixed|null
*/ */
public function getFirstHeader(array $headers, $defaultValue = null) public function getFirstHeader(array $headers, $defaultValue = null)
@@ -534,7 +534,7 @@ class Request
return $this; return $this;
} }
public function __isset($name) public function __isset($name): bool
{ {
return array_key_exists($name, $this->data) === true; return array_key_exists($name, $this->data) === true;
} }
@@ -16,7 +16,7 @@ class ClassLoader implements IClassLoader
public function loadClass(string $class) public function loadClass(string $class)
{ {
if (class_exists($class) === false) { if (class_exists($class) === false) {
throw new ClassNotFoundHttpException(sprintf('Class "%s" does not exist', $class), 404, null, $class); throw new ClassNotFoundHttpException($class, null, sprintf('Class "%s" does not exist', $class), 404, null);
} }
return new $class(); return new $class();
@@ -34,4 +34,4 @@ class ClassLoader implements IClassLoader
return \call_user_func_array($closure, $parameters); return \call_user_func_array($closure, $parameters);
} }
} }
@@ -83,7 +83,7 @@ class EventArgument implements IEventArgument
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function __isset(string $name) public function __isset(string $name): bool
{ {
return array_key_exists($name, $this->arguments); return array_key_exists($name, $this->arguments);
} }
@@ -9,7 +9,7 @@ class ClassNotFoundHttpException extends NotFoundHttpException
protected $class; protected $class;
protected $method; protected $method;
public function __construct($message = "", $code = 0, Throwable $previous = null, string $class, ?string $method = null) public function __construct(string $class, ?string $method = null, $message = "", $code = 0, Throwable $previous = null)
{ {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
+1 -1
View File
@@ -29,7 +29,7 @@ interface IGroupRoute extends IRoute
* @param array $handlers * @param array $handlers
* @return static * @return static
*/ */
public function setExceptionHandlers(array $handlers); public function setExceptionHandlers(array $handlers): self;
/** /**
* Get exception-handlers for group * Get exception-handlers for group
@@ -82,6 +82,6 @@ interface ILoadableRoute extends IRoute
* @param string $regex * @param string $regex
* @return static * @return static
*/ */
public function setMatch($regex): self; public function setMatch(string $regex): self;
} }
+4 -4
View File
@@ -10,11 +10,11 @@ interface IRoute
/** /**
* Method called to check if a domain matches * Method called to check if a domain matches
* *
* @param string $route * @param string $url
* @param Request $request * @param Request $request
* @return bool * @return bool
*/ */
public function matchRoute($route, Request $request): bool; public function matchRoute(string $url, Request $request): bool;
/** /**
* Called when route is matched. * Called when route is matched.
@@ -129,7 +129,7 @@ interface IRoute
* @param string $namespace * @param string $namespace
* @return static * @return static
*/ */
public function setDefaultNamespace($namespace): IRoute; public function setDefaultNamespace(string $namespace): IRoute;
/** /**
* Get default namespace * Get default namespace
@@ -196,7 +196,7 @@ interface IRoute
* @param string $middleware * @param string $middleware
* @return static * @return static
*/ */
public function addMiddleware($middleware): self; public function addMiddleware(string $middleware): self;
/** /**
* Set middlewares array * Set middlewares array
@@ -183,7 +183,7 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
* @param string $regex * @param string $regex
* @return static * @return static
*/ */
public function setMatch($regex): ILoadableRoute public function setMatch(string $regex): ILoadableRoute
{ {
$this->regex = $regex; $this->regex = $regex;
@@ -229,15 +229,15 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
/** /**
* Merge with information from another route. * Merge with information from another route.
* *
* @param array $values * @param array $settings
* @param bool $merge * @param bool $merge
* @return static * @return static
*/ */
public function setSettings(array $values, bool $merge = false): IRoute public function setSettings(array $settings, bool $merge = false): IRoute
{ {
if (isset($values['as']) === true) { if (isset($settings['as']) === true) {
$name = $values['as']; $name = $settings['as'];
if ($this->name !== null && $merge !== false) { if ($this->name !== null && $merge !== false) {
$name .= '.' . $this->name; $name .= '.' . $this->name;
@@ -246,11 +246,11 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
$this->setName($name); $this->setName($name);
} }
if (isset($values['prefix']) === true) { if (isset($settings['prefix']) === true) {
$this->prependUrl($values['prefix']); $this->prependUrl($settings['prefix']);
} }
return parent::setSettings($values, $merge); return parent::setSettings($settings, $merge);
} }
} }
+21 -21
View File
@@ -95,7 +95,7 @@ abstract class Route implements IRoute
} }
if (method_exists($class, $method) === false) { if (method_exists($class, $method) === false) {
throw new ClassNotFoundHttpException(sprintf('Method "%s" does not exist in class "%s"', $method, $className), 404, null, $className, $method); throw new ClassNotFoundHttpException($className, $method, sprintf('Method "%s" does not exist in class "%s"', $method, $className), 404, null);
} }
$router->debug('Executing callback'); $router->debug('Executing callback');
@@ -327,7 +327,7 @@ abstract class Route implements IRoute
* @param string $namespace * @param string $namespace
* @return static * @return static
*/ */
public function setDefaultNamespace($namespace): IRoute public function setDefaultNamespace(string $namespace): IRoute
{ {
$this->defaultNamespace = $namespace; $this->defaultNamespace = $namespace;
@@ -382,35 +382,35 @@ abstract class Route implements IRoute
/** /**
* Merge with information from another route. * Merge with information from another route.
* *
* @param array $values * @param array $settings
* @param bool $merge * @param bool $merge
* @return static * @return static
*/ */
public function setSettings(array $values, bool $merge = false): IRoute public function setSettings(array $settings, bool $merge = false): IRoute
{ {
if ($this->namespace === null && isset($values['namespace']) === true) { if ($this->namespace === null && isset($settings['namespace']) === true) {
$this->setNamespace($values['namespace']); $this->setNamespace($settings['namespace']);
} }
if (isset($values['method']) === true) { if (isset($settings['method']) === true) {
$this->setRequestMethods(array_merge($this->requestMethods, (array)$values['method'])); $this->setRequestMethods(array_merge($this->requestMethods, (array)$settings['method']));
} }
if (isset($values['where']) === true) { if (isset($settings['where']) === true) {
$this->setWhere(array_merge($this->where, (array)$values['where'])); $this->setWhere(array_merge($this->where, (array)$settings['where']));
} }
if (isset($values['parameters']) === true) { if (isset($settings['parameters']) === true) {
$this->setParameters(array_merge($this->parameters, (array)$values['parameters'])); $this->setParameters(array_merge($this->parameters, (array)$settings['parameters']));
} }
// Push middleware if multiple // Push middleware if multiple
if (isset($values['middleware']) === true) { if (isset($settings['middleware']) === true) {
$this->setMiddlewares(array_merge((array)$values['middleware'], $this->middlewares)); $this->setMiddlewares(array_merge((array)$settings['middleware'], $this->middlewares));
} }
if (isset($values['defaultParameterRegex']) === true) { if (isset($settings['defaultParameterRegex']) === true) {
$this->setDefaultParameterRegex($values['defaultParameterRegex']); $this->setDefaultParameterRegex($settings['defaultParameterRegex']);
} }
return $this; return $this;
@@ -493,11 +493,11 @@ abstract class Route implements IRoute
/** /**
* Add middleware class-name * Add middleware class-name
* *
* @param IMiddleware|string $middleware * @param string $middleware
* @return static * @return static
* @deprecated This method is deprecated and will be removed in the near future. * @deprecated This method is deprecated and will be removed in the near future.
*/ */
public function setMiddleware($middleware) public function setMiddleware(string $middleware): self
{ {
$this->middlewares[] = $middleware; $this->middlewares[] = $middleware;
@@ -507,10 +507,10 @@ abstract class Route implements IRoute
/** /**
* Add middleware class-name * Add middleware class-name
* *
* @param IMiddleware|string $middleware * @param string $middleware
* @return static * @return static
*/ */
public function addMiddleware($middleware): IRoute public function addMiddleware(string $middleware): IRoute
{ {
$this->middlewares[] = $middleware; $this->middlewares[] = $middleware;
@@ -545,7 +545,7 @@ abstract class Route implements IRoute
* @param string $regex * @param string $regex
* @return static * @return static
*/ */
public function setDefaultParameterRegex($regex) public function setDefaultParameterRegex(string $regex): self
{ {
$this->defaultParameterRegex = $regex; $this->defaultParameterRegex = $regex;
@@ -86,7 +86,7 @@ class RouteController extends LoadableRoute implements IControllerRoute
return '/' . trim($url, '/') . '/'; return '/' . trim($url, '/') . '/';
} }
public function matchRoute($url, Request $request): bool public function matchRoute(string $url, Request $request): bool
{ {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) { if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false; return false;
@@ -167,17 +167,17 @@ class RouteController extends LoadableRoute implements IControllerRoute
/** /**
* Merge with information from another route. * Merge with information from another route.
* *
* @param array $values * @param array $settings
* @param bool $merge * @param bool $merge
* @return static * @return static
*/ */
public function setSettings(array $values, bool $merge = false): IRoute public function setSettings(array $settings, bool $merge = false): IRoute
{ {
if (isset($values['names']) === true) { if (isset($settings['names']) === true) {
$this->names = $values['names']; $this->names = $settings['names'];
} }
return parent::setSettings($values, $merge); return parent::setSettings($settings, $merge);
} }
} }
+12 -12
View File
@@ -49,7 +49,7 @@ class RouteGroup extends Route implements IGroupRoute
* @param Request $request * @param Request $request
* @return bool * @return bool
*/ */
public function matchRoute($url, Request $request): bool public function matchRoute(string $url, Request $request): bool
{ {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) { if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false; return false;
@@ -154,28 +154,28 @@ class RouteGroup extends Route implements IGroupRoute
/** /**
* Merge with information from another route. * Merge with information from another route.
* *
* @param array $values * @param array $settings
* @param bool $merge * @param bool $merge
* @return static * @return static
*/ */
public function setSettings(array $values, bool $merge = false): IRoute public function setSettings(array $settings, bool $merge = false): IRoute
{ {
if (isset($values['prefix']) === true) { if (isset($settings['prefix']) === true) {
$this->setPrefix($values['prefix'] . $this->prefix); $this->setPrefix($settings['prefix'] . $this->prefix);
} }
if ($merge === false && isset($values['exceptionHandler']) === true) { if ($merge === false && isset($settings['exceptionHandler']) === true) {
$this->setExceptionHandlers((array)$values['exceptionHandler']); $this->setExceptionHandlers((array)$settings['exceptionHandler']);
} }
if ($merge === false && isset($values['domain']) === true) { if ($merge === false && isset($settings['domain']) === true) {
$this->setDomains((array)$values['domain']); $this->setDomains((array)$settings['domain']);
} }
if (isset($values['as']) === true) { if (isset($settings['as']) === true) {
$name = $values['as']; $name = $settings['as'];
if ($this->name !== null && $merge !== false) { if ($this->name !== null && $merge !== false) {
$name .= '.' . $this->name; $name .= '.' . $this->name;
@@ -184,7 +184,7 @@ class RouteGroup extends Route implements IGroupRoute
$this->name = $name; $this->name = $name;
} }
return parent::setSettings($values, $merge); return parent::setSettings($settings, $merge);
} }
/** /**
@@ -22,7 +22,7 @@ class RoutePartialGroup extends RouteGroup implements IPartialGroupRoute
* @param Request $request * @param Request $request
* @return bool * @return bool
*/ */
public function matchRoute($url, Request $request): bool public function matchRoute(string $url, Request $request): bool
{ {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) { if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false; return false;
@@ -83,7 +83,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
return true; return true;
} }
public function matchRoute($url, Request $request): bool public function matchRoute(string $url, Request $request): bool
{ {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) { if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false; return false;
@@ -210,21 +210,21 @@ class RouteResource extends LoadableRoute implements IControllerRoute
/** /**
* Merge with information from another route. * Merge with information from another route.
* *
* @param array $values * @param array $settings
* @param bool $merge * @param bool $merge
* @return static * @return static
*/ */
public function setSettings(array $values, bool $merge = false): IRoute public function setSettings(array $settings, bool $merge = false): IRoute
{ {
if (isset($values['names']) === true) { if (isset($settings['names']) === true) {
$this->names = $values['names']; $this->names = $settings['names'];
} }
if (isset($values['methods']) === true) { if (isset($settings['methods']) === true) {
$this->methodNames = $values['methods']; $this->methodNames = $settings['methods'];
} }
return parent::setSettings($values, $merge); return parent::setSettings($settings, $merge);
} }
} }
+1 -1
View File
@@ -12,7 +12,7 @@ class RouteUrl extends LoadableRoute
$this->setCallback($callback); $this->setCallback($callback);
} }
public function matchRoute($url, Request $request): bool public function matchRoute(string $url, Request $request): bool
{ {
if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) { if ($this->getGroup() !== null && $this->getGroup()->matchRoute($url, $request) === false) {
return false; return false;
+2 -2
View File
@@ -461,7 +461,7 @@ class Router
* @throws HttpException * @throws HttpException
* @throws \Exception * @throws \Exception
*/ */
protected function handleRouteRewrite($key, string $url): ?string protected function handleRouteRewrite(string $key, string $url): ?string
{ {
/* If the request has changed */ /* If the request has changed */
if ($this->request->hasPendingRewrite() === false) { if ($this->request->hasPendingRewrite() === false) {
@@ -874,7 +874,7 @@ class Router
* @param string $name * @param string $name
* @param array $arguments * @param array $arguments
*/ */
protected function fireEvents($name, array $arguments = []): void protected function fireEvents(string $name, array $arguments = []): void
{ {
if (\count($this->eventHandlers) === 0) { if (\count($this->eventHandlers) === 0) {
return; return;
+1 -1
View File
@@ -169,7 +169,7 @@ class SimpleRouter
* @param int $httpCode * @param int $httpCode
* @return IRoute * @return IRoute
*/ */
public static function redirect($where, $to, $httpCode = 301): IRoute public static function redirect(string $where, string $to, int $httpCode = 301): IRoute
{ {
return static::get($where, function () use ($to, $httpCode) { return static::get($where, function () use ($to, $httpCode) {
static::response()->redirect($to, $httpCode); static::response()->redirect($to, $httpCode);