From 52ba64ff85be4f027cb823af5f524132926029ca Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 25 Jan 2017 03:08:50 +0100 Subject: [PATCH] removed useless type juggling and checking --- src/Application/Application.php | 2 +- src/Application/PresenterFactory.php | 2 +- src/Application/Request.php | 2 +- src/Application/Responses/RedirectResponse.php | 4 ++-- src/Application/UI/Component.php | 2 +- src/Application/UI/Control.php | 7 +------ src/Application/UI/Presenter.php | 6 +++--- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index ad4327d31..eaa719bd2 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -105,7 +105,7 @@ public function run(): void public function createInitialRequest(): Request { $request = $this->router->match($this->httpRequest); - if (!$request instanceof Request) { + if (!$request) { throw new BadRequestException('No route for HTTP request.'); } return $request; diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index cf93ecdc8..8def0e2e1 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -63,7 +63,7 @@ public function getPresenterClass(string &$name): string return $this->cache[$name]; } - if (!is_string($name) || !Nette\Utils\Strings::match($name, '#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*\z#')) { + if (!Nette\Utils\Strings::match($name, '#^[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff:]*\z#')) { throw new InvalidPresenterException("Presenter name must be alphanumeric string, '$name' is invalid."); } diff --git a/src/Application/Request.php b/src/Application/Request.php index c41198799..86574704c 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -199,7 +199,7 @@ public function isMethod(string $method): bool */ public function setFlag(string $flag, bool $value = TRUE) { - $this->flags[$flag] = (bool) $value; + $this->flags[$flag] = $value; return $this; } diff --git a/src/Application/Responses/RedirectResponse.php b/src/Application/Responses/RedirectResponse.php index e7d664738..349d6c188 100644 --- a/src/Application/Responses/RedirectResponse.php +++ b/src/Application/Responses/RedirectResponse.php @@ -33,8 +33,8 @@ class RedirectResponse implements Nette\Application\IResponse */ public function __construct(string $url, int $code = Http\IResponse::S302_FOUND) { - $this->url = (string) $url; - $this->code = (int) $code; + $this->url = $url; + $this->code = $code; } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index d565dfda1..348adeade 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -78,7 +78,7 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void protected function tryCall(string $method, array $params): bool { $rc = $this->getReflection(); - if ($rc->hasMethod((string) $method)) { + if ($rc->hasMethod($method)) { $rm = $rc->getMethod($method); if ($rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic()) { $this->checkRequirements($rm); diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index 50b9afc38..82bb960fe 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -44,12 +44,7 @@ public function setTemplateFactory(ITemplateFactory $templateFactory) public function getTemplate(): ITemplate { if ($this->template === NULL) { - $value = $this->createTemplate(); - if (!$value instanceof ITemplate && $value !== NULL) { - $class2 = get_class($value); $class = get_class($this); - throw new Nette\UnexpectedValueException("Object returned by $class::createTemplate() must be instance of Nette\\Application\\UI\\ITemplate, '$class2' given."); - } - $this->template = $value; + $this->template = $this->createTemplate(); } return $this->template; } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 7594dce3f..b78997a02 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -372,7 +372,7 @@ public function getAction(bool $fullyQualified = FALSE): string */ public function changeAction(string $action): void { - if (is_string($action) && Nette\Utils\Strings::match($action, '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*\z#')) { + if (Nette\Utils\Strings::match($action, '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*\z#')) { $this->action = $action; $this->view = $action; } else { @@ -396,7 +396,7 @@ public function getView(): string */ public function setView(string $view) { - $this->view = (string) $view; + $this->view = $view; return $this; } @@ -629,7 +629,7 @@ public function forward($destination, $args = []): void public function redirectUrl(string $url, int $code = NULL): void { if ($this->isAjax()) { - $this->payload->redirect = (string) $url; + $this->payload->redirect = $url; $this->sendPayload(); } elseif (!$code) {