From fbb14e2cb61094bdeeb491e8c7f198fb11da6e7e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 9 Sep 2021 18:19:02 +0200 Subject: [PATCH 01/22] Presenter: support for @deprecated in presenters, action & signals --- src/Application/UI/Presenter.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 3f08163e2..f34a5bdb2 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -828,6 +828,12 @@ protected function createRequest( if (!$reflection->hasCallableMethod($method)) { throw new InvalidLinkException("Unknown signal '$signal', missing handler {$reflection->getName()}::$method()"); } + if ( + $this->invalidLinkMode + && ComponentReflection::parseAnnotation(new \ReflectionMethod($component::class, $method), 'deprecated') + ) { + trigger_error("Link to deprecated signal '$signal'" . ($component === $this ? '' : ' in ' . $component::class) . " from '{$this->getName()}:{$this->getAction()}'.", E_USER_DEPRECATED); + } // convert indexed parameters to named static::argsToParams(get_class($component), $method, $args, [], $missing); } @@ -855,6 +861,9 @@ protected function createRequest( $current = ($action === '*' || strcasecmp($action, (string) $this->action) === 0) && $presenterClass === static::class; $reflection = new ComponentReflection($presenterClass); + if ($this->invalidLinkMode && ComponentReflection::parseAnnotation($reflection, 'deprecated')) { + trigger_error("Link to deprecated presenter '$presenter' from '{$this->getName()}:{$this->getAction()}'.", E_USER_DEPRECATED); + } // counterpart of run() & tryCall() $method = $presenterClass::formatActionMethod($action); @@ -871,6 +880,12 @@ protected function createRequest( throw new InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method."); } } else { + if ( + $this->invalidLinkMode + && ComponentReflection::parseAnnotation(new \ReflectionMethod($presenterClass, $method), 'deprecated') + ) { + trigger_error("Link to deprecated action '$presenter:$action' from '{$this->getName()}:{$this->getAction()}'.", E_USER_DEPRECATED); + } static::argsToParams($presenterClass, $method, $args, $path === 'this' ? $this->params : [], $missing); } From c442b0a505e20795e5b0350e51351b0fa2f9cb95 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 10 Sep 2021 19:07:12 +0200 Subject: [PATCH 02/22] UIRuntime: improved {templatePrint} --- src/Bridges/ApplicationLatte/UIRuntime.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Bridges/ApplicationLatte/UIRuntime.php b/src/Bridges/ApplicationLatte/UIRuntime.php index 8a16745c7..1c2562e73 100644 --- a/src/Bridges/ApplicationLatte/UIRuntime.php +++ b/src/Bridges/ApplicationLatte/UIRuntime.php @@ -40,11 +40,8 @@ public static function initialize(Latte\Runtime\Template $template, &$parentName public static function printClass(Latte\Runtime\Template $template, string $parent = null): void { + $blueprint = new Latte\Runtime\Blueprint; $name = 'Template'; - $parent = $parent === 'default' - ? DefaultTemplate::class - : ($parent ?: Template::class); - $params = $template->getParameters(); $control = $params['control'] ?? $params['presenter'] ?? null; if ($control) { @@ -52,20 +49,24 @@ public static function printClass(Latte\Runtime\Template $template, string $pare unset($params[$control instanceof Presenter ? 'control' : 'presenter']); } - if (class_exists($parent)) { - get_class_vars($parent); + if ($parent) { + if (!class_exists($parent)) { + $blueprint->printHeader("{templatePrint}: Class '$parent' doesn't exist."); + return; + } $params = array_diff_key($params, get_class_vars($parent)); } - $funcs = (array) $template->global->fn; + $funcs = array_diff_key((array) $template->global->fn, (new Latte\Runtime\Defaults)->getFunctions()); unset($funcs['isLinkCurrent'], $funcs['isModuleCurrent']); $namespace = new Php\PhpNamespace(Php\Helpers::extractNamespace($name)); $class = $namespace->addClass(Php\Helpers::extractShortName($name)); - $class->setExtends($parent); - $class->addTrait(Nette\SmartObject::class); + $class->setExtends($parent ?: Template::class); + if (!$parent) { + $class->addTrait(Nette\SmartObject::class); + } - $blueprint = new Latte\Runtime\Blueprint; $blueprint->addProperties($class, $params, true); $blueprint->addFunctions($class, $funcs); From 31dacd1203b320ff4ba10fe4d9e10241b5a80284 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Sep 2021 23:38:21 +0200 Subject: [PATCH 03/22] improved phpDoc, used generics --- src/Application/UI/Control.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index bfc307a33..8d37bcdb9 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -52,7 +52,9 @@ final public function getTemplate(): Template /** - * @param string $class + * @template T of Template + * @param class-string $class + * @return T */ protected function createTemplate(/*string $class = null*/): Template { From df816a05cc436832ad5aa318554739700ed623e7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 15:27:18 +0100 Subject: [PATCH 04/22] opened 4.0-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eb1121be2..6213339ca 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } } } From de1ec589b8b0d123cb9e762527a25e096cd56697 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 25 Aug 2021 01:41:02 +0200 Subject: [PATCH 05/22] requires PHP 8.0 --- .github/workflows/coding-style.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- .github/workflows/tests.yml | 6 +++--- composer.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml index aef96a0e4..8b4a2262f 100644 --- a/.github/workflows/coding-style.yml +++ b/.github/workflows/coding-style.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.0 coverage: none - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index b0692d716..f985b0526 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 266902db6..82b6f1861 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1'] + php: ['8.0', '8.1'] fail-fast: false @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.0 coverage: none - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/composer.json b/composer.json index 6213339ca..b78c8e07c 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=8.0 <8.2", "nette/component-model": "^3.0", "nette/http": "^3.0.2", "nette/routing": "^3.0.2", From 60878878239516fe4d43869e80999c48ac3d3657 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 15:56:28 +0100 Subject: [PATCH 06/22] composer: updated dependencies --- composer.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index b78c8e07c..f2242cbfb 100644 --- a/composer.json +++ b/composer.json @@ -16,24 +16,24 @@ ], "require": { "php": ">=8.0 <8.2", - "nette/component-model": "^3.0", - "nette/http": "^3.0.2", - "nette/routing": "^3.0.2", - "nette/utils": "^3.2.1" + "nette/component-model": "^4.0", + "nette/http": "^4.0", + "nette/routing": "^4.0", + "nette/utils": "^3.2.1 || ^4.0" }, "suggest": { "nette/forms": "Allows to use Nette\\Application\\UI\\Form", "latte/latte": "Allows using Latte in templates" }, "require-dev": { - "nette/tester": "^2.3.1", - "nette/di": "^v3.0", - "nette/forms": "^3.0", - "nette/robot-loader": "^3.2", - "nette/security": "^3.0", + "nette/tester": "^2.4", + "nette/di": "^v4.0", + "nette/forms": "^4.0", + "nette/robot-loader": "^3.2 || ^4.0", + "nette/security": "^4.0", "latte/latte": "^2.10.2", - "tracy/tracy": "^2.6", - "mockery/mockery": "^1.0", + "tracy/tracy": "^2.8", + "mockery/mockery": "^1.4", "phpstan/phpstan-nette": "^0.12" }, "conflict": { From b9cbaf606cd27e5e07bf4bd395b6ae5fb8fd0cd0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 17:45:47 +0100 Subject: [PATCH 07/22] coding style --- src/Application/Application.php | 4 +- src/Application/LinkGenerator.php | 2 +- src/Application/MicroPresenter.php | 2 +- src/Application/PresenterFactory.php | 2 +- src/Application/Request.php | 2 +- src/Application/Responses/FileResponse.php | 6 +- src/Application/UI/Component.php | 6 +- src/Application/UI/ComponentReflection.php | 12 ++-- src/Application/UI/Control.php | 2 +- src/Application/UI/Presenter.php | 16 ++--- .../ApplicationDI/ApplicationExtension.php | 12 ++-- src/Bridges/ApplicationDI/LatteExtension.php | 4 +- src/Bridges/ApplicationLatte/Template.php | 9 +-- .../ApplicationLatte/TemplateFactory.php | 10 ++- src/Bridges/ApplicationLatte/UIMacros.php | 10 ++- src/Bridges/ApplicationLatte/UIRuntime.php | 4 +- src/Bridges/ApplicationTracy/RoutingPanel.php | 8 +-- tests/Application/MicroPresenter.invoke.phpt | 2 +- .../Application/MicroPresenter.response.phpt | 28 ++------ tests/Application/Presenter.twoDomains.phpt | 2 +- ...PresenterFactory.formatPresenterClass.phpt | 2 +- .../ApplicationExtension.invalidLink.phpt | 8 +-- tests/Bridges.DI/LatteExtension.basic.phpt | 6 +- .../Template.getParentName().phpt | 2 +- .../TemplateFactory.filters.phpt | 4 +- .../TemplateFactory.nonce.control.phpt | 2 +- .../TemplateFactory.nonce.presenter.phpt | 2 +- tests/Bridges.Latte/UIMacros.control.3.phpt | 2 +- .../Bridges.Latte/UIMacros.isLinkCurrent.phpt | 2 +- tests/Bridges.Latte/UIMacros.link.2.phpt | 64 +++++++++---------- .../UIMacros.renderSnippets2.phpt | 4 +- tests/Responses/FileResponse.range.phpt | 16 ++--- tests/Routers/Route.filter.global.phpt | 2 +- tests/Routers/Route.filter.query.phpt | 8 +-- tests/Routers/Route.filter.url.object.phpt | 8 +-- tests/Routers/Route.filter.url.phpt | 8 +-- .../Routers/Route.optional.autooptional3.phpt | 4 +- tests/Routers/Route.scalarParams.phpt | 58 ++++++++--------- tests/Routers/Route.secured.phpt | 2 +- tests/Routers/Route.type.phpt | 2 +- tests/Routers/Route.withHost.secured.phpt | 8 +-- tests/Routers/RouteList.addRoute.phpt | 2 +- tests/Routers/RouteList.modules.phpt | 2 +- tests/Routers/RouteList.withModule.phpt | 6 +- .../UI/Component.isLinkCurrent().asserts.php | 60 ++++++++--------- tests/UI/Component.redirect().phpt | 2 +- tests/UI/Presenter.link().persistent.phpt | 6 +- tests/UI/Presenter.link().php74.phpt | 6 +- tests/UI/Presenter.link().phpt | 6 +- tests/UI/Presenter.paramChecking.phpt | 2 +- tests/UI/Presenter.storeRequest().phpt | 4 +- 51 files changed, 207 insertions(+), 246 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index ed26eb5a3..6b3f840c1 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -71,7 +71,7 @@ public function __construct( IPresenterFactory $presenterFactory, Router $router, Nette\Http\IRequest $httpRequest, - Nette\Http\IResponse $httpResponse + Nette\Http\IResponse $httpResponse, ) { $this->httpRequest = $httpRequest; $this->httpResponse = $httpResponse; @@ -128,7 +128,7 @@ public function createInitialRequest(): Request $params, $this->httpRequest->getPost(), $this->httpRequest->getFiles(), - [Request::SECURED => $this->httpRequest->isSecured()] + [Request::SECURED => $this->httpRequest->isSecured()], ); } diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 19c98d330..855dc0d67 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -98,7 +98,7 @@ public function withReferenceUrl(string $url): self return new self( $this->router, new UrlScript($url), - $this->presenterFactory + $this->presenterFactory, ); } } diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 5a2960622..2fa1c743c 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -40,7 +40,7 @@ final class MicroPresenter implements Application\IPresenter public function __construct( Nette\DI\Container $context = null, Http\IRequest $httpRequest = null, - Router $router = null + Router $router = null, ) { $this->context = $context; $this->httpRequest = $httpRequest; diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index 45bad8b9c..a4cb18a3f 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -37,7 +37,7 @@ class PresenterFactory implements IPresenterFactory */ public function __construct(callable $factory = null) { - $this->factory = $factory ?: function (string $class): IPresenter { return new $class; }; + $this->factory = $factory ?: fn(string $class): IPresenter => new $class; } diff --git a/src/Application/Request.php b/src/Application/Request.php index f87cb13a7..da95d4efb 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -65,7 +65,7 @@ public function __construct( array $params = [], array $post = [], array $files = [], - array $flags = [] + array $flags = [], ) { $this->name = $name; $this->method = $method; diff --git a/src/Application/Responses/FileResponse.php b/src/Application/Responses/FileResponse.php index 6e5793629..b553ee179 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -39,7 +39,7 @@ public function __construct( string $file, string $name = null, string $contentType = null, - bool $forceDownload = true + bool $forceDownload = true, ) { if (!is_file($file) || !is_readable($file)) { throw new Nette\Application\BadRequestException("File '$file' doesn't exist or is not readable."); @@ -89,7 +89,7 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt 'Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"' - . '; filename*=utf-8\'\'' . rawurlencode($this->name) + . '; filename*=utf-8\'\'' . rawurlencode($this->name), ); $filesize = $length = filesize($this->file); @@ -126,7 +126,7 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt $httpResponse->setHeader('Content-Length', (string) $length); while (!feof($handle) && $length > 0) { - echo $s = fread($handle, min(4000000, $length)); + echo $s = fread($handle, min(4_000_000, $length)); $length -= strlen($s); } fclose($handle); diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 0d4a8bc26..40e4899a6 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -77,7 +77,7 @@ protected function createComponent(string $name): ?Nette\ComponentModel\ICompone { $res = parent::createComponent($name); if ($res && !$res instanceof SignalReceiver && !$res instanceof StatePersistent) { - $type = get_class($res); + $type = $res::class; trigger_error("It seems that component '$name' of type $type is not intended to be used in the Presenter.", E_USER_NOTICE); } return $res; @@ -164,7 +164,7 @@ public function loadState(array $params): void $name, $this instanceof Presenter ? 'presenter ' . $this->getName() : "component '{$this->getUniqueId()}'", $meta['type'], - is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]) + is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]), )); } $this->$name = $params[$name]; @@ -324,7 +324,7 @@ public function redirectPermanent(string $destination, $args = []): void $presenter = $this->getPresenter(); $presenter->redirectUrl( $presenter->createRequest($this, $destination, $args, 'redirect'), - Nette\Http\IResponse::S301_MOVED_PERMANENTLY + Nette\Http\IResponse::S301_MOVED_PERMANENTLY, ); } diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index ee13ae908..e73d5a235 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -38,7 +38,7 @@ final class ComponentReflection extends \ReflectionClass */ public function getPersistentParams(string $class = null): array { - $class = $class ?? $this->getName(); + $class ??= $this->getName(); $params = &self::$ppCache[$class]; if ($params !== null) { return $params; @@ -74,7 +74,7 @@ public function getPersistentParams(string $class = null): array public function getPersistentComponents(string $class = null): array { - $class = $class ?? $this->getName(); + $class ??= $this->getName(); $components = &self::$pcCache[$class]; if ($components !== null) { return $components; @@ -98,7 +98,7 @@ public function getPersistentComponents(string $class = null): array */ public function saveState(Component $component, array &$params): void { - $tree = self::getClassesAndTraits(get_class($component)); + $tree = self::getClassesAndTraits($component::class); foreach ($this->getPersistentParams() as $name => $meta) { if (isset($params[$name])) { @@ -121,7 +121,7 @@ public function saveState(Component $component, array &$params): void $name, $component instanceof Presenter ? 'presenter ' . $component->getName() : "component '{$component->getUniqueId()}'", $meta['type'], - is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]) + is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name]), )); } @@ -166,7 +166,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a $name, ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(), $type, - is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]) + is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]), )); } } elseif ($param->isDefaultValueAvailable()) { @@ -179,7 +179,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a throw new Nette\InvalidArgumentException(sprintf( 'Missing parameter $%s required by %s()', $name, - ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName() + ($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(), )); } } diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index 8d37bcdb9..ad0093cb8 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -82,7 +82,7 @@ protected function checkTemplateClass(string $class): ?string '%s: class %s was found but does not implement the %s, so it will not be used for the template.', static::class, $class, - Template::class + Template::class, ), E_USER_NOTICE); return null; } else { diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index f34a5bdb2..86b2fc7f2 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -451,7 +451,7 @@ public function setLayout($layout) */ public function sendTemplate(Template $template = null): void { - $template = $template ?? $this->getTemplate(); + $template ??= $this->getTemplate(); if (!$template->getFile()) { $files = $this->formatTemplateFiles(); foreach ($files as $file) { @@ -719,7 +719,7 @@ public function canonicalize(string $destination = null, array $args = []): void $this, $destination ?: $this->action, $args + $this->getGlobalState() + $request->getParameters(), - 'redirectX' + 'redirectX', ); } catch (InvalidLinkException $e) { } @@ -765,7 +765,7 @@ protected function createRequest( Component $component, string $destination, array $args, - string $mode + string $mode, ): ?string { // note: createRequest supposes that saveState(), run() & tryCall() behaviour is final @@ -815,7 +815,7 @@ protected function createRequest( // PROCESS SIGNAL ARGUMENTS if (isset($signal)) { // $component must be StatePersistent - $reflection = new ComponentReflection(get_class($component)); + $reflection = new ComponentReflection($component::class); if ($signal === 'this') { // means "no signal" $signal = ''; if (array_key_exists(0, $args)) { @@ -835,7 +835,7 @@ protected function createRequest( trigger_error("Link to deprecated signal '$signal'" . ($component === $this ? '' : ' in ' . $component::class) . " from '{$this->getName()}:{$this->getAction()}'.", E_USER_DEPRECATED); } // convert indexed parameters to named - static::argsToParams(get_class($component), $method, $args, [], $missing); + static::argsToParams($component::class, $method, $args, [], $missing); } // counterpart of StatePersistent @@ -1007,7 +1007,7 @@ public static function argsToParams( string $method, array &$args, array $supplemental = [], - array &$missing = null + array &$missing = null, ): void { $i = 0; $rm = new \ReflectionMethod($class, $method); @@ -1047,7 +1047,7 @@ public static function argsToParams( $name, $rm->getDeclaringClass()->getName() . '::' . $rm->getName(), $type, - is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]) + is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name]), )); } @@ -1354,7 +1354,7 @@ final public function injectPrimary( Http\IResponse $httpResponse, ?Http\Session $session = null, ?Nette\Security\User $user = null, - ?TemplateFactory $templateFactory = null + ?TemplateFactory $templateFactory = null, ) { if ($this->presenterFactory !== null) { throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.'); diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index a1e7f15e0..07d750180 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -42,7 +42,7 @@ public function __construct( bool $debugMode = false, array $scanDirs = null, string $tempDir = null, - Nette\Loaders\RobotLoader $robotLoader = null + Nette\Loaders\RobotLoader $robotLoader = null, ) { $this->debugMode = $debugMode; $this->scanDirs = (array) $scanDirs; @@ -60,7 +60,7 @@ public function getConfigSchema(): Nette\Schema\Schema 'mapping' => Expect::arrayOf('string|array'), 'scanDirs' => Expect::anyOf( Expect::arrayOf('string')->default($this->scanDirs)->mergeDefaults(), - false + false, )->firstIsDefault(), 'scanComposer' => Expect::bool(class_exists(ClassLoader::class)), 'scanFilter' => Expect::string('*Presenter'), @@ -95,7 +95,7 @@ public function loadConfiguration() ->setType(Nette\Application\IPresenterFactory::class) ->setFactory(Nette\Application\PresenterFactory::class, [new Definitions\Statement( Nette\Bridges\ApplicationDI\PresenterFactoryCallback::class, - [1 => $this->invalidLinkMode, $touch ?? null] + [1 => $this->invalidLinkMode, $touch ?? null], )]); if ($config->mapping) { @@ -182,9 +182,7 @@ private function findPresenters(): array $classFile = dirname($rc->getFileName()) . '/autoload_classmap.php'; if (is_file($classFile)) { $this->getContainerBuilder()->addDependency($classFile); - $classes = array_merge($classes, array_keys((function ($path) { - return require $path; - })($classFile))); + $classes = array_merge($classes, array_keys((fn($path) => require $path)($classFile))); } } @@ -207,7 +205,7 @@ private function findPresenters(): array /** @internal */ public static function initializeBlueScreenPanel( Tracy\BlueScreen $blueScreen, - Nette\Application\Application $application + Nette\Application\Application $application, ): void { $blueScreen->addPanel(function (?\Throwable $e) use ($application, $blueScreen): ?array { $dumper = $blueScreen->getDumper(); diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 2433eb1f6..0f45144b6 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -102,7 +102,7 @@ public function beforeCompile() public static function initLattePanel( Nette\Application\UI\TemplateFactory $factory, Tracy\Bar $bar, - bool $all = false + bool $all = false, ) { if (!$factory instanceof ApplicationLatte\TemplateFactory) { return; @@ -112,7 +112,7 @@ public static function initLattePanel( if ($all || $control instanceof Nette\Application\UI\Presenter) { $bar->addPanel(new Latte\Bridges\Tracy\LattePanel( $template->getLatte(), - $all && $control ? (new \ReflectionObject($control))->getShortName() : '' + $all && $control ? (new \ReflectionObject($control))->getShortName() : '', )); } }; diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 72a4248dc..1b19e39e1 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -106,11 +106,12 @@ public function addFunction(string $name, callable $callback) */ public function setTranslator(?Nette\Localization\Translator $translator) { - $this->latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi, ...$args) use ($translator): string { - return $translator === null + $this->latte->addFilter( + 'translate', + fn(Latte\Runtime\FilterInfo $fi, ...$args): string => $translator === null ? $args[0] - : $translator->translate(...$args); - }); + : $translator->translate(...$args), + ); return $this; } diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 90d8adbb2..0bd47cd88 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -45,7 +45,7 @@ public function __construct( Nette\Http\IRequest $httpRequest = null, Nette\Security\User $user = null, Nette\Caching\Storage $cacheStorage = null, - $templateClass = null + $templateClass = null, ) { $this->latteFactory = $latteFactory; $this->httpRequest = $httpRequest; @@ -61,7 +61,7 @@ public function __construct( /** @return Template */ public function createTemplate(UI\Control $control = null, string $class = null): UI\Template { - $class = $class ?? $this->templateClass; + $class ??= $this->templateClass; if (!is_a($class, Template::class, true)) { throw new Nette\InvalidArgumentException("Class $class does not implement " . Template::class . ' or it does not exist.'); } @@ -87,11 +87,9 @@ public function createTemplate(UI\Control $control = null, string $class = null) } }); - $latte->addFilter('modifyDate', function ($time, $delta, $unit = null) { - return $time + $latte->addFilter('modifyDate', fn($time, $delta, $unit = null) => $time ? Nette\Utils\DateTime::from($time)->modify($delta . $unit) - : null; - }); + : null); if (!isset($latte->getFilters()['translate'])) { $latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi): void { diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php index d3a12c762..14ea03e3c 100644 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ b/src/Bridges/ApplicationLatte/UIMacros.php @@ -38,9 +38,7 @@ public static function install(Latte\Compiler $compiler): void $me = new static($compiler); $me->addMacro('control', [$me, 'macroControl']); - $me->addMacro('href', null, null, function (MacroNode $node, PhpWriter $writer) use ($me): string { - return ' ?> href="macroLink($node, $writer) . ' ?>"addMacro('href', null, null, fn(MacroNode $node, PhpWriter $writer): string => ' ?> href="macroLink($node, $writer) . ' ?>"addMacro('plink', [$me, 'macroLink']); $me->addMacro('link', [$me, 'macroLink']); $me->addMacro('ifCurrent', [$me, 'macroIfCurrent'], '}'); // deprecated; use n:class="$presenter->linkCurrent ? ..." @@ -119,7 +117,7 @@ public function macroControl(MacroNode $node, PhpWriter $writer) ? "\$_tmp->$method($param);" : $writer->write( "ob_start(function () {}); \$_tmp->$method($param); \$ʟ_fi = new LR\\FilterInfo(%var); echo %modifyContent(ob_get_clean());", - Latte\Engine::CONTENT_HTML + Latte\Engine::CONTENT_HTML, ) ); } @@ -138,7 +136,7 @@ public function macroLink(MacroNode $node, PhpWriter $writer) 'echo %escape(%modify(' . ($node->name === 'plink' ? '$this->global->uiPresenter' : '$this->global->uiControl') . '->link(%node.word, %node.array?)))' - . ($node->startLine ? " /* line $node->startLine */;" : ';') + . ($node->startLine ? " /* line $node->startLine */;" : ';'), ); } @@ -154,7 +152,7 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer) return $writer->write( $node->args ? 'if ($this->global->uiPresenter->isLinkCurrent(%node.word, %node.array?)) {' - : 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {' + : 'if ($this->global->uiPresenter->getLastCreatedRequestFlag("current")) {', ); } diff --git a/src/Bridges/ApplicationLatte/UIRuntime.php b/src/Bridges/ApplicationLatte/UIRuntime.php index 1c2562e73..f533c1b5b 100644 --- a/src/Bridges/ApplicationLatte/UIRuntime.php +++ b/src/Bridges/ApplicationLatte/UIRuntime.php @@ -26,7 +26,7 @@ final class UIRuntime public static function initialize(Latte\Runtime\Template $template, &$parentName, array $blocks): void { $providers = $template->global; - $blocks = array_filter(array_keys($blocks), function (string $s): bool { return $s[0] !== '_'; }); + $blocks = array_filter(array_keys($blocks), fn(string $s): bool => $s[0] !== '_'); if ( $parentName === null && $blocks @@ -45,7 +45,7 @@ public static function printClass(Latte\Runtime\Template $template, string $pare $params = $template->getParameters(); $control = $params['control'] ?? $params['presenter'] ?? null; if ($control) { - $name = preg_replace('#(Control|Presenter)$#', '', get_class($control)) . 'Template'; + $name = preg_replace('#(Control|Presenter)$#', '', $control::class) . 'Template'; unset($params[$control instanceof Presenter ? 'control' : 'presenter']); } diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 0b068387c..16f00709c 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -44,7 +44,7 @@ final class RoutingPanel implements Tracy\IBarPanel public function __construct( Routing\Router $router, Nette\Http\IRequest $httpRequest, - Nette\Application\IPresenterFactory $presenterFactory + Nette\Application\IPresenterFactory $presenterFactory, ) { $this->router = $router; $this->httpRequest = $httpRequest; @@ -74,7 +74,7 @@ public function getPanel(): string $matched = $this->matched; $routers = $this->routers; $source = $this->source; - $hasModule = (bool) array_filter($routers, function (\stdClass $rq): string { return $rq->module; }); + $hasModule = (bool) array_filter($routers, fn(\stdClass $rq): string => $rq->module); $url = $this->httpRequest->getUrl(); $method = $this->httpRequest->getMethod(); require __DIR__ . '/templates/RoutingPanel.panel.phtml'; @@ -90,7 +90,7 @@ private function analyse( string $module = '', bool $parentMatches = true, int $level = -1, - int $flag = 0 + int $flag = 0, ): void { if ($router instanceof Routing\RouteList) { try { @@ -137,7 +137,7 @@ private function analyse( $this->routers[] = (object) [ 'level' => max(0, $level), 'matched' => $matched, - 'class' => get_class($router), + 'class' => $router::class, 'defaults' => $router instanceof Routing\Route || $router instanceof Routing\SimpleRouter ? $router->getDefaults() : [], 'mask' => $router instanceof Routing\Route ? $router->getMask() : null, 'params' => $params, diff --git a/tests/Application/MicroPresenter.invoke.phpt b/tests/Application/MicroPresenter.invoke.phpt index 7266a4e51..2376d885e 100644 --- a/tests/Application/MicroPresenter.invoke.phpt +++ b/tests/Application/MicroPresenter.invoke.phpt @@ -39,7 +39,7 @@ test('', function () { $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function (stdClass $obj) use (&$log) { - $log[] = get_class($obj); + $log[] = $obj::class; }, ])); Assert::same([ diff --git a/tests/Application/MicroPresenter.response.phpt b/tests/Application/MicroPresenter.response.phpt index ad132e3e6..de5f27dba 100644 --- a/tests/Application/MicroPresenter.response.phpt +++ b/tests/Application/MicroPresenter.response.phpt @@ -40,9 +40,7 @@ function createContainer() test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function () { - return 'test'; - }, + 'callback' => fn() => 'test', ])); Assert::type(\Nette\Application\Responses\TextResponse::class, $response); @@ -53,9 +51,7 @@ test('', function () { test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function ($param) { - return $param; - }, + 'callback' => fn($param) => $param, 'param' => 'test', ])); @@ -67,9 +63,7 @@ test('', function () { test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function () { - return '{=date(Y)}'; - }, + 'callback' => fn() => '{=date(Y)}', ])); Assert::type(Nette\Application\Responses\TextResponse::class, $response); @@ -80,9 +74,7 @@ test('', function () { test('', function () { $presenter = new NetteModule\MicroPresenter(createContainer()); $response = $presenter->run(new Request('Nette:Micro', 'GET', [ - 'callback' => function () { - return [new SplFileInfo(Tester\FileMock::create('{$param}')), []]; - }, + 'callback' => fn() => [new SplFileInfo(Tester\FileMock::create('{$param}')), []], 'param' => 'test', ])); @@ -96,9 +88,7 @@ test('', function () { $response = $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function ($presenter) { - $template = $presenter->createTemplate(null, function () { - return new Latte\Engine; - }); + $template = $presenter->createTemplate(null, fn() => new Latte\Engine); $template->getLatte()->setLoader(new Latte\Loaders\StringLoader); $template->setFile('test'); @@ -116,9 +106,7 @@ test('', function () { $response = $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function ($presenter) { - $template = $presenter->createTemplate(null, function () { - return new Latte\Engine; - }); + $template = $presenter->createTemplate(null, fn() => new Latte\Engine); $template->getLatte()->setLoader(new Latte\Loaders\FileLoader); $template->setFile(Tester\FileMock::create('{$param}')); $template->setParameters(['param' => 'test']); @@ -139,9 +127,7 @@ test('', function () { $response = $presenter->run(new Request('Nette:Micro', 'GET', [ 'callback' => function ($presenter) use ($filename) { - $template = $presenter->createTemplate(null, function () { - return new Latte\Engine; - }); + $template = $presenter->createTemplate(null, fn() => new Latte\Engine); $template->getLatte()->setLoader(new Latte\Loaders\FileLoader); $template->setFile($filename); $template->setParameters(['param' => 'test']); diff --git a/tests/Application/Presenter.twoDomains.phpt b/tests/Application/Presenter.twoDomains.phpt index 58dbca8bc..ac6c5171a 100644 --- a/tests/Application/Presenter.twoDomains.phpt +++ b/tests/Application/Presenter.twoDomains.phpt @@ -32,7 +32,7 @@ function testLink($domain) Mockery::mock(Nette\Application\IPresenterFactory::class), new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $request = new Application\Request('Test', Http\Request::GET, []); diff --git a/tests/Application/PresenterFactory.formatPresenterClass.phpt b/tests/Application/PresenterFactory.formatPresenterClass.phpt index 694c3017e..786c74a72 100644 --- a/tests/Application/PresenterFactory.formatPresenterClass.phpt +++ b/tests/Application/PresenterFactory.formatPresenterClass.phpt @@ -80,5 +80,5 @@ Assert::exception( ]); }, Nette\InvalidStateException::class, - 'Invalid mapping mask for module *.' + 'Invalid mapping mask for module *.', ); diff --git a/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt b/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt index 4d41ab141..94b49c927 100644 --- a/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt +++ b/tests/Bridges.DI/ApplicationExtension.invalidLink.phpt @@ -39,7 +39,7 @@ test('', function () { $container = new Container4; Assert::same( Presenter::INVALID_LINK_TEXTUAL, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); @@ -59,7 +59,7 @@ test('', function () { $container = new Container5; Assert::same( Presenter::INVALID_LINK_WARNING | Presenter::INVALID_LINK_TEXTUAL, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); @@ -79,7 +79,7 @@ test('', function () { $container = new Container6; Assert::same( Presenter::INVALID_LINK_WARNING, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); @@ -99,6 +99,6 @@ test('', function () { $container = new Container7; Assert::same( Presenter::INVALID_LINK_WARNING, - $container->getService('presenter')->invalidLinkMode + $container->getService('presenter')->invalidLinkMode, ); }); diff --git a/tests/Bridges.DI/LatteExtension.basic.phpt b/tests/Bridges.DI/LatteExtension.basic.phpt index b6aecb8e3..aa8d25ed8 100644 --- a/tests/Bridges.DI/LatteExtension.basic.phpt +++ b/tests/Bridges.DI/LatteExtension.basic.phpt @@ -19,7 +19,7 @@ class LoremIpsumMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('lorem', 'lorem'); - Notes::add(get_class($me)); + Notes::add($me::class); } } @@ -30,7 +30,7 @@ class IpsumLoremMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('ipsum', 'ipsum'); - Notes::add(get_class($me)); + Notes::add($me::class); } } @@ -41,7 +41,7 @@ class FooMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('foo', 'foo'); - Notes::add(get_class($me)); + Notes::add($me::class); } } diff --git a/tests/Bridges.Latte/Template.getParentName().phpt b/tests/Bridges.Latte/Template.getParentName().phpt index 696c93167..fa53f71b0 100644 --- a/tests/Bridges.Latte/Template.getParentName().phpt +++ b/tests/Bridges.Latte/Template.getParentName().phpt @@ -40,7 +40,7 @@ Assert::same('file.latte', $template->getParentName()); $template = $latte->createTemplate( '{extends $file} {block name}...{/block}', - ['file' => 'file.latte'] + ['file' => 'file.latte'], ); $template->prepare(); Assert::same('file.latte', $template->getParentName()); diff --git a/tests/Bridges.Latte/TemplateFactory.filters.phpt b/tests/Bridges.Latte/TemplateFactory.filters.phpt index 04cbb8e60..d91001c09 100644 --- a/tests/Bridges.Latte/TemplateFactory.filters.phpt +++ b/tests/Bridges.Latte/TemplateFactory.filters.phpt @@ -38,7 +38,7 @@ setlocale(LC_TIME, 'C'); date_default_timezone_set('Europe/Prague'); Assert::null($latte->invokeFilter('modifyDate', [null, null])); -Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, '+1 day'])); +Assert::same('1978-01-24 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, '+1 day'])); Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', ['1978-05-05', '+1 day'])); Assert::same('1978-05-06 00:00:00', (string) $latte->invokeFilter('modifyDate', [new DateTime('1978-05-05'), '1day'])); -Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254400000, -1, 'day'])); +Assert::same('1978-01-22 11:40:00', (string) $latte->invokeFilter('modifyDate', [254_400_000, -1, 'day'])); diff --git a/tests/Bridges.Latte/TemplateFactory.nonce.control.phpt b/tests/Bridges.Latte/TemplateFactory.nonce.control.phpt index f1d687156..8f6981014 100644 --- a/tests/Bridges.Latte/TemplateFactory.nonce.control.phpt +++ b/tests/Bridges.Latte/TemplateFactory.nonce.control.phpt @@ -32,5 +32,5 @@ $latte->setLoader(new Latte\Loaders\StringLoader); Assert::match( '', - $latte->renderToString('') + $latte->renderToString(''), ); diff --git a/tests/Bridges.Latte/TemplateFactory.nonce.presenter.phpt b/tests/Bridges.Latte/TemplateFactory.nonce.presenter.phpt index a9825ddf2..856c240ea 100644 --- a/tests/Bridges.Latte/TemplateFactory.nonce.presenter.phpt +++ b/tests/Bridges.Latte/TemplateFactory.nonce.presenter.phpt @@ -35,5 +35,5 @@ $latte->setLoader(new Latte\Loaders\StringLoader); Assert::match( '', - $latte->renderToString('') + $latte->renderToString(''), ); diff --git a/tests/Bridges.Latte/UIMacros.control.3.phpt b/tests/Bridges.Latte/UIMacros.control.3.phpt index 07a86bf59..2f83f85f1 100644 --- a/tests/Bridges.Latte/UIMacros.control.3.phpt +++ b/tests/Bridges.Latte/UIMacros.control.3.phpt @@ -40,7 +40,7 @@ Assert::same( Assert::same( '
', - $latte->renderToString('
') + $latte->renderToString('
'), ); Assert::exception(function () use ($latte) { diff --git a/tests/Bridges.Latte/UIMacros.isLinkCurrent.phpt b/tests/Bridges.Latte/UIMacros.isLinkCurrent.phpt index 9e3482fb0..13506e8a3 100644 --- a/tests/Bridges.Latte/UIMacros.isLinkCurrent.phpt +++ b/tests/Bridges.Latte/UIMacros.isLinkCurrent.phpt @@ -43,5 +43,5 @@ Assert::matchFile(__DIR__ . '/expected/UIMacros.isLinkCurrent.phtml', $latte->co {ifCurrent default}default{/ifCurrent} custom function -' +', )); diff --git a/tests/Bridges.Latte/UIMacros.link.2.phpt b/tests/Bridges.Latte/UIMacros.link.2.phpt index 80243c381..3d03183ca 100644 --- a/tests/Bridges.Latte/UIMacros.link.2.phpt +++ b/tests/Bridges.Latte/UIMacros.link.2.phpt @@ -55,66 +55,66 @@ $params['action'] = 'login'; $params['arr'] = ['link' => 'login', 'param' => 123]; Assert::match(<<<'EOD' -plink:['Homepage:'] + plink:['Homepage:'] -plink:['Homepage:'] + plink:['Homepage:'] -plink:['Homepage:action'] + plink:['Homepage:action'] -plink:['Homepage:action'] + plink:['Homepage:action'] -plink:['Homepage:action',10,20,'{one}&two'] + plink:['Homepage:action',10,20,'{one}&two'] -plink:['Homepage:action#hash',10,20,'{one}&two'] + plink:['Homepage:action#hash',10,20,'{one}&two'] -plink:['#hash'] + plink:['#hash'] -plink:[':',10] + plink:[':',10] -plink:{'0':'default','1':10,'a':20,'b':30} + plink:{'0':'default','1':10,'a':20,'b':30} -link:['login'] + link:['login'] - + - + - + - + - -EOD + + EOD , strtr($latte->renderToString(<<<'EOD' -{plink Homepage:} + {plink Homepage:} -{plink Homepage: } + {plink Homepage: } -{plink Homepage:action } + {plink Homepage:action } -{plink 'Homepage:action' } + {plink 'Homepage:action' } -{plink Homepage:action 10, 20, '{one}&two'} + {plink Homepage:action 10, 20, '{one}&two'} -{plink Homepage:action#hash 10, 20, '{one}&two'} + {plink Homepage:action#hash 10, 20, '{one}&two'} -{plink #hash} + {plink #hash} -{plink : 10 } + {plink : 10 } -{plink default 10, 'a' => 20, 'b' => 30} + {plink default 10, 'a' => 20, 'b' => 30} -{link $action} + {link $action} - + - + - + - + - -EOD + + EOD , $params), [''' => "'", ''' => "'"])); diff --git a/tests/Bridges.Latte/UIMacros.renderSnippets2.phpt b/tests/Bridges.Latte/UIMacros.renderSnippets2.phpt index 9d0e7a5d8..ed97b43ac 100644 --- a/tests/Bridges.Latte/UIMacros.renderSnippets2.phpt +++ b/tests/Bridges.Latte/UIMacros.renderSnippets2.phpt @@ -53,9 +53,7 @@ class TestPresenter extends Nette\Application\UI\Presenter { public function createComponentMulti() { - return new Nette\Application\UI\Multiplier(function () { - return new InnerControl; - }); + return new Nette\Application\UI\Multiplier(fn() => new InnerControl); } diff --git a/tests/Responses/FileResponse.range.phpt b/tests/Responses/FileResponse.range.phpt index b34a83261..575757227 100644 --- a/tests/Responses/FileResponse.range.phpt +++ b/tests/Responses/FileResponse.range.phpt @@ -23,7 +23,7 @@ test('', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-20']), - $response = new Http\Response + $response = new Http\Response, ); Assert::same(substr($origData, 10, 11), ob_get_clean()); Assert::same(206, $response->getCode()); @@ -34,7 +34,7 @@ test('', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-10']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, 10, 1), ob_get_clean()); }); @@ -44,7 +44,7 @@ test('', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=10-' . filesize($file)]), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, 10), ob_get_clean()); }); @@ -54,7 +54,7 @@ test('prefix', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=20-']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, 20), ob_get_clean()); }); @@ -64,7 +64,7 @@ test('prefix', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=' . (filesize($file) - 1) . '-']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, -1), ob_get_clean()); }); @@ -74,7 +74,7 @@ test('prefix', function () use ($fileResponse, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=' . filesize($file) . '-']), - $response = new Http\Response + $response = new Http\Response, ); Assert::same('', ob_get_clean()); Assert::same(416, $response->getCode()); @@ -85,7 +85,7 @@ test('suffix', function () use ($fileResponse, $origData) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=-20']), - new Http\Response + new Http\Response, ); Assert::same(substr($origData, -20), ob_get_clean()); }); @@ -95,7 +95,7 @@ test('suffix', function () use ($fileResponse, $origData, $file) { ob_start(); $fileResponse->send( new Http\Request(new Http\UrlScript, null, null, null, ['range' => 'bytes=-' . filesize($file)]), - new Http\Response + new Http\Response, ); Assert::same($origData, ob_get_clean()); }); diff --git a/tests/Routers/Route.filter.global.phpt b/tests/Routers/Route.filter.global.phpt index 518383124..af9dca896 100644 --- a/tests/Routers/Route.filter.global.phpt +++ b/tests/Routers/Route.filter.global.phpt @@ -78,5 +78,5 @@ testRouteIn($route, '/cs/abc-cs/def-cs', [ Assert::same( 'http://example.com/cs/abc-cs/def-cs?test=testvalue', - testRouteOut($route, ['presenter' => 'Abc', 'lang' => 'cs', 'action' => 'def', 'test' => 'testvalue']) + testRouteOut($route, ['presenter' => 'Abc', 'lang' => 'cs', 'action' => 'def', 'test' => 'testvalue']), ); diff --git a/tests/Routers/Route.filter.query.phpt b/tests/Routers/Route.filter.query.phpt index 7d70be6d7..eb2aae981 100644 --- a/tests/Routers/Route.filter.query.phpt +++ b/tests/Routers/Route.filter.query.phpt @@ -16,12 +16,8 @@ require __DIR__ . '/Route.php'; $route = new Route(' ? action=', [ 'presenter' => [ - Route::FILTER_IN => function ($s) { - return strrev($s); - }, - Route::FILTER_OUT => function ($s) { - return strtoupper(strrev($s)); - }, + Route::FILTER_IN => fn($s) => strrev($s), + Route::FILTER_OUT => fn($s) => strtoupper(strrev($s)), ], ]); diff --git a/tests/Routers/Route.filter.url.object.phpt b/tests/Routers/Route.filter.url.object.phpt index d8082a52a..f9d23091b 100644 --- a/tests/Routers/Route.filter.url.object.phpt +++ b/tests/Routers/Route.filter.url.object.phpt @@ -24,12 +24,8 @@ $identityMap[2] = new RouterObject(2); $route = new Route('', [ 'presenter' => 'presenter', 'parameter' => [ - Route::FILTER_IN => function ($s) use ($identityMap) { - return $identityMap[$s] ?? null; - }, - Route::FILTER_OUT => function ($obj) { - return $obj instanceof RouterObject ? $obj->getId() : null; - }, + Route::FILTER_IN => fn($s) => $identityMap[$s] ?? null, + Route::FILTER_OUT => fn($obj) => $obj instanceof RouterObject ? $obj->getId() : null, ], ]); diff --git a/tests/Routers/Route.filter.url.phpt b/tests/Routers/Route.filter.url.phpt index 0bf25218a..d96abff62 100644 --- a/tests/Routers/Route.filter.url.phpt +++ b/tests/Routers/Route.filter.url.phpt @@ -16,12 +16,8 @@ require __DIR__ . '/Route.php'; $route = new Route('', [ 'presenter' => [ - Route::FILTER_IN => function ($s) { - return strrev($s); - }, - Route::FILTER_OUT => function ($s) { - return strrev($s); - }, + Route::FILTER_IN => fn($s) => strrev($s), + Route::FILTER_OUT => fn($s) => strrev($s), ], ]); diff --git a/tests/Routers/Route.optional.autooptional3.phpt b/tests/Routers/Route.optional.autooptional3.phpt index 020192b63..1034f58e0 100644 --- a/tests/Routers/Route.optional.autooptional3.phpt +++ b/tests/Routers/Route.optional.autooptional3.phpt @@ -37,10 +37,10 @@ Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'default' => 'abc' Assert::same( 'http://example.com/homepage/123/xyz', - testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz']) + testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz']), ); Assert::same( 'http://example.com/homepage/abc/xyz', - testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz', 'default' => 'abc']) + testRouteOut($route, ['presenter' => 'Homepage', 'action' => 'default', 'required' => 'xyz', 'default' => 'abc']), ); diff --git a/tests/Routers/Route.scalarParams.phpt b/tests/Routers/Route.scalarParams.phpt index 7791a9020..4f475fea3 100644 --- a/tests/Routers/Route.scalarParams.phpt +++ b/tests/Routers/Route.scalarParams.phpt @@ -21,22 +21,22 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => null])); @@ -51,27 +51,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -85,27 +85,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -119,27 +119,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -153,27 +153,27 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); Assert::null(testRouteOut($route, ['presenter' => 'Homepage', 'param' => ''])); @@ -187,26 +187,26 @@ test('', function () { Assert::same( 'http://example.com/homepage/12', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12]), ); Assert::same( 'http://example.com/homepage/12.1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => 12.1]), ); Assert::same( 'http://example.com/homepage/0', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => false]), ); Assert::same( 'http://example.com/homepage/1', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => true]), ); Assert::same( 'http://example.com/homepage/', - testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]) + testRouteOut($route, ['presenter' => 'Homepage', 'param' => null]), ); }); diff --git a/tests/Routers/Route.secured.phpt b/tests/Routers/Route.secured.phpt index f5a0a79a4..195bb73e9 100644 --- a/tests/Routers/Route.secured.phpt +++ b/tests/Routers/Route.secured.phpt @@ -22,6 +22,6 @@ $route = new Route('', [ $url = $route->constructUrl( ['presenter' => 'Presenter', 'param' => 'any'], - new UrlScript('https://example.org') + new UrlScript('https://example.org'), ); Assert::same('https://example.org/any', $url); diff --git a/tests/Routers/Route.type.phpt b/tests/Routers/Route.type.phpt index 2faeb7a9b..bea846714 100644 --- a/tests/Routers/Route.type.phpt +++ b/tests/Routers/Route.type.phpt @@ -20,5 +20,5 @@ $params = ['id' => 5, 'presenter' => 'p']; Assert::same( 'http://example.com/?presenter=p', - $route->constructUrl($params, new Nette\Http\UrlScript('http://example.com')) + $route->constructUrl($params, new Nette\Http\UrlScript('http://example.com')), ); diff --git a/tests/Routers/Route.withHost.secured.phpt b/tests/Routers/Route.withHost.secured.phpt index 4ec0c0389..97c1d0a49 100644 --- a/tests/Routers/Route.withHost.secured.phpt +++ b/tests/Routers/Route.withHost.secured.phpt @@ -23,13 +23,13 @@ $route = new Route('//example.org/test', [ $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.org') + new UrlScript('https://example.org'), ); Assert::same('https://example.org/test', $url); $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.com') + new UrlScript('https://example.com'), ); Assert::same('https://example.org/test', $url); @@ -42,12 +42,12 @@ $route = new Route('https://example.org/test', [ $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.org') + new UrlScript('https://example.org'), ); Assert::same('https://example.org/test', $url); $url = $route->constructUrl( ['presenter' => 'Default', 'action' => 'default'], - new UrlScript('https://example.com') + new UrlScript('https://example.com'), ); Assert::same('https://example.org/test', $url); diff --git a/tests/Routers/RouteList.addRoute.phpt b/tests/Routers/RouteList.addRoute.phpt index 57703b365..fd6ab423a 100644 --- a/tests/Routers/RouteList.addRoute.phpt +++ b/tests/Routers/RouteList.addRoute.phpt @@ -24,7 +24,7 @@ testRouteIn( $list, '/hello', ['presenter' => 'hello', 'test' => 'testvalue'], - '/hello?test=testvalue' + '/hello?test=testvalue', ); testRouteIn($list, '/none'); diff --git a/tests/Routers/RouteList.modules.phpt b/tests/Routers/RouteList.modules.phpt index d6086a333..db2aff0d2 100644 --- a/tests/Routers/RouteList.modules.phpt +++ b/tests/Routers/RouteList.modules.phpt @@ -35,5 +35,5 @@ testRouteIn( 'action' => 'default', 'test' => 'testvalue', ], - '/auth/?test=testvalue' + '/auth/?test=testvalue', ); diff --git a/tests/Routers/RouteList.withModule.phpt b/tests/Routers/RouteList.withModule.phpt index f9344cce5..01a067750 100644 --- a/tests/Routers/RouteList.withModule.phpt +++ b/tests/Routers/RouteList.withModule.phpt @@ -26,21 +26,21 @@ testRouteIn( $list, '/foo', ['presenter' => 'A:foo', 'test' => 'testvalue'], - '/foo?test=testvalue' + '/foo?test=testvalue', ); testRouteIn( $list, '/bar', ['presenter' => 'A:B:bar', 'test' => 'testvalue'], - '/bar?test=testvalue' + '/bar?test=testvalue', ); testRouteIn( $list, '/hello', ['presenter' => 'C:hello', 'test' => 'testvalue'], - '/hello?test=testvalue' + '/hello?test=testvalue', ); testRouteIn($list, '/none'); diff --git a/tests/UI/Component.isLinkCurrent().asserts.php b/tests/UI/Component.isLinkCurrent().asserts.php index 743284423..d7f1b53f2 100644 --- a/tests/UI/Component.isLinkCurrent().asserts.php +++ b/tests/UI/Component.isLinkCurrent().asserts.php @@ -34,7 +34,7 @@ function callIsComponentLinkCurrent( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->run($request); @@ -45,31 +45,31 @@ function callIsComponentLinkCurrent( Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:default', - [] + [], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:default', - ['int' => 2] + ['int' => 2], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, [Application\UI\Presenter::ACTION_KEY => 'otherAction']), 'Test:default', - [] + [], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, [Application\UI\Presenter::ACTION_KEY => 'otherAction']), 'Test:otherAction', - [] + [], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:default', - ['bool' => true] + ['bool' => true], )); Assert::true(callIsLinkCurrent( @@ -78,7 +78,7 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -87,7 +87,7 @@ function callIsComponentLinkCurrent( [ 'bool' => false, 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -96,7 +96,7 @@ function callIsComponentLinkCurrent( [ 'bool' => false, 'int' => 2, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -105,7 +105,7 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( @@ -114,31 +114,31 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:*', - [] + [], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true]), 'Test:*', - ['float' => 1.0] + ['float' => 1.0], )); Assert::true(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, 'float' => 1.0]), 'Test:*', - ['float' => 1.0] + ['float' => 1.0], )); Assert::false(callIsLinkCurrent( new Application\Request('Test', Http\Request::GET, ['int' => 1, 'bool' => true, 'float' => 1.0]), 'Test:*', - ['float' => 2.0] + ['float' => 2.0], )); Assert::true(callIsLinkCurrent( @@ -146,7 +146,7 @@ function callIsComponentLinkCurrent( 'Test:*', [ 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -154,7 +154,7 @@ function callIsComponentLinkCurrent( 'Test:*', [ 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( @@ -164,7 +164,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'Test:default', - [] + [], )); Assert::true(callIsLinkCurrent( @@ -174,7 +174,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'signal!', - [] + [], )); Assert::false(callIsLinkCurrent( @@ -184,7 +184,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'otherSignal!', - [] + [], )); @@ -198,7 +198,7 @@ function callIsComponentLinkCurrent( 'Test:default', [ Application\UI\Presenter::ACTION_KEY => 'otherAction', - ] + ], )); Assert::false(callIsLinkCurrent( @@ -210,7 +210,7 @@ function callIsComponentLinkCurrent( 'Test:otherAction', [ Application\UI\Presenter::ACTION_KEY => 'default', - ] + ], )); @@ -224,7 +224,7 @@ function callIsComponentLinkCurrent( 'signal!', [ Application\UI\Presenter::SIGNAL_KEY => 'otherSignal', - ] + ], )); Assert::false(callIsLinkCurrent( @@ -236,7 +236,7 @@ function callIsComponentLinkCurrent( 'otherSignal!', [ Application\UI\Presenter::SIGNAL_KEY => 'signal', - ] + ], )); @@ -253,7 +253,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'click!', - [] + [], )); $testPresenter = new TestPresenter; @@ -268,7 +268,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'otherSignal!', - [] + [], )); $testPresenter = new TestPresenter; @@ -286,7 +286,7 @@ function callIsComponentLinkCurrent( 'click!', [ 'x' => 1, - ] + ], )); $testPresenter = new TestPresenter; @@ -304,7 +304,7 @@ function callIsComponentLinkCurrent( 'click!', [ 'x' => 2, - ] + ], )); $testPresenter = new TestPresenter; @@ -323,7 +323,7 @@ function callIsComponentLinkCurrent( 'test:click!', [ 'x' => 1, - ] + ], )); $testPresenter = new TestPresenter; @@ -342,5 +342,5 @@ function callIsComponentLinkCurrent( 'test:click!', [ 'x' => 2, - ] + ], )); diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt index 2a749c432..1894fe1ed 100644 --- a/tests/UI/Component.redirect().phpt +++ b/tests/UI/Component.redirect().phpt @@ -38,7 +38,7 @@ $presenter->injectPrimary( null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript('http://localhost')), - new Http\Response + new Http\Response, ); diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index d519f2673..3828d8a0b 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -138,9 +138,7 @@ $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); $presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class); $presenterFactory->shouldReceive('getPresenterClass') - ->andReturnUsing(function ($presenter) { - return $presenter . 'Presenter'; - }); + ->andReturnUsing(fn($presenter) => $presenter . 'Presenter'); $presenter = new TestPresenter; $presenter->injectPrimary( @@ -148,7 +146,7 @@ $presenter->injectPrimary( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->invalidLinkMode = TestPresenter::INVALID_LINK_WARNING; diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 85c4fdec3..8af741944 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -299,9 +299,7 @@ $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); $presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class); $presenterFactory->shouldReceive('getPresenterClass') - ->andReturnUsing(function ($presenter) { - return $presenter . 'Presenter'; - }); + ->andReturnUsing(fn($presenter) => $presenter . 'Presenter'); $presenter = new TestPresenter; $presenter->injectPrimary( @@ -309,7 +307,7 @@ $presenter->injectPrimary( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->invalidLinkMode = TestPresenter::INVALID_LINK_WARNING; diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index b3321f473..012ce8dd7 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -285,9 +285,7 @@ $url = new Http\UrlScript('http://localhost/index.php', '/index.php'); $presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class); $presenterFactory->shouldReceive('getPresenterClass') - ->andReturnUsing(function ($presenter) { - return $presenter . 'Presenter'; - }); + ->andReturnUsing(fn($presenter) => $presenter . 'Presenter'); $presenter = new TestPresenter; $presenter->injectPrimary( @@ -295,7 +293,7 @@ $presenter->injectPrimary( $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->invalidLinkMode = TestPresenter::INVALID_LINK_WARNING; diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index f792d4e3a..0eb443e86 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -21,7 +21,7 @@ $presenter->injectPrimary( null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), - new Http\Response + new Http\Response, ); diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index d32861228..69f2f02cd 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -124,7 +124,7 @@ test('', function () { new Http\Request(new Http\UrlScript), new Http\Response, $session = new MockSession, - $user = new MockUser + $user = new MockUser, ); $section = $session->testSection = new MockSessionSection($session); @@ -150,7 +150,7 @@ test('', function () { new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), new Http\Response, - $session = new MockSession + $session = new MockSession, ); $section = $session->testSection = new MockSessionSection($session); From 7e9b81d5cf410273a35ef9875bf1596e506a6453 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 18:32:26 +0100 Subject: [PATCH 08/22] removed support for PHP 7 --- src/Application/UI/Component.php | 2 +- src/Application/UI/ComponentReflection.php | 4 +- src/Application/UI/Link.php | 11 +---- src/Application/UI/Presenter.php | 4 +- src/Bridges/ApplicationLatte/Template.php | 12 +---- ...ComponentReflection.combineArgs.php80.phpt | 45 ------------------- tests/UI/ComponentReflection.combineArgs.phpt | 29 ++++++++++++ 7 files changed, 36 insertions(+), 71 deletions(-) delete mode 100644 tests/UI/ComponentReflection.combineArgs.php80.phpt diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 40e4899a6..fe7a04b5b 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -130,7 +130,7 @@ public function checkRequirements($element): void $element instanceof \ReflectionMethod && substr($element->getName(), 0, 6) === 'handle' && !ComponentReflection::parseAnnotation($element, 'crossOrigin') - && (PHP_VERSION_ID < 80000 || !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class)) + && !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class) && !$this->getPresenter()->getHttpRequest()->isSameSite() ) { $this->getPresenter()->detectedCsrf(); diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index e73d5a235..1d291f8a4 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -50,7 +50,7 @@ public function getPersistentParams(string $class = null): array foreach ($defaults as $name => $default) { $rp = new \ReflectionProperty($class, $name); if (!$rp->isStatic() - && ((PHP_VERSION_ID >= 80000 && $rp->getAttributes(Nette\Application\Attributes\Persistent::class)) + && ($rp->getAttributes(Nette\Application\Attributes\Persistent::class) || self::parseAnnotation($rp, 'persistent')) ) { $params[$name] = [ @@ -283,7 +283,7 @@ public static function getParameterType(\ReflectionParameter $param): string public static function getPropertyType(\ReflectionProperty $prop, $default): string { - $type = PHP_VERSION_ID < 70400 ? null : $prop->getType(); + $type = $prop->getType(); return $type ? ($type instanceof \ReflectionNamedType ? $type->getName() : (string) $type) : ($default === null ? 'scalar' : gettype($default)); diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 7236be96f..048e27214 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -103,15 +103,6 @@ public function isLinkCurrent(): bool */ public function __toString(): string { - try { - return $this->component->link($this->destination, $this->params); - - } catch (\Throwable $e) { - if (func_num_args() || PHP_VERSION_ID >= 70400) { - throw $e; - } - trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR); - return ''; - } + return $this->component->link($this->destination, $this->params); } } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 86b2fc7f2..10bd0c686 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -1135,9 +1135,7 @@ public function restoreRequest(string $key): void public static function getPersistentComponents(): array { $rc = new \ReflectionClass(static::class); - $attrs = PHP_VERSION_ID >= 80000 - ? $rc->getAttributes(Application\Attributes\Persistent::class) - : null; + $attrs = $rc->getAttributes(Application\Attributes\Persistent::class); return $attrs ? $attrs[0]->getArguments() : (array) ComponentReflection::parseAnnotation($rc, 'persistent'); diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 1b19e39e1..2af2a865b 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -63,15 +63,7 @@ public function renderToString(string $file = null, array $params = []): string */ public function __toString(): string { - try { - return $this->latte->renderToString($this->file, $this->getParameters()); - } catch (\Throwable $e) { - if (func_num_args() || PHP_VERSION_ID >= 70400) { - throw $e; - } - trigger_error('Exception in ' . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR); - return ''; - } + return $this->latte->renderToString($this->file, $this->getParameters()); } @@ -143,7 +135,7 @@ final public function getParameters(): array { $res = []; foreach ((new \ReflectionObject($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) { - if (PHP_VERSION_ID < 70400 || $prop->isInitialized($this)) { + if ($prop->isInitialized($this)) { $res[$prop->getName()] = $prop->getValue($this); } } diff --git a/tests/UI/ComponentReflection.combineArgs.php80.phpt b/tests/UI/ComponentReflection.combineArgs.php80.phpt deleted file mode 100644 index f34392077..000000000 --- a/tests/UI/ComponentReflection.combineArgs.php80.phpt +++ /dev/null @@ -1,45 +0,0 @@ - '1', 'strArray' => 'abc'])); - Assert::same([[1], [2]], Reflection::combineArgs($method, ['intArray' => [1], 'strArray' => [2]])); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, []); - }, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['intArray' => '']); - }, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['intArray' => null]); - }, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()'); - - Assert::exception(function () use ($method) { - Reflection::combineArgs($method, ['intArray' => new stdClass]); - }, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.'); -}); diff --git a/tests/UI/ComponentReflection.combineArgs.phpt b/tests/UI/ComponentReflection.combineArgs.phpt index b0e79704e..421001366 100644 --- a/tests/UI/ComponentReflection.combineArgs.phpt +++ b/tests/UI/ComponentReflection.combineArgs.phpt @@ -57,6 +57,11 @@ class MyPresenter public function objects(stdClass $req, ?stdClass $nullable, stdClass $opt = null) { } + + + public function hintsUnion(int|array $intArray, string|array $strArray) + { + } } @@ -252,3 +257,27 @@ test('', function () { Reflection::combineArgs($method, ['req' => [], 'opt' => null]); }, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.'); }); + + +test('', function () { + $method = new ReflectionMethod('MyPresenter', 'hintsUnion'); + + Assert::same([1, 'abc'], Reflection::combineArgs($method, ['intArray' => '1', 'strArray' => 'abc'])); + Assert::same([[1], [2]], Reflection::combineArgs($method, ['intArray' => [1], 'strArray' => [2]])); + + Assert::exception(function () use ($method) { + Reflection::combineArgs($method, []); + }, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()'); + + Assert::exception(function () use ($method) { + Reflection::combineArgs($method, ['intArray' => '']); + }, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given.'); + + Assert::exception(function () use ($method) { + Reflection::combineArgs($method, ['intArray' => null]); + }, Nette\InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion()'); + + Assert::exception(function () use ($method) { + Reflection::combineArgs($method, ['intArray' => new stdClass]); + }, Nette\InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given.'); +}); From dfda7d3abb9d377380a0e32f25848d5816646899 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 2 Mar 2021 14:43:25 +0100 Subject: [PATCH 09/22] removed deprecated stuff --- src/Application/PresenterFactory.php | 18 ---------- src/Application/Routers/Route.php | 21 +---------- src/Application/Routers/RouteList.php | 18 +--------- src/Application/Routers/SimpleRouter.php | 36 ++----------------- src/Application/UI/Component.php | 13 +++---- src/Application/UI/Form.php | 13 +++---- src/Application/UI/Presenter.php | 21 ----------- src/Bridges/ApplicationDI/LatteExtension.php | 5 +-- .../ApplicationDI/RoutingExtension.php | 11 ++---- tests/Application/Application.run.phpt | 4 +-- tests/Application/Presenter.twoDomains.phpt | 1 - tests/Bridges.DI/RoutingExtension.basic.phpt | 29 --------------- tests/Routers/Route.oneWay.phpt | 26 -------------- .../UI/Component.isLinkCurrent().asserts.php | 1 - tests/UI/Component.redirect().phpt | 1 - tests/UI/Presenter.link().persistent.phpt | 1 - tests/UI/Presenter.link().php74.phpt | 1 - tests/UI/Presenter.link().phpt | 1 - tests/UI/Presenter.paramChecking.phpt | 1 - tests/UI/Presenter.parameters.phpt | 2 +- tests/UI/Presenter.storeRequest().phpt | 2 -- 21 files changed, 18 insertions(+), 208 deletions(-) delete mode 100644 tests/Routers/Route.oneWay.phpt diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index a4cb18a3f..213f80969 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -120,22 +120,4 @@ public function formatPresenterClass(string $presenter): string } return $mapping[0]; } - - - /** - * Formats presenter name from class name. - * @internal - */ - public function unformatPresenterClass(string $class): ?string - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - foreach ($this->mapping as $module => $mapping) { - $mapping = str_replace(['\\', '*'], ['\\\\', '(\w+)'], $mapping); - if (preg_match("#^\\\\?$mapping[0]((?:$mapping[1])*)$mapping[2]$#Di", $class, $matches)) { - return ($module === '*' ? '' : $module . ':') - . preg_replace("#$mapping[1]#iA", '$1:', $matches[1]) . $matches[3]; - } - } - return null; - } } diff --git a/src/Application/Routers/Route.php b/src/Application/Routers/Route.php index 5a4bdbab7..f6e46d2ee 100644 --- a/src/Application/Routers/Route.php +++ b/src/Application/Routers/Route.php @@ -40,15 +40,12 @@ class Route extends Nette\Routing\Route implements Nette\Routing\Router ], ]; - /** @var int */ - private $flags; - /** * @param string $mask e.g. '//' * @param array|string|\Closure $metadata default values or metadata or callback for NetteModule\MicroPresenter */ - public function __construct(string $mask, $metadata = [], int $flags = 0) + public function __construct(string $mask, array|string|\Closure $metadata = [], int $flags = 0) { if (is_string($metadata)) { [$presenter, $action] = Nette\Application\Helpers::splitName($metadata); @@ -66,12 +63,8 @@ public function __construct(string $mask, $metadata = [], int $flags = 0) ]; } - if ($flags) { - trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::addRoute(..., ..., $flags) instead.', E_USER_DEPRECATED); - } $this->defaultMeta += self::UI_META; - $this->flags = $flags; parent::__construct($mask, $metadata); } @@ -106,10 +99,6 @@ public function match(Nette\Http\IRequest $httpRequest): ?array */ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string { - if ($this->flags & self::ONE_WAY) { - return null; - } - $metadata = $this->getMetadata(); if (isset($metadata[self::MODULE_KEY])) { // try split into module and [submodule:]presenter parts $presenter = $params[self::PRESENTER_KEY]; @@ -144,14 +133,6 @@ public function getConstantParameters(): array } - /** @deprecated */ - public function getFlags(): int - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return $this->flags; - } - - /********************* Inflectors ****************d*g**/ diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index e9752cb3c..f4b60d9b1 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -15,7 +15,7 @@ /** * The router broker. */ -class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess, \Countable, \IteratorAggregate +class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, \ArrayAccess { private const PRESENTER_KEY = 'presenter'; @@ -93,14 +93,6 @@ public function getModule(): ?string } - /** @deprecated */ - public function count(): int - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return count($this->getRouters()); - } - - /** * @param mixed $index * @param Nette\Routing\Router $router @@ -150,14 +142,6 @@ public function offsetUnset($index): void } $this->modify($index, null); } - - - /** @deprecated */ - public function getIterator(): \ArrayIterator - { - trigger_error(__METHOD__ . '() is deprecated, use getRouters().', E_USER_DEPRECATED); - return new \ArrayIterator($this->getRouters()); - } } diff --git a/src/Application/Routers/SimpleRouter.php b/src/Application/Routers/SimpleRouter.php index 9c63c68eb..655799e06 100644 --- a/src/Application/Routers/SimpleRouter.php +++ b/src/Application/Routers/SimpleRouter.php @@ -18,15 +18,10 @@ */ final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Routing\Router { - private const - PRESENTER_KEY = 'presenter', - MODULE_KEY = 'module'; + private const PRESENTER_KEY = 'presenter'; - /** @var int */ - private $flags; - - public function __construct($defaults = [], int $flags = 0) + public function __construct(array $defaults = [], int $flags = 0) { if (is_string($defaults)) { [$presenter, $action] = Nette\Application\Helpers::splitName($defaults); @@ -39,35 +34,8 @@ public function __construct($defaults = [], int $flags = 0) ]; } - if (isset($defaults[self::MODULE_KEY])) { - throw new Nette\DeprecatedException(__METHOD__ . '() parameter module is deprecated, use RouteList::withModule() instead.'); - } elseif ($flags) { - trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::add(..., $flags) instead.', E_USER_DEPRECATED); - } - - $this->flags = $flags; parent::__construct($defaults); } - - - /** - * Constructs absolute URL from array. - */ - public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string - { - if ($this->flags & self::ONE_WAY) { - return null; - } - return parent::constructUrl($params, $refUrl); - } - - - /** @deprecated */ - public function getFlags(): int - { - trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED); - return $this->flags; - } } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index fe7a04b5b..3a8c8d4d1 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -37,13 +37,9 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa * Returns the presenter where this component belongs to. * @return Presenter */ - public function getPresenter(): ?Presenter + public function getPresenter(): Presenter { - if (func_num_args()) { - trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getPresenterIfExists()', E_USER_DEPRECATED); - $throw = func_get_arg(0); - } - return $this->lookup(Presenter::class, $throw ?? true); + return $this->lookup(Presenter::class, throw: true); } @@ -52,14 +48,13 @@ public function getPresenter(): ?Presenter */ public function getPresenterIfExists(): ?Presenter { - return $this->lookup(Presenter::class, false); + return $this->lookup(Presenter::class, throw: false); } - /** @deprecated */ public function hasPresenter(): bool { - return (bool) $this->lookup(Presenter::class, false); + return (bool) $this->lookup(Presenter::class, throw: false); } diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 4544dffd6..96dc923dc 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -65,13 +65,9 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void /** * Returns the presenter where this component belongs to. */ - final public function getPresenter(): ?Presenter + final public function getPresenter(): Presenter { - if (func_num_args()) { - trigger_error(__METHOD__ . '() parameter $throw is deprecated, use getPresenterIfExists()', E_USER_DEPRECATED); - $throw = func_get_arg(0); - } - return $this->lookup(Presenter::class, $throw ?? true); + return $this->lookup(Presenter::class, throw: true); } @@ -80,14 +76,13 @@ final public function getPresenter(): ?Presenter */ final public function getPresenterIfExists(): ?Presenter { - return $this->lookup(Presenter::class, false); + return $this->lookup(Presenter::class, throw: false); } - /** @deprecated */ public function hasPresenter(): bool { - return (bool) $this->lookup(Presenter::class, false); + return (bool) $this->lookup(Presenter::class, throw: false); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 10bd0c686..73cef786e 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -25,7 +25,6 @@ * @property string $view * @property string|bool $layout * @property-read \stdClass $payload - * @property-read Nette\DI\Container $context * @property-read Nette\Http\Session $session * @property-read Nette\Security\User $user */ @@ -109,9 +108,6 @@ abstract class Presenter extends Control implements Application\IPresenter /** @var array|null */ private $lastCreatedRequestFlag; - /** @var Nette\DI\Container */ - private $context; - /** @var Nette\Http\IRequest */ private $httpRequest; @@ -164,7 +160,6 @@ final public function getPresenterIfExists(): self } - /** @deprecated */ final public function hasPresenter(): bool { return true; @@ -1345,7 +1340,6 @@ public function getFlashSession(): Http\SessionSection final public function injectPrimary( - ?Nette\DI\Container $context, ?Application\IPresenterFactory $presenterFactory, ?Nette\Routing\Router $router, Http\IRequest $httpRequest, @@ -1358,7 +1352,6 @@ final public function injectPrimary( throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.'); } - $this->context = $context; $this->presenterFactory = $presenterFactory; $this->router = $router; $this->httpRequest = $httpRequest; @@ -1369,20 +1362,6 @@ final public function injectPrimary( } - /** - * Gets the context. - * @deprecated - */ - public function getContext(): Nette\DI\Container - { - if (!$this->context) { - throw new Nette\InvalidStateException('Context has not been set.'); - } - trigger_error(__METHOD__ . '() is deprecated, use dependency injection.', E_USER_DEPRECATED); - return $this->context; - } - - final public function getHttpRequest(): Http\IRequest { return $this->httpRequest; diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 0f45144b6..5137fe9d5 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -39,7 +39,6 @@ public function getConfigSchema(): Nette\Schema\Schema { return Expect::structure([ 'debugger' => Expect::anyOf(true, false, 'all'), - 'xhtml' => Expect::bool(false)->deprecated(), 'macros' => Expect::arrayOf('string'), 'templateClass' => Expect::string(), 'strictTypes' => Expect::bool(false), @@ -61,9 +60,7 @@ public function loadConfiguration() ->getResultDefinition() ->setFactory(Latte\Engine::class) ->addSetup('setTempDirectory', [$this->tempDir]) - ->addSetup('setAutoRefresh', [$this->debugMode]) - ->addSetup('setContentType', [$config->xhtml ? Latte\Compiler::CONTENT_XHTML : Latte\Compiler::CONTENT_HTML]) - ->addSetup('Nette\Utils\Html::$xhtml = ?', [$config->xhtml]); + ->addSetup('setAutoRefresh', [$this->debugMode]); if ($config->strictTypes) { $latteFactory->addSetup('setStrictTypes', [true]); diff --git a/src/Bridges/ApplicationDI/RoutingExtension.php b/src/Bridges/ApplicationDI/RoutingExtension.php index 21142a74c..770ca41d8 100644 --- a/src/Bridges/ApplicationDI/RoutingExtension.php +++ b/src/Bridges/ApplicationDI/RoutingExtension.php @@ -35,7 +35,6 @@ public function getConfigSchema(): Nette\Schema\Schema return Expect::structure([ 'debugger' => Expect::bool(), 'routes' => Expect::arrayOf('string'), - 'routeClass' => Expect::string()->deprecated(), 'cache' => Expect::bool(false), ]); } @@ -52,14 +51,8 @@ public function loadConfiguration() $router = $builder->addDefinition($this->prefix('router')) ->setFactory(Nette\Application\Routers\RouteList::class); - if ($this->config->routeClass) { - foreach ($this->config->routes as $mask => $action) { - $router->addSetup('$service[] = new ' . $this->config->routeClass . '(?, ?)', [$mask, $action]); - } - } else { - foreach ($this->config->routes as $mask => $action) { - $router->addSetup('$service->addRoute(?, ?)', [$mask, $action]); - } + foreach ($this->config->routes as $mask => $action) { + $router->addSetup('$service->addRoute(?, ?)', [$mask, $action]); } if ($this->name === 'routing') { diff --git a/tests/Application/Application.run.phpt b/tests/Application/Application.run.phpt index 3b7c84382..f5ea35449 100644 --- a/tests/Application/Application.run.phpt +++ b/tests/Application/Application.run.phpt @@ -338,8 +338,8 @@ Assert::noError(function () use ($httpRequest, $httpResponse) { $errors = []; - $presenter->injectPrimary(null, $presenterFactory, $router, $httpRequest, $httpResponse); - $errorPresenter->injectPrimary(null, $presenterFactory, $router, $httpRequest, $httpResponse); + $presenter->injectPrimary($presenterFactory, $router, $httpRequest, $httpResponse); + $errorPresenter->injectPrimary($presenterFactory, $router, $httpRequest, $httpResponse); $app = new Application($presenterFactory, $router, $httpRequest, $httpResponse); $app->catchExceptions = true; diff --git a/tests/Application/Presenter.twoDomains.phpt b/tests/Application/Presenter.twoDomains.phpt index ac6c5171a..ccbd8e8bb 100644 --- a/tests/Application/Presenter.twoDomains.phpt +++ b/tests/Application/Presenter.twoDomains.phpt @@ -28,7 +28,6 @@ function testLink($domain) $presenter = new TestPresenter; $presenter->injectPrimary( - null, Mockery::mock(Nette\Application\IPresenterFactory::class), new Application\Routers\SimpleRouter, new Http\Request($url), diff --git a/tests/Bridges.DI/RoutingExtension.basic.phpt b/tests/Bridges.DI/RoutingExtension.basic.phpt index f8f35d1f4..a8e13d1a6 100644 --- a/tests/Bridges.DI/RoutingExtension.basic.phpt +++ b/tests/Bridges.DI/RoutingExtension.basic.phpt @@ -14,11 +14,6 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -class Route extends Nette\Application\Routers\Route -{ -} - - test('', function () { $loader = new DI\Config\Loader; $config = $loader->load(Tester\FileMock::create(' @@ -36,33 +31,9 @@ test('', function () { $container = new Container1; $router = $container->getService('router'); Assert::type(Nette\Application\Routers\RouteList::class, $router); - @Assert::count(2, $router); // @ is deprecated Assert::same('index.php', $router[0]->getMask()); Assert::same('item/', $router[1]->getMask()); Assert::type(Nette\Application\Routers\RouteList::class, $router); Assert::type(Nette\Application\Routers\Route::class, $router[0]); }); - - -test('', function () { - $loader = new DI\Config\Loader; - $config = $loader->load(Tester\FileMock::create(' - routing: - routeClass: - Route - routes: - item/: Homepage:detail - ', 'neon')); - - $compiler = new DI\Compiler; - $compiler->addExtension('routing', new RoutingExtension(false)); - $code = @$compiler->addConfig($config)->setClassName('Container2')->compile(); // @ routingClass is deprecated - eval($code); - - $container = new Container2; - $router = $container->getService('router'); - - Assert::type(Nette\Application\Routers\RouteList::class, $router); - Assert::type(Route::class, $router[0]); -}); diff --git a/tests/Routers/Route.oneWay.phpt b/tests/Routers/Route.oneWay.phpt deleted file mode 100644 index c9578d790..000000000 --- a/tests/Routers/Route.oneWay.phpt +++ /dev/null @@ -1,26 +0,0 @@ -/', [ // @ is deprecated - 'presenter' => 'Default', - 'action' => 'default', -], Route::ONE_WAY); - -testRouteIn($route, '/presenter/action/', [ - 'presenter' => 'Presenter', - 'action' => 'action', - 'test' => 'testvalue', -], null); diff --git a/tests/UI/Component.isLinkCurrent().asserts.php b/tests/UI/Component.isLinkCurrent().asserts.php index d7f1b53f2..54aef1817 100644 --- a/tests/UI/Component.isLinkCurrent().asserts.php +++ b/tests/UI/Component.isLinkCurrent().asserts.php @@ -30,7 +30,6 @@ function callIsComponentLinkCurrent( $presenterFactory->shouldReceive('getPresenterClass')->andReturn('TestPresenter'); $presenter->injectPrimary( - null, $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt index 1894fe1ed..e4e53f09b 100644 --- a/tests/UI/Component.redirect().phpt +++ b/tests/UI/Component.redirect().phpt @@ -34,7 +34,6 @@ class TestPresenter extends Application\UI\Presenter $presenter = new TestPresenter; $presenter->setParent(null, 'test'); $presenter->injectPrimary( - null, null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript('http://localhost')), diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index 3828d8a0b..205b69232 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -142,7 +142,6 @@ $presenterFactory->shouldReceive('getPresenterClass') $presenter = new TestPresenter; $presenter->injectPrimary( - null, $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 8af741944..522f43f72 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -303,7 +303,6 @@ $presenterFactory->shouldReceive('getPresenterClass') $presenter = new TestPresenter; $presenter->injectPrimary( - null, $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index 012ce8dd7..fda4895ad 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -289,7 +289,6 @@ $presenterFactory->shouldReceive('getPresenterClass') $presenter = new TestPresenter; $presenter->injectPrimary( - null, $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), diff --git a/tests/UI/Presenter.paramChecking.phpt b/tests/UI/Presenter.paramChecking.phpt index 0eb443e86..a2754b9a8 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -17,7 +17,6 @@ require __DIR__ . '/../bootstrap.php'; $presenter = new ParamPresenter; $presenter->injectPrimary( - null, null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), diff --git a/tests/UI/Presenter.parameters.phpt b/tests/UI/Presenter.parameters.phpt index c55be4093..e43072a9f 100644 --- a/tests/UI/Presenter.parameters.phpt +++ b/tests/UI/Presenter.parameters.phpt @@ -36,7 +36,7 @@ class TestPresenter extends Application\UI\Presenter function createPresenter() { $presenter = new TestPresenter; - $presenter->injectPrimary(null, null, null, new Http\Request(new Http\UrlScript), new Http\Response); + $presenter->injectPrimary(null, null, new Http\Request(new Http\UrlScript), new Http\Response); $presenter->autoCanonicalize = false; return $presenter; } diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index 69f2f02cd..f74ee2e59 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -118,7 +118,6 @@ class MockUser extends Security\User test('', function () { $presenter = new TestPresenter; $presenter->injectPrimary( - null, null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), @@ -145,7 +144,6 @@ test('', function () { test('', function () { $presenter = new TestPresenter; $presenter->injectPrimary( - null, null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), From 70c660032a47aee1bff044462e489ebc46ff8954 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 19:10:22 +0100 Subject: [PATCH 10/22] added property typehints --- src/Application/Application.php | 27 ++---- src/Application/ErrorPresenter.php | 3 +- src/Application/LinkGenerator.php | 9 +- src/Application/MicroPresenter.php | 12 +-- src/Application/PresenterFactory.php | 5 +- src/Application/Request.php | 18 ++-- src/Application/Responses/FileResponse.php | 15 +-- src/Application/Responses/ForwardResponse.php | 3 +- src/Application/Responses/JsonResponse.php | 6 +- .../Responses/RedirectResponse.php | 6 +- src/Application/Responses/TextResponse.php | 3 +- src/Application/Routers/CliRouter.php | 3 +- src/Application/Routers/RouteList.php | 3 +- src/Application/UI/BadSignalException.php | 3 +- src/Application/UI/Component.php | 3 +- src/Application/UI/ComponentReflection.php | 12 +-- src/Application/UI/Control.php | 16 ++-- src/Application/UI/Link.php | 9 +- src/Application/UI/Presenter.php | 92 +++++++------------ src/Application/exceptions.php | 2 - .../ApplicationDI/ApplicationExtension.php | 17 ++-- src/Bridges/ApplicationDI/LatteExtension.php | 6 +- .../PresenterFactoryCallback.php | 9 +- .../ApplicationDI/RoutingExtension.php | 3 +- .../ApplicationLatte/DefaultTemplate.php | 17 ++-- .../ApplicationLatte/SnippetBridge.php | 8 +- src/Bridges/ApplicationLatte/Template.php | 6 +- .../ApplicationLatte/TemplateFactory.php | 15 +-- src/Bridges/ApplicationLatte/UIMacros.php | 6 +- src/Bridges/ApplicationTracy/RoutingPanel.php | 17 ++-- tests/Bridges.DI/LatteExtension.basic.phpt | 3 +- .../TemplateFactory.customTemplate.phpt | 2 +- tests/Routers/Route.filter.url.object.phpt | 3 +- tests/bootstrap.php | 2 +- 34 files changed, 130 insertions(+), 234 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 6b3f840c1..168f3e6e0 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -21,14 +21,12 @@ class Application { use Nette\SmartObject; - /** @var int */ - public $maxLoop = 20; + public int $maxLoop = 20; - /** @var bool enable fault barrier? */ - public $catchExceptions; + /** enable fault barrier? */ + public bool $catchExceptions = false; - /** @var string|null */ - public $errorPresenter; + public ?string $errorPresenter = null; /** @var array Occurs before the application loads presenter */ public $onStartup = []; @@ -49,22 +47,17 @@ class Application public $onError = []; /** @var Request[] */ - private $requests = []; + private array $requests = []; - /** @var IPresenter|null */ - private $presenter; + private ?IPresenter $presenter = null; - /** @var Nette\Http\IRequest */ - private $httpRequest; + private Nette\Http\IRequest $httpRequest; - /** @var Nette\Http\IResponse */ - private $httpResponse; + private Nette\Http\IResponse $httpResponse; - /** @var IPresenterFactory */ - private $presenterFactory; + private IPresenterFactory $presenterFactory; - /** @var Router */ - private $router; + private Router $router; public function __construct( diff --git a/src/Application/ErrorPresenter.php b/src/Application/ErrorPresenter.php index df698a62d..0111c7b77 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -22,8 +22,7 @@ final class ErrorPresenter implements Application\IPresenter { use Nette\SmartObject; - /** @var ILogger|null */ - private $logger; + private ?ILogger $logger; public function __construct(ILogger $logger = null) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 855dc0d67..c2e17ae1f 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -21,14 +21,11 @@ final class LinkGenerator { use Nette\SmartObject; - /** @var Router */ - private $router; + private Router $router; - /** @var UrlScript */ - private $refUrl; + private UrlScript $refUrl; - /** @var IPresenterFactory|null */ - private $presenterFactory; + private ?IPresenterFactory $presenterFactory; public function __construct(Router $router, UrlScript $refUrl, IPresenterFactory $presenterFactory = null) diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 2fa1c743c..3c4a1a319 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -24,17 +24,13 @@ final class MicroPresenter implements Application\IPresenter { use Nette\SmartObject; - /** @var Nette\DI\Container|null */ - private $context; + private ?Nette\DI\Container $context; - /** @var Nette\Http\IRequest|null */ - private $httpRequest; + private ?Nette\Http\IRequest $httpRequest; - /** @var Router|null */ - private $router; + private ?Router $router; - /** @var Application\Request|null */ - private $request; + private ?Application\Request $request; public function __construct( diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index 213f80969..463834e7b 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -20,13 +20,12 @@ class PresenterFactory implements IPresenterFactory use Nette\SmartObject; /** @var array[] of module => splited mask */ - private $mapping = [ + private array $mapping = [ '*' => ['', '*Module\\', '*Presenter'], 'Nette' => ['NetteModule\\', '*\\', '*Presenter'], ]; - /** @var array */ - private $cache = []; + private array $cache = []; /** @var callable */ private $factory; diff --git a/src/Application/Request.php b/src/Application/Request.php index da95d4efb..232c32e1c 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -37,23 +37,17 @@ final class Request /** flag */ public const VARYING = 'varying'; - /** @var string|null */ - private $method; + private ?string $method; - /** @var array */ - private $flags = []; + private array $flags = []; - /** @var string */ - private $name; + private string $name; - /** @var array */ - private $params; + private array $params; - /** @var array */ - private $post; + private array $post; - /** @var array */ - private $files; + private array $files; /** diff --git a/src/Application/Responses/FileResponse.php b/src/Application/Responses/FileResponse.php index b553ee179..8dd9efbcc 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -19,20 +19,15 @@ final class FileResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var bool */ - public $resuming = true; + public bool $resuming = true; - /** @var string */ - private $file; + private string $file; - /** @var string */ - private $contentType; + private string $contentType; - /** @var string */ - private $name; + private string $name; - /** @var bool */ - private $forceDownload; + private bool $forceDownload; public function __construct( diff --git a/src/Application/Responses/ForwardResponse.php b/src/Application/Responses/ForwardResponse.php index 43cd9dc91..f2ee36e50 100644 --- a/src/Application/Responses/ForwardResponse.php +++ b/src/Application/Responses/ForwardResponse.php @@ -19,8 +19,7 @@ final class ForwardResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var Nette\Application\Request */ - private $request; + private Nette\Application\Request $request; public function __construct(Nette\Application\Request $request) diff --git a/src/Application/Responses/JsonResponse.php b/src/Application/Responses/JsonResponse.php index 5240a7d79..0d0736f80 100644 --- a/src/Application/Responses/JsonResponse.php +++ b/src/Application/Responses/JsonResponse.php @@ -19,11 +19,9 @@ final class JsonResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var mixed */ - private $payload; + private mixed $payload; - /** @var string */ - private $contentType; + private string $contentType; public function __construct($payload, string $contentType = null) diff --git a/src/Application/Responses/RedirectResponse.php b/src/Application/Responses/RedirectResponse.php index 1ffb11a29..fda1a378a 100644 --- a/src/Application/Responses/RedirectResponse.php +++ b/src/Application/Responses/RedirectResponse.php @@ -20,11 +20,9 @@ final class RedirectResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var string */ - private $url; + private string $url; - /** @var int */ - private $httpCode; + private int $httpCode; public function __construct(string $url, int $httpCode = Http\IResponse::S302_FOUND) diff --git a/src/Application/Responses/TextResponse.php b/src/Application/Responses/TextResponse.php index 20dc07bf6..5806c1983 100644 --- a/src/Application/Responses/TextResponse.php +++ b/src/Application/Responses/TextResponse.php @@ -19,8 +19,7 @@ final class TextResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var mixed */ - private $source; + private mixed $source; /** diff --git a/src/Application/Routers/CliRouter.php b/src/Application/Routers/CliRouter.php index 5a1825449..5caa1808a 100644 --- a/src/Application/Routers/CliRouter.php +++ b/src/Application/Routers/CliRouter.php @@ -21,8 +21,7 @@ final class CliRouter implements Nette\Routing\Router private const PRESENTER_KEY = 'action'; - /** @var array */ - private $defaults; + private array $defaults; public function __construct(array $defaults = []) diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index f4b60d9b1..f9bd9907f 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -19,8 +19,7 @@ class RouteList extends Nette\Routing\RouteList implements Nette\Routing\Router, { private const PRESENTER_KEY = 'presenter'; - /** @var string|null */ - private $module; + private ?string $module; public function __construct(string $module = null) diff --git a/src/Application/UI/BadSignalException.php b/src/Application/UI/BadSignalException.php index 3c9ade6c2..a118a24ff 100644 --- a/src/Application/UI/BadSignalException.php +++ b/src/Application/UI/BadSignalException.php @@ -17,6 +17,5 @@ */ class BadSignalException extends Nette\Application\BadRequestException { - /** @var int */ - protected $code = 403; + protected int $code = 403; } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 3a8c8d4d1..a2a6f01a6 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -29,8 +29,7 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa /** @var array Occurs when component is attached to presenter */ public $onAnchor = []; - /** @var array */ - protected $params = []; + protected array $params = []; /** diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 1d291f8a4..1cc3fcd62 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -22,14 +22,14 @@ final class ComponentReflection extends \ReflectionClass { use Nette\SmartObject; - /** @var array getPersistentParams cache */ - private static $ppCache = []; + /** getPersistentParams cache */ + private static array $ppCache = []; - /** @var array getPersistentComponents cache */ - private static $pcCache = []; + /** getPersistentComponents cache */ + private static array $pcCache = []; - /** @var array isMethodCallable cache */ - private static $mcCache = []; + /** isMethodCallable cache */ + private static array $mcCache = []; /** diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index ad0093cb8..62aed56fb 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -19,17 +19,13 @@ */ abstract class Control extends Component implements Renderable { - /** @var bool */ - public $snippetMode; + public bool $snippetMode = false; - /** @var TemplateFactory */ - private $templateFactory; + private TemplateFactory $templateFactory; - /** @var Template */ - private $template; + private Template $template; - /** @var array */ - private $invalidSnippets = []; + private array $invalidSnippets = []; /********************* template factory ****************d*g**/ @@ -44,7 +40,7 @@ final public function setTemplateFactory(TemplateFactory $templateFactory) final public function getTemplate(): Template { - if ($this->template === null) { + if (!isset($this->template)) { $this->template = $this->createTemplate(); } return $this->template; @@ -61,7 +57,7 @@ protected function createTemplate(/*string $class = null*/): Template $class = func_num_args() // back compatibility ? func_get_arg(0) : $this->formatTemplateClass(); - $templateFactory = $this->templateFactory ?: $this->getPresenter()->getTemplateFactory(); + $templateFactory = $this->templateFactory ?? $this->getPresenter()->getTemplateFactory(); return $templateFactory->createTemplate($this, $class); } diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 048e27214..4e922fa9e 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -20,14 +20,11 @@ final class Link { use Nette\SmartObject; - /** @var Component */ - private $component; + private Component $component; - /** @var string */ - private $destination; + private string $destination; - /** @var array */ - private $params; + private array $params; /** diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 73cef786e..95176a07f 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -45,8 +45,7 @@ abstract class Presenter extends Control implements Application\IPresenter FLASH_KEY = '_fid', DEFAULT_ACTION = 'default'; - /** @var int */ - public $invalidLinkMode; + public int $invalidLinkMode = 0; /** @var array Occurs when the presenter is starting */ public $onStartup = []; @@ -57,80 +56,57 @@ abstract class Presenter extends Control implements Application\IPresenter /** @var array Occurs when the presenter is shutting down */ public $onShutdown = []; - /** @var bool automatically call canonicalize() */ - public $autoCanonicalize = true; + /** automatically call canonicalize() */ + public bool $autoCanonicalize = true; - /** @var bool use absolute Urls or paths? */ - public $absoluteUrls = false; + /** use absolute Urls or paths? */ + public bool $absoluteUrls = false; - /** @var Nette\Application\Request|null */ - private $request; + private ?Nette\Application\Request $request = null; - /** @var Nette\Application\Response */ - private $response; + private ?Nette\Application\Response $response = null; - /** @var array */ - private $globalParams = []; + private array $globalParams = []; - /** @var array */ - private $globalState; + private array $globalState; - /** @var array|null */ - private $globalStateSinces; + private ?array $globalStateSinces; - /** @var string */ - private $action; + private string $action = ''; - /** @var string */ - private $view; + private string $view = ''; - /** @var string|bool */ - private $layout; + private string|bool $layout = ''; - /** @var \stdClass */ - private $payload; + private \stdClass $payload; - /** @var string */ - private $signalReceiver; + private string $signalReceiver; - /** @var string|null */ - private $signal; + private ?string $signal = null; - /** @var bool */ - private $ajaxMode; + private bool $ajaxMode; - /** @var bool */ - private $startupCheck; + private bool $startupCheck = false; - /** @var Nette\Application\Request|null */ - private $lastCreatedRequest; + private ?Nette\Application\Request $lastCreatedRequest; - /** @var array|null */ - private $lastCreatedRequestFlag; + private ?array $lastCreatedRequestFlag; - /** @var Nette\Http\IRequest */ - private $httpRequest; + private Nette\Http\IRequest $httpRequest; - /** @var Nette\Http\IResponse */ - private $httpResponse; + private Nette\Http\IResponse $httpResponse; - /** @var Nette\Http\Session */ - private $session; + private ?Nette\Http\Session $session = null; - /** @var Nette\Application\IPresenterFactory */ - private $presenterFactory; + private ?Nette\Application\IPresenterFactory $presenterFactory = null; - /** @var Nette\Routing\Router */ - private $router; + private ?Nette\Routing\Router $router = null; - /** @var Nette\Security\User */ - private $user; + private ?Nette\Security\User $user = null; - /** @var TemplateFactory */ - private $templateFactory; + private ?TemplateFactory $templateFactory = null; - /** @var Nette\Http\UrlScript */ - private $refUrlCache; + private Nette\Http\UrlScript $refUrlCache; public function __construct() @@ -190,7 +166,7 @@ public function run(Application\Request $request): Application\Response try { // STARTUP $this->request = $request; - $this->payload = $this->payload ?: new \stdClass; + $this->payload ??= new \stdClass; $this->setParent($this->getParent(), $request->getPresenterName()); if (!$this->httpResponse->isSent()) { @@ -321,7 +297,7 @@ public function detectedCsrf(): void */ public function processSignal(): void { - if ($this->signal === null) { + if (!isset($this->signal)) { return; } @@ -581,7 +557,7 @@ final public function getPayload(): \stdClass */ public function isAjax(): bool { - if ($this->ajaxMode === null) { + if (!isset($this->ajaxMode)) { $this->ajaxMode = $this->httpRequest->isAjax(); } return $this->ajaxMode; @@ -964,7 +940,7 @@ public static function parseDestination(string $destination): array */ protected function requestToUrl(Application\Request $request, bool $relative = null): string { - if ($this->refUrlCache === null) { + if (!isset($this->refUrlCache)) { $url = $this->httpRequest->getUrl(); $this->refUrlCache = new Http\UrlScript($url->withoutUserInfo()->getHostUrl() . $url->getScriptPath()); } @@ -1144,7 +1120,7 @@ protected function getGlobalState(string $forClass = null): array { $sinces = &$this->globalStateSinces; - if ($this->globalState === null) { + if (!isset($this->globalState)) { $state = []; foreach ($this->globalParams as $id => $params) { $prefix = $id . self::NAME_SEPARATOR; @@ -1348,7 +1324,7 @@ final public function injectPrimary( ?Nette\Security\User $user = null, ?TemplateFactory $templateFactory = null, ) { - if ($this->presenterFactory !== null) { + if (isset($this->presenterFactory)) { throw new Nette\InvalidStateException('Method ' . __METHOD__ . ' is intended for initialization and should not be called more than once.'); } diff --git a/src/Application/exceptions.php b/src/Application/exceptions.php index cad173ea6..9b0c7d5bc 100644 --- a/src/Application/exceptions.php +++ b/src/Application/exceptions.php @@ -42,7 +42,6 @@ class InvalidPresenterException extends \Exception */ class BadRequestException extends \Exception { - /** @var int */ protected $code = Http\IResponse::S404_NOT_FOUND; @@ -64,6 +63,5 @@ public function getHttpCode(): int */ class ForbiddenRequestException extends BadRequestException { - /** @var int */ protected $code = Http\IResponse::S403_FORBIDDEN; } diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index 07d750180..35e1163ea 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -22,20 +22,15 @@ */ final class ApplicationExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private bool $debugMode; - /** @var array */ - private $scanDirs; + private array $scanDirs; - /** @var Nette\Loaders\RobotLoader|null */ - private $robotLoader; + private ?Nette\Loaders\RobotLoader $robotLoader; - /** @var int */ - private $invalidLinkMode; + private int $invalidLinkMode; - /** @var string|null */ - private $tempDir; + private ?string $tempDir; public function __construct( @@ -56,7 +51,7 @@ public function getConfigSchema(): Nette\Schema\Schema return Expect::structure([ 'debugger' => Expect::bool(), 'errorPresenter' => Expect::string('Nette:Error')->dynamic(), - 'catchExceptions' => Expect::bool()->dynamic(), + 'catchExceptions' => Expect::bool(false)->dynamic(), 'mapping' => Expect::arrayOf('string|array'), 'scanDirs' => Expect::anyOf( Expect::arrayOf('string')->default($this->scanDirs)->mergeDefaults(), diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 5137fe9d5..bca570d51 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -21,11 +21,9 @@ */ final class LatteExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private bool $debugMode; - /** @var string */ - private $tempDir; + private string $tempDir; public function __construct(string $tempDir, bool $debugMode = false) diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index 1f8b21107..abf6923ba 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -18,14 +18,11 @@ */ final class PresenterFactoryCallback { - /** @var Nette\DI\Container */ - private $container; + private Nette\DI\Container $container; - /** @var int */ - private $invalidLinkMode; + private int $invalidLinkMode; - /** @var string|null */ - private $touchToRefresh; + private ?string $touchToRefresh; public function __construct(Nette\DI\Container $container, int $invalidLinkMode, ?string $touchToRefresh) diff --git a/src/Bridges/ApplicationDI/RoutingExtension.php b/src/Bridges/ApplicationDI/RoutingExtension.php index 770ca41d8..e91c4e719 100644 --- a/src/Bridges/ApplicationDI/RoutingExtension.php +++ b/src/Bridges/ApplicationDI/RoutingExtension.php @@ -20,8 +20,7 @@ */ final class RoutingExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private bool $debugMode; public function __construct(bool $debugMode = false) diff --git a/src/Bridges/ApplicationLatte/DefaultTemplate.php b/src/Bridges/ApplicationLatte/DefaultTemplate.php index d20a576fa..19ced2762 100644 --- a/src/Bridges/ApplicationLatte/DefaultTemplate.php +++ b/src/Bridges/ApplicationLatte/DefaultTemplate.php @@ -20,23 +20,18 @@ */ final class DefaultTemplate extends Template { - /** @var Nette\Application\UI\Presenter */ - public $presenter; + public Nette\Application\IPresenter $presenter; - /** @var Nette\Application\UI\Control */ - public $control; + public Nette\Application\UI\Control $control; - /** @var Nette\Security\User */ - public $user; + public Nette\Security\User $user; - /** @var string */ - public $baseUrl; + public string $baseUrl; - /** @var string */ - public $basePath; + public string $basePath; /** @var \stdClass[] */ - public $flashes = []; + public array $flashes = []; /** diff --git a/src/Bridges/ApplicationLatte/SnippetBridge.php b/src/Bridges/ApplicationLatte/SnippetBridge.php index 94db78b0d..75537dbc3 100644 --- a/src/Bridges/ApplicationLatte/SnippetBridge.php +++ b/src/Bridges/ApplicationLatte/SnippetBridge.php @@ -22,11 +22,9 @@ class SnippetBridge implements ISnippetBridge { use Nette\SmartObject; - /** @var Control */ - private $control; + private Control $control; - /** @var \stdClass|null */ - private $payload; + private \stdClass $payload; public function __construct(Control $control) @@ -69,7 +67,7 @@ public function getHtmlId($name): string public function addSnippet($name, $content): void { - if ($this->payload === null) { + if (!isset($this->payload)) { $this->payload = $this->control->getPresenter()->getPayload(); } $this->payload->snippets[$this->control->getSnippetId($name)] = $content; diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 2af2a865b..9e1fcddb9 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -18,11 +18,9 @@ */ class Template implements Nette\Application\UI\Template { - /** @var Latte\Engine */ - private $latte; + private Latte\Engine $latte; - /** @var string */ - private $file; + private ?string $file = null; public function __construct(Latte\Engine $latte) diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 0bd47cd88..1ee19957c 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -24,20 +24,15 @@ class TemplateFactory implements UI\TemplateFactory /** @var array Occurs when a new template is created */ public $onCreate = []; - /** @var LatteFactory */ - private $latteFactory; + private LatteFactory $latteFactory; - /** @var Nette\Http\IRequest|null */ - private $httpRequest; + private ?Nette\Http\IRequest $httpRequest; - /** @var Nette\Security\User|null */ - private $user; + private ?Nette\Security\User $user; - /** @var Nette\Caching\Storage|null */ - private $cacheStorage; + private ?Nette\Caching\Storage $cacheStorage; - /** @var string */ - private $templateClass; + private string $templateClass; public function __construct( diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php index 14ea03e3c..5907ba5b3 100644 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ b/src/Bridges/ApplicationLatte/UIMacros.php @@ -26,11 +26,9 @@ */ final class UIMacros extends Latte\Macros\MacroSet { - /** @var bool|string */ - private $extends; + private bool|string $extends; - /** @var string|null */ - private $printTemplate; + private ?string $printTemplate = null; public static function install(Latte\Compiler $compiler): void diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 16f00709c..415f57885 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -22,23 +22,18 @@ final class RoutingPanel implements Tracy\IBarPanel { use Nette\SmartObject; - /** @var Routing\Router */ - private $router; + private Routing\Router $router; - /** @var Nette\Http\IRequest */ - private $httpRequest; + private Nette\Http\IRequest $httpRequest; - /** @var Nette\Application\IPresenterFactory */ - private $presenterFactory; + private Nette\Application\IPresenterFactory $presenterFactory; /** @var \stdClass[] */ - private $routers = []; + private array $routers = []; - /** @var array|null */ - private $matched; + private ?array $matched = null; - /** @var \ReflectionClass|\ReflectionMethod */ - private $source; + private \ReflectionClass|\ReflectionMethod|null $source = null; public function __construct( diff --git a/tests/Bridges.DI/LatteExtension.basic.phpt b/tests/Bridges.DI/LatteExtension.basic.phpt index aa8d25ed8..a1114bbd9 100644 --- a/tests/Bridges.DI/LatteExtension.basic.phpt +++ b/tests/Bridges.DI/LatteExtension.basic.phpt @@ -48,8 +48,7 @@ class FooMacros extends Latte\Macros\MacroSet class NonStaticMacrosFactory { - /** @var string */ - private $parameter; + private string $parameter; public function __construct($parameter) diff --git a/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt index 88a90e7c9..ead5aab39 100644 --- a/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt +++ b/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt @@ -20,7 +20,7 @@ Tester\Environment::bypassFinals(); class TemplateMock extends Template { - private $file = 'ko'; + private string $file = 'ko'; public function render(string $file = null, array $params = []): void diff --git a/tests/Routers/Route.filter.url.object.phpt b/tests/Routers/Route.filter.url.object.phpt index f9d23091b..39a30a13a 100644 --- a/tests/Routers/Route.filter.url.object.phpt +++ b/tests/Routers/Route.filter.url.object.phpt @@ -54,8 +54,7 @@ Assert::null(testRouteOut($route, [ class RouterObject { - /** @var int */ - private $id; + private int $id; public function __construct($id) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 91c483705..83f9370e5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -52,7 +52,7 @@ function test(string $title, Closure $function): void class Notes { - public static $notes = []; + public static array $notes = []; public static function add($message): void From be59df0c7adcc640f6fc8c99d7d7493dc83f798b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 19:51:16 +0100 Subject: [PATCH 11/22] added PHP 8 typehints --- src/Application/LinkGenerator.php | 2 +- src/Application/PresenterFactory.php | 3 +- src/Application/Request.php | 24 +++------ src/Application/Responses/JsonResponse.php | 5 +- src/Application/Responses/TextResponse.php | 10 +--- src/Application/Routers/RouteList.php | 12 ++--- src/Application/UI/Component.php | 5 +- src/Application/UI/ComponentReflection.php | 4 +- src/Application/UI/Control.php | 3 +- src/Application/UI/Link.php | 6 +-- src/Application/UI/MethodReflection.php | 3 +- src/Application/UI/Presenter.php | 49 ++++++------------- src/Application/UI/Template.php | 3 +- .../ApplicationLatte/DefaultTemplate.php | 6 +-- src/Bridges/ApplicationLatte/Template.php | 13 ++--- .../ApplicationLatte/TemplateFactory.php | 3 +- .../TemplateFactory.customTemplate.phpt | 3 +- tests/UI/Control.formatTemplateClass.phpt | 2 +- tests/UI/Presenter.formatTemplateClass.phpt | 2 +- tests/UI/Presenter.link().persistent.phpt | 2 +- tests/UI/Presenter.link().php74.phpt | 2 +- tests/UI/Presenter.link().phpt | 2 +- tests/UI/Presenter.parameters.phpt | 2 +- tests/UI/Presenter.storeRequest().phpt | 7 +-- 24 files changed, 58 insertions(+), 115 deletions(-) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index c2e17ae1f..42aa3155a 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -90,7 +90,7 @@ public function link(string $dest, array $params = []): string } - public function withReferenceUrl(string $url): self + public function withReferenceUrl(string $url): static { return new self( $this->router, diff --git a/src/Application/PresenterFactory.php b/src/Application/PresenterFactory.php index 463834e7b..1b6590433 100644 --- a/src/Application/PresenterFactory.php +++ b/src/Application/PresenterFactory.php @@ -83,9 +83,8 @@ public function getPresenterClass(string &$name): string /** * Sets mapping as pairs [module => mask] - * @return static */ - public function setMapping(array $mapping) + public function setMapping(array $mapping): static { foreach ($mapping as $module => $mask) { if (is_string($mask)) { diff --git a/src/Application/Request.php b/src/Application/Request.php index 232c32e1c..99ff3dabd 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -72,9 +72,8 @@ public function __construct( /** * Sets the presenter name. - * @return static */ - public function setPresenterName(string $name) + public function setPresenterName(string $name): static { $this->name = $name; return $this; @@ -92,9 +91,8 @@ public function getPresenterName(): string /** * Sets variables provided to the presenter. - * @return static */ - public function setParameters(array $params) + public function setParameters(array $params): static { $this->params = $params; return $this; @@ -112,9 +110,8 @@ public function getParameters(): array /** * Returns a parameter provided to the presenter. - * @return mixed */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->params[$key] ?? null; } @@ -122,9 +119,8 @@ public function getParameter(string $key) /** * Sets variables provided to the presenter via POST. - * @return static */ - public function setPost(array $params) + public function setPost(array $params): static { $this->post = $params; return $this; @@ -134,9 +130,8 @@ public function setPost(array $params) /** * Returns a variable provided to the presenter via POST. * If no key is passed, returns the entire array. - * @return mixed */ - public function getPost(string $key = null) + public function getPost(string $key = null): mixed { return func_num_args() === 0 ? $this->post @@ -146,9 +141,8 @@ public function getPost(string $key = null) /** * Sets all uploaded files. - * @return static */ - public function setFiles(array $files) + public function setFiles(array $files): static { $this->files = $files; return $this; @@ -166,9 +160,8 @@ public function getFiles(): array /** * Sets the method. - * @return static */ - public function setMethod(?string $method) + public function setMethod(?string $method): static { $this->method = $method; return $this; @@ -195,9 +188,8 @@ public function isMethod(string $method): bool /** * Sets the flag. - * @return static */ - public function setFlag(string $flag, bool $value = true) + public function setFlag(string $flag, bool $value = true): static { $this->flags[$flag] = $value; return $this; diff --git a/src/Application/Responses/JsonResponse.php b/src/Application/Responses/JsonResponse.php index 0d0736f80..93dbcfdad 100644 --- a/src/Application/Responses/JsonResponse.php +++ b/src/Application/Responses/JsonResponse.php @@ -31,10 +31,7 @@ public function __construct($payload, string $contentType = null) } - /** - * @return mixed - */ - public function getPayload() + public function getPayload(): mixed { return $this->payload; } diff --git a/src/Application/Responses/TextResponse.php b/src/Application/Responses/TextResponse.php index 5806c1983..439a2b32d 100644 --- a/src/Application/Responses/TextResponse.php +++ b/src/Application/Responses/TextResponse.php @@ -22,19 +22,13 @@ final class TextResponse implements Nette\Application\Response private mixed $source; - /** - * @param mixed $source - */ - public function __construct($source) + public function __construct(mixed $source) { $this->source = $source; } - /** - * @return mixed - */ - public function getSource() + public function getSource(): mixed { return $this->source; } diff --git a/src/Application/Routers/RouteList.php b/src/Application/Routers/RouteList.php index f9bd9907f..fb9407210 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -64,19 +64,15 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri /** * @param string $mask e.g. '//' * @param array|string|\Closure $metadata default values or metadata or callback for NetteModule\MicroPresenter - * @return static */ - public function addRoute(string $mask, $metadata = [], int $flags = 0) + public function addRoute(string $mask, array|string|\Closure $metadata = [], int $flags = 0): static { $this->add(new Route($mask, $metadata), $flags); return $this; } - /** - * @return static - */ - public function withModule(string $module) + public function withModule(string $module): static { $router = new static; $router->module = $module . ':'; @@ -108,11 +104,9 @@ public function offsetSet($index, $router): void /** * @param int $index - * @return mixed * @throws Nette\OutOfRangeException */ - #[\ReturnTypeWillChange] - public function offsetGet($index) + public function offsetGet($index): mixed { if (!$this->offsetExists($index)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index a2a6f01a6..17ba8c3b3 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -34,7 +34,6 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa /** * Returns the presenter where this component belongs to. - * @return Presenter */ public function getPresenter(): Presenter { @@ -90,7 +89,6 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void /** * Calls public method if exists. - * @return bool does method exist? */ protected function tryCall(string $method, array $params): bool { @@ -181,9 +179,8 @@ public function saveState(array &$params): void /** * Returns component param. - * @return mixed */ - final public function getParameter(string $name, $default = null) + final public function getParameter(string $name, $default = null): mixed { return $this->params[$name] ?? $default; } diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 1cc3fcd62..469211839 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -251,7 +251,6 @@ private static function convertSingleType(&$val, string $type): bool /** * Returns an annotation value. - * @param \ReflectionClass|\ReflectionMethod $ref */ public static function parseAnnotation(\Reflector $ref, string $name): ?array { @@ -301,9 +300,8 @@ public function hasAnnotation(string $name): bool /** * Returns an annotation value. - * @return mixed */ - public function getAnnotation(string $name) + public function getAnnotation(string $name): mixed { $res = self::parseAnnotation($this, $name); return $res ? end($res) : null; diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index 62aed56fb..6e988f0b2 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -97,9 +97,8 @@ public function templatePrepareFilters(Template $template): void /** * Saves the message to template, that can be displayed after redirect. - * @param string|\stdClass|Nette\HtmlStringable $message */ - public function flashMessage($message, string $type = 'info'): \stdClass + public function flashMessage(string|\stdClass|Nette\HtmlStringable $message, string $type = 'info'): \stdClass { $id = $this->getParameterId('flash'); $flash = $message instanceof \stdClass ? $message : (object) [ diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 4e922fa9e..687a331b2 100644 --- a/src/Application/UI/Link.php +++ b/src/Application/UI/Link.php @@ -58,9 +58,8 @@ public function getDestination(): string /** * Changes link parameter. - * @return static */ - public function setParameter(string $key, $value) + public function setParameter(string $key, $value): static { $this->params[$key] = $value; return $this; @@ -69,9 +68,8 @@ public function setParameter(string $key, $value) /** * Returns link parameter. - * @return mixed */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->params[$key] ?? null; } diff --git a/src/Application/UI/MethodReflection.php b/src/Application/UI/MethodReflection.php index c676e3331..6e3c8cba0 100644 --- a/src/Application/UI/MethodReflection.php +++ b/src/Application/UI/MethodReflection.php @@ -30,9 +30,8 @@ public function hasAnnotation(string $name): bool /** * Returns an annotation value. - * @return mixed */ - public function getAnnotation(string $name) + public function getAnnotation(string $name): mixed { $res = ComponentReflection::parseAnnotation($this, $name); return $res ? end($res) : null; diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 95176a07f..6f35062bd 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -124,13 +124,13 @@ final public function getRequest(): ?Application\Request /** * Returns self. */ - final public function getPresenter(): self + final public function getPresenter(): static { return $this; } - final public function getPresenterIfExists(): self + final public function getPresenterIfExists(): static { return $this; } @@ -265,17 +265,13 @@ protected function beforeRender() /** * Common render method. - * @return void */ - protected function afterRender() + protected function afterRender(): void { } - /** - * @return void - */ - protected function shutdown(Application\Response $response) + protected function shutdown(Application\Response $response): void { } @@ -327,9 +323,8 @@ final public function getSignal(): ?array /** * Checks if the signal receiver is the given one. - * @param Component|string $component */ - final public function isSignalReceiver($component, $signal = null): bool + final public function isSignalReceiver(Nette\ComponentModel\Component|string $component, $signal = null): bool { if ($component instanceof Nette\ComponentModel\Component) { $component = $component === $this @@ -385,9 +380,8 @@ final public function getView(): string /** * Changes current view. Any name is allowed. - * @return static */ - public function setView(string $view) + public function setView(string $view): static { $this->view = $view; return $this; @@ -396,9 +390,8 @@ public function setView(string $view) /** * Returns current layout name. - * @return string|bool */ - final public function getLayout() + final public function getLayout(): string|bool { return $this->layout; } @@ -406,10 +399,8 @@ final public function getLayout() /** * Changes or disables layout. - * @param string|bool $layout - * @return static */ - public function setLayout($layout) + public function setLayout(string|bool $layout): static { $this->layout = $layout === false ? false : (string) $layout; return $this; @@ -523,9 +514,6 @@ public static function formatRenderMethod(string $view): string } - /** - * @param string $class - */ protected function createTemplate(/*string $class = null*/): Template { $class = func_num_args() // back compatibility @@ -577,11 +565,10 @@ public function sendPayload(): void /** * Sends JSON data to the output. - * @param mixed $data * @throws Nette\Application\AbortException * @return never */ - public function sendJson($data): void + public function sendJson(mixed $data): void { $this->sendResponse(new Responses\JsonResponse($data)); } @@ -615,12 +602,11 @@ public function terminate(): void /** * Forward to another presenter or action. - * @param string|Nette\Application\Request $destination * @param array|mixed $args * @throws Nette\Application\AbortException * @return never */ - public function forward($destination, $args = []): void + public function forward(string|Nette\Application\Request $destination, $args = []): void { if ($destination instanceof Application\Request) { $this->sendResponse(new Responses\ForwardResponse($destination)); @@ -707,13 +693,15 @@ public function canonicalize(string $destination = null, array $args = []): void /** * Attempts to cache the sent entity by its last modification date. - * @param string|int|\DateTimeInterface $lastModified * @param string $etag strong entity tag validator * @param string $expire like '20 minutes' * @throws Nette\Application\AbortException */ - public function lastModified($lastModified, string $etag = null, string $expire = null): void - { + public function lastModified( + string|int|\DateTimeInterface $lastModified, + string $etag = null, + string $expire = null, + ): void { if ($expire !== null) { $this->httpResponse->setExpiration($expire); } @@ -728,7 +716,6 @@ public function lastModified($lastModified, string $etag = null, string $expire * Request/URL factory. * @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" * @param string $mode forward|redirect|link - * @return string|null URL * @throws InvalidLinkException * @internal */ @@ -1058,7 +1045,6 @@ protected function handleInvalidLink(InvalidLinkException $e): string /** * Stores current request to session. - * @return string key */ public function storeRequest(string $expiration = '+ 10 minutes'): string { @@ -1350,10 +1336,7 @@ final public function getHttpResponse(): Http\IResponse } - /** - * @return Http\Session|Http\SessionSection - */ - final public function getSession(string $namespace = null) + final public function getSession(string $namespace = null): Http\Session|Http\SessionSection { if (!$this->session) { throw new Nette\InvalidStateException('Service Session has not been set.'); diff --git a/src/Application/UI/Template.php b/src/Application/UI/Template.php index b4374d3fd..d50339577 100644 --- a/src/Application/UI/Template.php +++ b/src/Application/UI/Template.php @@ -22,9 +22,8 @@ function render(): void; /** * Sets the path to the template file. - * @return static */ - function setFile(string $file); + function setFile(string $file): static; /** * Returns the path to the template file. diff --git a/src/Bridges/ApplicationLatte/DefaultTemplate.php b/src/Bridges/ApplicationLatte/DefaultTemplate.php index 19ced2762..0649e0586 100644 --- a/src/Bridges/ApplicationLatte/DefaultTemplate.php +++ b/src/Bridges/ApplicationLatte/DefaultTemplate.php @@ -36,9 +36,8 @@ final class DefaultTemplate extends Template /** * Adds new template parameter. - * @return static */ - public function add(string $name, $value) + public function add(string $name, $value): static { if (property_exists($this, $name)) { throw new Nette\InvalidStateException("The variable '$name' already exists."); @@ -50,9 +49,8 @@ public function add(string $name, $value) /** * Sets all parameters. - * @return static */ - public function setParameters(array $params) + public function setParameters(array $params): static { return Nette\Utils\Arrays::toObject($params, $this); } diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 9e1fcddb9..c1f844083 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -57,7 +57,6 @@ public function renderToString(string $file = null, array $params = []): string /** * Renders template to string. - * @param can throw exceptions? (hidden parameter) */ public function __toString(): string { @@ -70,9 +69,8 @@ public function __toString(): string /** * Registers run-time filter. - * @return static */ - public function addFilter(?string $name, callable $callback) + public function addFilter(?string $name, callable $callback): static { $this->latte->addFilter($name, $callback); return $this; @@ -81,9 +79,8 @@ public function addFilter(?string $name, callable $callback) /** * Registers run-time function. - * @return static */ - public function addFunction(string $name, callable $callback) + public function addFunction(string $name, callable $callback): static { $this->latte->addFunction($name, $callback); return $this; @@ -92,9 +89,8 @@ public function addFunction(string $name, callable $callback) /** * Sets translate adapter. - * @return static */ - public function setTranslator(?Nette\Localization\Translator $translator) + public function setTranslator(?Nette\Localization\Translator $translator): static { $this->latte->addFilter( 'translate', @@ -111,9 +107,8 @@ public function setTranslator(?Nette\Localization\Translator $translator) /** * Sets the path to the template file. - * @return static */ - public function setFile(string $file) + public function setFile(string $file): static { $this->file = $file; return $this; diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 1ee19957c..79eb60f24 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -53,8 +53,7 @@ public function __construct( } - /** @return Template */ - public function createTemplate(UI\Control $control = null, string $class = null): UI\Template + public function createTemplate(UI\Control $control = null, string $class = null): Template { $class ??= $this->templateClass; if (!is_a($class, Template::class, true)) { diff --git a/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt b/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt index ead5aab39..99baf1bbd 100644 --- a/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt +++ b/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt @@ -29,9 +29,10 @@ class TemplateMock extends Template } - public function setFile(string $file) + public function setFile(string $file): static { $this->file = $file; + return $this; } diff --git a/tests/UI/Control.formatTemplateClass.phpt b/tests/UI/Control.formatTemplateClass.phpt index 789d6b952..4d66a4a49 100644 --- a/tests/UI/Control.formatTemplateClass.phpt +++ b/tests/UI/Control.formatTemplateClass.phpt @@ -35,7 +35,7 @@ class CTemplate implements Nette\Application\UI\Template } - public function setFile(string $file) + public function setFile(string $file): static { } diff --git a/tests/UI/Presenter.formatTemplateClass.phpt b/tests/UI/Presenter.formatTemplateClass.phpt index 80388035f..b9ed33bb7 100644 --- a/tests/UI/Presenter.formatTemplateClass.phpt +++ b/tests/UI/Presenter.formatTemplateClass.phpt @@ -35,7 +35,7 @@ class CTemplate implements Nette\Application\UI\Template } - public function setFile(string $file) + public function setFile(string $file): static { } diff --git a/tests/UI/Presenter.link().persistent.phpt b/tests/UI/Presenter.link().persistent.phpt index 205b69232..9e5f0cc13 100644 --- a/tests/UI/Presenter.link().persistent.phpt +++ b/tests/UI/Presenter.link().persistent.phpt @@ -54,7 +54,7 @@ class TestPresenter extends BasePresenter public $p2; - protected function startup() + protected function startup(): void { parent::startup(); diff --git a/tests/UI/Presenter.link().php74.phpt b/tests/UI/Presenter.link().php74.phpt index 522f43f72..9c2cefe88 100644 --- a/tests/UI/Presenter.link().php74.phpt +++ b/tests/UI/Presenter.link().php74.phpt @@ -69,7 +69,7 @@ class TestPresenter extends Application\UI\Presenter public ?bool $pbooln = null; - protected function startup() + protected function startup(): void { parent::startup(); $this['mycontrol'] = new TestControl; diff --git a/tests/UI/Presenter.link().phpt b/tests/UI/Presenter.link().phpt index fda4895ad..7458e905d 100644 --- a/tests/UI/Presenter.link().phpt +++ b/tests/UI/Presenter.link().phpt @@ -62,7 +62,7 @@ class TestPresenter extends Application\UI\Presenter public $pbool = true; - protected function startup() + protected function startup(): void { parent::startup(); $this['mycontrol'] = new TestControl; diff --git a/tests/UI/Presenter.parameters.phpt b/tests/UI/Presenter.parameters.phpt index e43072a9f..f56ed22fd 100644 --- a/tests/UI/Presenter.parameters.phpt +++ b/tests/UI/Presenter.parameters.phpt @@ -25,7 +25,7 @@ class TestPresenter extends Application\UI\Presenter } - protected function startup() + protected function startup(): void { parent::startup(); throw new Application\AbortException; diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index f74ee2e59..5661be744 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -73,10 +73,11 @@ class MockSessionSection extends Nette\Http\SessionSection } - public function setExpiration($expiraton, $variables = null) + public function setExpiration(?string $expiraton, string|array $variables = null): static { $this->testExpiration = $expiraton; $this->testExpirationVariables = $variables; + return $this; } @@ -92,7 +93,7 @@ class MockSessionSection extends Nette\Http\SessionSection } - public function offsetGet($name) + public function offsetGet($name): mixed { } @@ -109,7 +110,7 @@ class MockUser extends Security\User } - public function getId() + public function getId(): string|int { return 'test_id'; } From 0b933ed8b05a9d6ae944e777d4c15dd0aea2f82e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 2 Mar 2021 13:32:39 +0100 Subject: [PATCH 12/22] used constructor promotion --- src/Application/ErrorPresenter.php | 9 ++---- src/Application/LinkGenerator.php | 17 ++++------- src/Application/MicroPresenter.php | 15 ++-------- src/Application/Request.php | 30 ++++--------------- .../ApplicationDI/ApplicationExtension.php | 15 ++-------- .../PresenterFactoryCallback.php | 17 ++++------- .../ApplicationLatte/TemplateFactory.php | 20 +++---------- 7 files changed, 29 insertions(+), 94 deletions(-) diff --git a/src/Application/ErrorPresenter.php b/src/Application/ErrorPresenter.php index 0111c7b77..b027f07c3 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -22,12 +22,9 @@ final class ErrorPresenter implements Application\IPresenter { use Nette\SmartObject; - private ?ILogger $logger; - - - public function __construct(ILogger $logger = null) - { - $this->logger = $logger; + public function __construct( + private ?ILogger $logger = null, + ) { } diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 42aa3155a..160c7545b 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -21,18 +21,11 @@ final class LinkGenerator { use Nette\SmartObject; - private Router $router; - - private UrlScript $refUrl; - - private ?IPresenterFactory $presenterFactory; - - - public function __construct(Router $router, UrlScript $refUrl, IPresenterFactory $presenterFactory = null) - { - $this->router = $router; - $this->refUrl = $refUrl; - $this->presenterFactory = $presenterFactory; + public function __construct( + private Router $router, + private UrlScript $refUrl, + private ?IPresenterFactory $presenterFactory = null, + ) { } diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 3c4a1a319..1a3cc3230 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -24,23 +24,14 @@ final class MicroPresenter implements Application\IPresenter { use Nette\SmartObject; - private ?Nette\DI\Container $context; - - private ?Nette\Http\IRequest $httpRequest; - - private ?Router $router; - private ?Application\Request $request; public function __construct( - Nette\DI\Container $context = null, - Http\IRequest $httpRequest = null, - Router $router = null, + private ?Nette\DI\Container $context = null, + private ?Nette\Http\IRequest $httpRequest = null, + private ?Router $router = null, ) { - $this->context = $context; - $this->httpRequest = $httpRequest; - $this->router = $router; } diff --git a/src/Application/Request.php b/src/Application/Request.php index 99ff3dabd..b3bd616a4 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -37,36 +37,18 @@ final class Request /** flag */ public const VARYING = 'varying'; - private ?string $method; - - private array $flags = []; - - private string $name; - - private array $params; - - private array $post; - - private array $files; - /** * @param string $name presenter name (module:module:presenter) */ public function __construct( - string $name, - string $method = null, - array $params = [], - array $post = [], - array $files = [], - array $flags = [], + private string $name, + private ?string $method = null, + private array $params = [], + private array $post = [], + private array $files = [], + private array $flags = [], ) { - $this->name = $name; - $this->method = $method; - $this->params = $params; - $this->post = $post; - $this->files = $files; - $this->flags = $flags; } diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index 35e1163ea..98361d845 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -22,27 +22,18 @@ */ final class ApplicationExtension extends Nette\DI\CompilerExtension { - private bool $debugMode; - private array $scanDirs; - private ?Nette\Loaders\RobotLoader $robotLoader; - private int $invalidLinkMode; - private ?string $tempDir; - public function __construct( - bool $debugMode = false, + private bool $debugMode = false, array $scanDirs = null, - string $tempDir = null, - Nette\Loaders\RobotLoader $robotLoader = null, + private ?string $tempDir = null, + private ?Nette\Loaders\RobotLoader $robotLoader = null, ) { - $this->debugMode = $debugMode; $this->scanDirs = (array) $scanDirs; - $this->tempDir = $tempDir; - $this->robotLoader = $robotLoader; } diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index abf6923ba..d537eeadc 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -18,18 +18,11 @@ */ final class PresenterFactoryCallback { - private Nette\DI\Container $container; - - private int $invalidLinkMode; - - private ?string $touchToRefresh; - - - public function __construct(Nette\DI\Container $container, int $invalidLinkMode, ?string $touchToRefresh) - { - $this->container = $container; - $this->invalidLinkMode = $invalidLinkMode; - $this->touchToRefresh = $touchToRefresh; + public function __construct( + private Nette\DI\Container $container, + private int $invalidLinkMode, + private ?string $touchToRefresh, + ) { } diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 79eb60f24..1fa6853a9 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -24,28 +24,16 @@ class TemplateFactory implements UI\TemplateFactory /** @var array Occurs when a new template is created */ public $onCreate = []; - private LatteFactory $latteFactory; - - private ?Nette\Http\IRequest $httpRequest; - - private ?Nette\Security\User $user; - - private ?Nette\Caching\Storage $cacheStorage; - private string $templateClass; public function __construct( - LatteFactory $latteFactory, - Nette\Http\IRequest $httpRequest = null, - Nette\Security\User $user = null, - Nette\Caching\Storage $cacheStorage = null, + private LatteFactory $latteFactory, + private ?Nette\Http\IRequest $httpRequest = null, + private ?Nette\Security\User $user = null, + private ?Nette\Caching\Storage $cacheStorage = null, $templateClass = null, ) { - $this->latteFactory = $latteFactory; - $this->httpRequest = $httpRequest; - $this->user = $user; - $this->cacheStorage = $cacheStorage; if ($templateClass && (!class_exists($templateClass) || !is_a($templateClass, Template::class, true))) { throw new Nette\InvalidArgumentException("Class $templateClass does not implement " . Template::class . ' or it does not exist.'); } From 5383147393b23d1a4e76015ae231322e6ae0a445 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 20:35:50 +0100 Subject: [PATCH 13/22] Control, Presenter::createTemplate has argument --- src/Application/UI/Control.php | 6 ++---- src/Application/UI/Presenter.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index 6e988f0b2..288d81aa1 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -52,11 +52,9 @@ final public function getTemplate(): Template * @param class-string $class * @return T */ - protected function createTemplate(/*string $class = null*/): Template + protected function createTemplate(string $class = null): Template { - $class = func_num_args() // back compatibility - ? func_get_arg(0) - : $this->formatTemplateClass(); + $class ??= $this->formatTemplateClass(); $templateFactory = $this->templateFactory ?? $this->getPresenter()->getTemplateFactory(); return $templateFactory->createTemplate($this, $class); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 6f35062bd..d391a84b0 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -514,11 +514,9 @@ public static function formatRenderMethod(string $view): string } - protected function createTemplate(/*string $class = null*/): Template + protected function createTemplate(string $class = null): Template { - $class = func_num_args() // back compatibility - ? func_get_arg(0) - : $this->formatTemplateClass(); + $class ??= $this->formatTemplateClass(); return $this->getTemplateFactory()->createTemplate($this, $class); } From 796a545413929fc8bb53291fb84c84967870be12 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 1 Mar 2021 21:06:01 +0100 Subject: [PATCH 14/22] Form: $crossOrigin is defined in descendant --- src/Application/UI/Form.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 96dc923dc..c27670682 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -20,9 +20,6 @@ class Form extends Nette\Forms\Form implements SignalReceiver /** @var array Occurs when form is attached to presenter */ public $onAnchor = []; - /** @var bool */ - protected $crossOrigin = false; - /** * Application form constructor. @@ -95,19 +92,10 @@ public function isAnchored(): bool } - /** - * Disables CSRF protection using a SameSite cookie. - */ - public function allowCrossOrigin(): void - { - $this->crossOrigin = true; - } - - /** @deprecated use allowCrossOrigin() */ public function disableSameSiteProtection(): void { - $this->crossOrigin = true; + $this->allowCrossOrigin(); } From 10c6919bf87fd37700132918397190478d50fcd8 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 11 Mar 2021 21:44:34 +0100 Subject: [PATCH 15/22] removed community health files --- .github/ISSUE_TEMPLATE/Bug_report.md | 19 ------------- .github/ISSUE_TEMPLATE/Feature_request.md | 9 ------ .github/ISSUE_TEMPLATE/Support_question.md | 12 -------- .github/ISSUE_TEMPLATE/Support_us.md | 21 -------------- .github/funding.yml | 2 -- .github/pull_request_template.md | 11 -------- contributing.md | 33 ---------------------- 7 files changed, 107 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/Feature_request.md delete mode 100644 .github/ISSUE_TEMPLATE/Support_question.md delete mode 100644 .github/ISSUE_TEMPLATE/Support_us.md delete mode 100644 .github/funding.yml delete mode 100644 .github/pull_request_template.md delete mode 100644 contributing.md diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md deleted file mode 100644 index a4cd12634..000000000 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: "🐛 Bug Report" -about: "If something isn't working as expected 🤔" - ---- - -Version: ?.?.? - -### Bug Description -... A clear and concise description of what the bug is. A good bug report shouldn't leave others needing to chase you up for more information. - -### Steps To Reproduce -... If possible a minimal demo of the problem ... - -### Expected Behavior -... A clear and concise description of what you expected to happen. - -### Possible Solution -... Only if you have suggestions on a fix for the bug diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md deleted file mode 100644 index d2e219489..000000000 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -name: "🚀 Feature Request" -about: "I have a suggestion (and may want to implement it) 🙂" - ---- - -- Is your feature request related to a problem? Please describe. -- Explain your intentions. -- It's up to you to make a strong case to convince the project's developers of the merits of this feature. diff --git a/.github/ISSUE_TEMPLATE/Support_question.md b/.github/ISSUE_TEMPLATE/Support_question.md deleted file mode 100644 index 75c48b6ed..000000000 --- a/.github/ISSUE_TEMPLATE/Support_question.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: "🤗 Support Question" -about: "If you have a question 💬, please check out our forum!" - ---- - ---------------^ Click "Preview" for a nicer view! -We primarily use GitHub as an issue tracker; for usage and support questions, please check out these resources below. Thanks! 😁. - -* Nette Forum: https://forum.nette.org -* Nette Gitter: https://gitter.im/nette/nette -* Slack (czech): https://pehapkari.slack.com/messages/C2R30BLKA diff --git a/.github/ISSUE_TEMPLATE/Support_us.md b/.github/ISSUE_TEMPLATE/Support_us.md deleted file mode 100644 index 92d8a4c3a..000000000 --- a/.github/ISSUE_TEMPLATE/Support_us.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: "❤️ Support us" -about: "If you would like to support our efforts in maintaining this project 🙌" - ---- - ---------------^ Click "Preview" for a nicer view! - -> https://nette.org/donate - -Help support Nette! - -We develop Nette Framework for more than 14 years. In order to make your life more comfortable. Nette cares about the safety of your sites. Nette saves you time. And gives job opportunities. - -Nette earns you money. And is absolutely free. - -To ensure future development and improving the documentation, we need your donation. - -Whether you are chief of IT company which benefits from Nette, or developer who goes for advice on our forum, if you like Nette, [please make a donation now](https://nette.org/donate). - -Thank you! diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 25adc9520..000000000 --- a/.github/funding.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: dg -custom: "https://nette.org/donate" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index f8aa3f408..000000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,11 +0,0 @@ -- bug fix / new feature? -- BC break? yes/no -- doc PR: nette/docs#??? - - diff --git a/contributing.md b/contributing.md deleted file mode 100644 index 184152c02..000000000 --- a/contributing.md +++ /dev/null @@ -1,33 +0,0 @@ -How to contribute & use the issue tracker -========================================= - -Nette welcomes your contributions. There are several ways to help out: - -* Create an issue on GitHub, if you have found a bug -* Write test cases for open bug issues -* Write fixes for open bug/feature issues, preferably with test cases included -* Contribute to the [documentation](https://nette.org/en/writing) - -Issues ------- - -Please **do not use the issue tracker to ask questions**. We will be happy to help you -on [Nette forum](https://forum.nette.org) or chat with us on [Gitter](https://gitter.im/nette/nette). - -A good bug report shouldn't leave others needing to chase you up for more -information. Please try to be as detailed as possible in your report. - -**Feature requests** are welcome. But take a moment to find out whether your idea -fits with the scope and aims of the project. It's up to *you* to make a strong -case to convince the project's developers of the merits of this feature. - -Contributing ------------- - -If you'd like to contribute, please take a moment to read [the contributing guide](https://nette.org/en/contributing). - -The best way to propose a feature is to discuss your ideas on [Nette forum](https://forum.nette.org) before implementing them. - -Please do not fix whitespace, format code, or make a purely cosmetic patch. - -Thanks! :heart: From 3f13230e914c2a597c88470b52c67601cc65bc34 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Jul 2021 12:44:47 +0200 Subject: [PATCH 16/22] used native PHP 8 functions --- src/Application/Application.php | 2 +- src/Application/UI/Component.php | 2 +- src/Application/UI/Presenter.php | 4 ++-- src/Bridges/ApplicationDI/LatteExtension.php | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 168f3e6e0..8e4cfe818 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -110,7 +110,7 @@ public function createInitialRequest(): Request throw new BadRequestException('No route for HTTP request.'); } elseif (!is_string($presenter)) { throw new Nette\InvalidStateException('Missing presenter in route definition.'); - } elseif (Nette\Utils\Strings::startsWith($presenter, 'Nette:') && $presenter !== 'Nette:Micro') { + } elseif (str_starts_with($presenter, 'Nette:') && $presenter !== 'Nette:Micro') { throw new BadRequestException('Invalid request. Presenter is not achievable.'); } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 17ba8c3b3..9b4c03613 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -120,7 +120,7 @@ public function checkRequirements($element): void { if ( $element instanceof \ReflectionMethod - && substr($element->getName(), 0, 6) === 'handle' + && str_starts_with($element->getName(), 'handle') && !ComponentReflection::parseAnnotation($element, 'crossOrigin') && !$element->getAttributes(Nette\Application\Attributes\CrossOrigin::class) && !$this->getPresenter()->getHttpRequest()->isSameSite() diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index d391a84b0..1a856af1b 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -154,7 +154,7 @@ public function getUniqueId(): string public function isModuleCurrent(string $module): bool { $current = Helpers::splitName($this->getName())[0]; - return Nette\Utils\Strings::startsWith($current . ':', ltrim($module . ':', ':')); + return str_starts_with($current . ':', ltrim($module . ':', ':')); } @@ -778,7 +778,7 @@ protected function createRequest( throw new InvalidLinkException("Unable to pass parameters to 'this!' signal."); } - } elseif (strpos($signal, self::NAME_SEPARATOR) === false) { + } elseif (!str_contains($signal, self::NAME_SEPARATOR)) { // counterpart of signalReceived() & tryCall() $method = $component->formatSignalMethod($signal); if (!$reflection->hasCallableMethod($method)) { diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index bca570d51..0dabc78aa 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -120,15 +120,15 @@ public function addMacro(string $macro): void $definition = $builder->getDefinition($this->prefix('latteFactory'))->getResultDefinition(); if (($macro[0] ?? null) === '@') { - if (strpos($macro, '::') === false) { - $method = 'install'; - } else { + if (str_contains($macro, '::')) { [$macro, $method] = explode('::', $macro); + } else { + $method = 'install'; } $definition->addSetup('?->onCompile[] = function ($engine) { ?->' . $method . '($engine->getCompiler()); }', ['@self', $macro]); } else { - if (strpos($macro, '::') === false && class_exists($macro)) { + if (!str_contains($macro, '::') && class_exists($macro)) { $macro .= '::install'; } $definition->addSetup('?->onCompile[] = function ($engine) { ' . $macro . '($engine->getCompiler()); }', ['@self']); From ba0b05c67a3383c3220a35b17e8ff87ed2a5d583 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 30 Aug 2021 10:18:19 +0200 Subject: [PATCH 17/22] Form: do not send 'do' when action is changed --- src/Application/UI/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index c27670682..3b6df55db 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -124,7 +124,7 @@ protected function beforeRender() { parent::beforeRender(); $key = ($this->isMethod('post') ? '_' : '') . Presenter::SIGNAL_KEY; - if (!isset($this[$key])) { + if (!isset($this[$key]) && $this->getAction() !== '') { $do = $this->lookupPath(Presenter::class) . self::NAME_SEPARATOR . 'submit'; $this[$key] = (new Nette\Forms\Controls\HiddenField($do))->setOmitted(); } From af52aa487576ee18b385cae07a5940e7396f2695 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Sep 2021 23:44:04 +0200 Subject: [PATCH 18/22] Component: only UI components can be added to presenter/component (BC break) WIP --- src/Application/UI/Component.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 9b4c03613..f8e5e2e55 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -66,14 +66,12 @@ public function getUniqueId(): string } - protected function createComponent(string $name): ?Nette\ComponentModel\IComponent + public function addComponent(Nette\ComponentModel\IComponent $component, ?string $name, string $insertBefore = null): static { - $res = parent::createComponent($name); - if ($res && !$res instanceof SignalReceiver && !$res instanceof StatePersistent) { - $type = $res::class; - trigger_error("It seems that component '$name' of type $type is not intended to be used in the Presenter.", E_USER_NOTICE); + if (!$component instanceof SignalReceiver && !$component instanceof StatePersistent) { + throw new Nette\InvalidStateException("Component '$name' of type " . gettype($component) . ' is not intended to be used in the Presenter.'); } - return $res; + return parent::addComponent($component, $name, $insertBefore = null); } From fba51b252a6378b5628c52524dd67281e57a1059 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 24 Sep 2021 14:06:27 +0200 Subject: [PATCH 19/22] removed magic properties except for $template & $payload (BC break) --- src/Application/Request.php | 6 ------ src/Application/UI/Component.php | 3 --- src/Application/UI/ComponentReflection.php | 2 -- src/Application/UI/Presenter.php | 7 ------- 4 files changed, 18 deletions(-) diff --git a/src/Application/Request.php b/src/Application/Request.php index b3bd616a4..c820174f0 100644 --- a/src/Application/Request.php +++ b/src/Application/Request.php @@ -14,12 +14,6 @@ /** * Presenter request. - * - * @property string $presenterName - * @property array $parameters - * @property array $post - * @property array $files - * @property string|null $method */ final class Request { diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index f8e5e2e55..f2373fed5 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -18,9 +18,6 @@ * Components are persistent objects located on a presenter. They have ability to own * other child components, and interact with user. Components have properties * for storing their status, and responds to user command. - * - * @property-read Presenter $presenter - * @property-read bool $linkCurrent */ abstract class Component extends Nette\ComponentModel\Container implements SignalReceiver, StatePersistent, \ArrayAccess { diff --git a/src/Application/UI/ComponentReflection.php b/src/Application/UI/ComponentReflection.php index 469211839..c9b9491da 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -14,8 +14,6 @@ /** * Helpers for Presenter & Component. - * @property-read string $name - * @property-read string $fileName * @internal */ final class ComponentReflection extends \ReflectionClass diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 1a856af1b..5a5d2cfb0 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -19,14 +19,7 @@ /** * Presenter component represents a webpage instance. It converts Request to Response. - * - * @property-read Nette\Application\Request $request - * @property-read string $action - * @property string $view - * @property string|bool $layout * @property-read \stdClass $payload - * @property-read Nette\Http\Session $session - * @property-read Nette\Security\User $user */ abstract class Presenter extends Control implements Application\IPresenter { From 7f1be6a350b4d9d1b70d25bd09b1d37d07b423de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sat, 25 Sep 2021 12:56:50 +0200 Subject: [PATCH 20/22] LinkGenerator: accept classname in $dest --- src/Application/LinkGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 160c7545b..52f28f4c9 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -36,7 +36,7 @@ public function __construct( */ public function link(string $dest, array $params = []): string { - if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()$~D', $dest, $m)) { + if (!preg_match('~^([\w\\\:]+):(\w*+)(#.*)?()$~D', $dest, $m)) { throw new UI\InvalidLinkException("Invalid link destination '$dest'."); } [, $presenter, $action, $frag] = $m; From b9f6f2a447c637493b902b25741f14cd97c94587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sun, 26 Sep 2021 20:31:04 +0200 Subject: [PATCH 21/22] LinkGenerator: presenter mapped name and class name are unmistakable --- src/Application/LinkGenerator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index 52f28f4c9..ec6e66fd3 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -31,12 +31,16 @@ public function __construct( /** * Generates URL to presenter. - * @param string $dest in format "[[[module:]presenter:]action] [#fragment]" + * @param string $dest in format "[[[module:]presenter:]action] [#fragment]" or "[[Class\Name:]action] [#fragment]" * @throws UI\InvalidLinkException */ public function link(string $dest, array $params = []): string { - if (!preg_match('~^([\w\\\:]+):(\w*+)(#.*)?()$~D', $dest, $m)) { + if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()$~D', $dest, $m) + && !preg_match('~^(\\?\w+(?:\\{1}\w+)+):(\w*+)(#.*)?()$~D', $dest, $m) + ) { + throw new UI\InvalidLinkException("Invalid link destination '$dest'."); + } throw new UI\InvalidLinkException("Invalid link destination '$dest'."); } [, $presenter, $action, $frag] = $m; From 38666ca7383f9574ac0a6a0b9a1c5116e018d8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sun, 26 Sep 2021 20:44:29 +0200 Subject: [PATCH 22/22] LinkGenerator: add character class to regex to match properly --- src/Application/LinkGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/LinkGenerator.php b/src/Application/LinkGenerator.php index ec6e66fd3..f52638859 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -37,7 +37,7 @@ public function __construct( public function link(string $dest, array $params = []): string { if (!preg_match('~^([\w:]+):(\w*+)(#.*)?()$~D', $dest, $m) - && !preg_match('~^(\\?\w+(?:\\{1}\w+)+):(\w*+)(#.*)?()$~D', $dest, $m) + && !preg_match('~^([\\\]?\w+(?:[\\\]{1}\w+)+):(\w*+)(#.*)?()$~D', $dest, $m) ) { throw new UI\InvalidLinkException("Invalid link destination '$dest'."); }