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/.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 eb1121be2..f2242cbfb 100644 --- a/composer.json +++ b/composer.json @@ -15,25 +15,25 @@ } ], "require": { - "php": ">=7.2", - "nette/component-model": "^3.0", - "nette/http": "^3.0.2", - "nette/routing": "^3.0.2", - "nette/utils": "^3.2.1" + "php": ">=8.0 <8.2", + "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": { @@ -54,7 +54,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } } } 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: diff --git a/src/Application/Application.php b/src/Application/Application.php index ed26eb5a3..8e4cfe818 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,29 +47,24 @@ 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( IPresenterFactory $presenterFactory, Router $router, Nette\Http\IRequest $httpRequest, - Nette\Http\IResponse $httpResponse + Nette\Http\IResponse $httpResponse, ) { $this->httpRequest = $httpRequest; $this->httpResponse = $httpResponse; @@ -117,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.'); } @@ -128,7 +121,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/ErrorPresenter.php b/src/Application/ErrorPresenter.php index df698a62d..b027f07c3 100644 --- a/src/Application/ErrorPresenter.php +++ b/src/Application/ErrorPresenter.php @@ -22,13 +22,9 @@ final class ErrorPresenter implements Application\IPresenter { use Nette\SmartObject; - /** @var ILogger|null */ - private $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 19c98d330..f52638859 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/LinkGenerator.php @@ -21,32 +21,26 @@ final class LinkGenerator { use Nette\SmartObject; - /** @var Router */ - private $router; - - /** @var UrlScript */ - private $refUrl; - - /** @var IPresenterFactory|null */ - private $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, + ) { } /** * 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; @@ -93,12 +87,12 @@ 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, new UrlScript($url), - $this->presenterFactory + $this->presenterFactory, ); } } diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index 5a2960622..1a3cc3230 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -24,27 +24,14 @@ final class MicroPresenter implements Application\IPresenter { use Nette\SmartObject; - /** @var Nette\DI\Container|null */ - private $context; - - /** @var Nette\Http\IRequest|null */ - private $httpRequest; - - /** @var Router|null */ - private $router; - - /** @var Application\Request|null */ - private $request; + 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/PresenterFactory.php b/src/Application/PresenterFactory.php index 45bad8b9c..1b6590433 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; @@ -37,7 +36,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; } @@ -84,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)) { @@ -120,22 +118,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/Request.php b/src/Application/Request.php index f87cb13a7..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 { @@ -37,50 +31,25 @@ final class Request /** flag */ public const VARYING = 'varying'; - /** @var string|null */ - private $method; - - /** @var array */ - private $flags = []; - - /** @var string */ - private $name; - - /** @var array */ - private $params; - - /** @var array */ - private $post; - - /** @var array */ - private $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; } /** * Sets the presenter name. - * @return static */ - public function setPresenterName(string $name) + public function setPresenterName(string $name): static { $this->name = $name; return $this; @@ -98,9 +67,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; @@ -118,9 +86,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; } @@ -128,9 +95,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; @@ -140,9 +106,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 @@ -152,9 +117,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; @@ -172,9 +136,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; @@ -201,9 +164,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/FileResponse.php b/src/Application/Responses/FileResponse.php index 6e5793629..8dd9efbcc 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -19,27 +19,22 @@ 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( 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 +84,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 +121,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/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..93dbcfdad 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) @@ -33,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/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..439a2b32d 100644 --- a/src/Application/Responses/TextResponse.php +++ b/src/Application/Responses/TextResponse.php @@ -19,23 +19,16 @@ final class TextResponse implements Nette\Application\Response { use Nette\SmartObject; - /** @var mixed */ - private $source; + 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/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/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..fb9407210 100644 --- a/src/Application/Routers/RouteList.php +++ b/src/Application/Routers/RouteList.php @@ -15,12 +15,11 @@ /** * 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'; - /** @var string|null */ - private $module; + private ?string $module; public function __construct(string $module = null) @@ -65,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 . ':'; @@ -93,14 +88,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 @@ -117,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'); @@ -150,14 +135,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/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 0d4a8bc26..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 { @@ -29,21 +26,15 @@ 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 = []; /** * 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 +43,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); } @@ -73,14 +63,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 = get_class($res); - 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); } @@ -96,7 +84,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 { @@ -128,9 +115,9 @@ 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') - && (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(); @@ -164,7 +151,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]; @@ -187,9 +174,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; } @@ -324,7 +310,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..c9b9491da 100644 --- a/src/Application/UI/ComponentReflection.php +++ b/src/Application/UI/ComponentReflection.php @@ -14,22 +14,20 @@ /** * Helpers for Presenter & Component. - * @property-read string $name - * @property-read string $fileName * @internal */ 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 = []; /** @@ -38,7 +36,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; @@ -50,7 +48,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] = [ @@ -74,7 +72,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 +96,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 +119,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 +164,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 +177,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(), )); } } @@ -251,7 +249,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 { @@ -283,7 +280,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)); @@ -301,9 +298,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 bfc307a33..288d81aa1 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; @@ -52,14 +48,14 @@ 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 + 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(); + $class ??= $this->formatTemplateClass(); + $templateFactory = $this->templateFactory ?? $this->getPresenter()->getTemplateFactory(); return $templateFactory->createTemplate($this, $class); } @@ -80,7 +76,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 { @@ -99,9 +95,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/Form.php b/src/Application/UI/Form.php index 4544dffd6..3b6df55db 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. @@ -65,13 +62,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 +73,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); } @@ -100,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(); } @@ -141,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(); } diff --git a/src/Application/UI/Link.php b/src/Application/UI/Link.php index 7236be96f..687a331b2 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; /** @@ -61,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; @@ -72,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; } @@ -103,15 +98,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/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 3f08163e2..5a5d2cfb0 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -19,15 +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\DI\Container $context - * @property-read Nette\Http\Session $session - * @property-read Nette\Security\User $user */ abstract class Presenter extends Control implements Application\IPresenter { @@ -46,8 +38,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 = []; @@ -58,83 +49,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\DI\Container */ - private $context; + private Nette\Http\IRequest $httpRequest; - /** @var Nette\Http\IRequest */ - private $httpRequest; + private Nette\Http\IResponse $httpResponse; - /** @var Nette\Http\IResponse */ - private $httpResponse; + private ?Nette\Http\Session $session = null; - /** @var Nette\Http\Session */ - private $session; + private ?Nette\Application\IPresenterFactory $presenterFactory = null; - /** @var Nette\Application\IPresenterFactory */ - private $presenterFactory; + private ?Nette\Routing\Router $router = null; - /** @var Nette\Routing\Router */ - private $router; + private ?Nette\Security\User $user = null; - /** @var Nette\Security\User */ - private $user; + private ?TemplateFactory $templateFactory = null; - /** @var TemplateFactory */ - private $templateFactory; - - /** @var Nette\Http\UrlScript */ - private $refUrlCache; + private Nette\Http\UrlScript $refUrlCache; public function __construct() @@ -152,19 +117,18 @@ 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; } - /** @deprecated */ final public function hasPresenter(): bool { return true; @@ -183,7 +147,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 . ':', ':')); } @@ -195,7 +159,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()) { @@ -294,17 +258,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 { } @@ -326,7 +286,7 @@ public function detectedCsrf(): void */ public function processSignal(): void { - if ($this->signal === null) { + if (!isset($this->signal)) { return; } @@ -356,9 +316,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 @@ -414,9 +373,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; @@ -425,9 +383,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; } @@ -435,10 +392,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; @@ -451,7 +406,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) { @@ -552,14 +507,9 @@ public static function formatRenderMethod(string $view): string } - /** - * @param string $class - */ - 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); } @@ -586,7 +536,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; @@ -606,11 +556,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)); } @@ -644,12 +593,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)); @@ -719,7 +667,7 @@ public function canonicalize(string $destination = null, array $args = []): void $this, $destination ?: $this->action, $args + $this->getGlobalState() + $request->getParameters(), - 'redirectX' + 'redirectX', ); } catch (InvalidLinkException $e) { } @@ -736,13 +684,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); } @@ -757,7 +707,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 */ @@ -765,7 +714,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,21 +764,27 @@ 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)) { 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)) { 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); + static::argsToParams($component::class, $method, $args, [], $missing); } // counterpart of StatePersistent @@ -855,6 +810,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 +829,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); } @@ -954,7 +918,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()); } @@ -992,7 +956,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); @@ -1032,7 +996,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]), )); } @@ -1072,7 +1036,6 @@ protected function handleInvalidLink(InvalidLinkException $e): string /** * Stores current request to session. - * @return string key */ public function storeRequest(string $expiration = '+ 10 minutes'): string { @@ -1120,9 +1083,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'); @@ -1136,7 +1097,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; @@ -1332,20 +1293,18 @@ public function getFlashSession(): Http\SessionSection final public function injectPrimary( - ?Nette\DI\Container $context, ?Application\IPresenterFactory $presenterFactory, ?Nette\Routing\Router $router, Http\IRequest $httpRequest, Http\IResponse $httpResponse, ?Http\Session $session = null, ?Nette\Security\User $user = null, - ?TemplateFactory $templateFactory = 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.'); } - $this->context = $context; $this->presenterFactory = $presenterFactory; $this->router = $router; $this->httpRequest = $httpRequest; @@ -1356,20 +1315,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; @@ -1382,10 +1327,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/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 a1e7f15e0..98361d845 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -22,32 +22,18 @@ */ final class ApplicationExtension extends Nette\DI\CompilerExtension { - /** @var bool */ - private $debugMode; + private array $scanDirs; - /** @var array */ - private $scanDirs; - - /** @var Nette\Loaders\RobotLoader|null */ - private $robotLoader; - - /** @var int */ - private $invalidLinkMode; - - /** @var string|null */ - private $tempDir; + private int $invalidLinkMode; 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; } @@ -56,11 +42,11 @@ 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(), - false + false, )->firstIsDefault(), 'scanComposer' => Expect::bool(class_exists(ClassLoader::class)), 'scanFilter' => Expect::string('*Presenter'), @@ -95,7 +81,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 +168,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 +191,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..0dabc78aa 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) @@ -39,7 +37,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 +58,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]); @@ -102,7 +97,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 +107,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() : '', )); } }; @@ -125,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']); diff --git a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php index 1f8b21107..d537eeadc 100644 --- a/src/Bridges/ApplicationDI/PresenterFactoryCallback.php +++ b/src/Bridges/ApplicationDI/PresenterFactoryCallback.php @@ -18,21 +18,11 @@ */ final class PresenterFactoryCallback { - /** @var Nette\DI\Container */ - private $container; - - /** @var int */ - private $invalidLinkMode; - - /** @var string|null */ - private $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/ApplicationDI/RoutingExtension.php b/src/Bridges/ApplicationDI/RoutingExtension.php index 21142a74c..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) @@ -35,7 +34,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 +50,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/src/Bridges/ApplicationLatte/DefaultTemplate.php b/src/Bridges/ApplicationLatte/DefaultTemplate.php index d20a576fa..0649e0586 100644 --- a/src/Bridges/ApplicationLatte/DefaultTemplate.php +++ b/src/Bridges/ApplicationLatte/DefaultTemplate.php @@ -20,30 +20,24 @@ */ 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 = []; /** * 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."); @@ -55,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/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 72a4248dc..c1f844083 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) @@ -59,19 +57,10 @@ public function renderToString(string $file = null, array $params = []): string /** * Renders template to string. - * @param can throw exceptions? (hidden parameter) */ 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()); } @@ -80,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; @@ -91,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; @@ -102,15 +89,15 @@ 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', 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; } @@ -120,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; @@ -142,7 +128,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/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 90d8adbb2..1fa6853a9 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -24,33 +24,16 @@ class TemplateFactory implements UI\TemplateFactory /** @var array Occurs when a new template is created */ public $onCreate = []; - /** @var LatteFactory */ - private $latteFactory; - - /** @var Nette\Http\IRequest|null */ - private $httpRequest; - - /** @var Nette\Security\User|null */ - private $user; - - /** @var Nette\Caching\Storage|null */ - private $cacheStorage; - - /** @var string */ - private $templateClass; + private string $templateClass; public function __construct( - LatteFactory $latteFactory, - Nette\Http\IRequest $httpRequest = null, - Nette\Security\User $user = null, - Nette\Caching\Storage $cacheStorage = null, - $templateClass = 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.'); } @@ -58,10 +41,9 @@ 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 = $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 +69,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..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 @@ -38,9 +36,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 +115,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 +134,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 +150,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 8a16745c7..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 @@ -40,32 +40,33 @@ 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) { - $name = preg_replace('#(Control|Presenter)$#', '', get_class($control)) . 'Template'; + $name = preg_replace('#(Control|Presenter)$#', '', $control::class) . 'Template'; 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); diff --git a/src/Bridges/ApplicationTracy/RoutingPanel.php b/src/Bridges/ApplicationTracy/RoutingPanel.php index 0b068387c..415f57885 100644 --- a/src/Bridges/ApplicationTracy/RoutingPanel.php +++ b/src/Bridges/ApplicationTracy/RoutingPanel.php @@ -22,29 +22,24 @@ 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( Routing\Router $router, Nette\Http\IRequest $httpRequest, - Nette\Application\IPresenterFactory $presenterFactory + Nette\Application\IPresenterFactory $presenterFactory, ) { $this->router = $router; $this->httpRequest = $httpRequest; @@ -74,7 +69,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 +85,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 +132,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/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/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..ccbd8e8bb 100644 --- a/tests/Application/Presenter.twoDomains.phpt +++ b/tests/Application/Presenter.twoDomains.phpt @@ -28,11 +28,10 @@ function testLink($domain) $presenter = new TestPresenter; $presenter->injectPrimary( - null, 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..a1114bbd9 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,15 +41,14 @@ class FooMacros extends Latte\Macros\MacroSet { $me = new static($compiler); $me->addMacro('foo', 'foo'); - Notes::add(get_class($me)); + Notes::add($me::class); } } class NonStaticMacrosFactory { - /** @var string */ - private $parameter; + private string $parameter; public function __construct($parameter) 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/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.customTemplate.phpt b/tests/Bridges.Latte/TemplateFactory.customTemplate.phpt index 88a90e7c9..99baf1bbd 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 @@ -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/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..39a30a13a 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, ], ]); @@ -58,8 +54,7 @@ Assert::null(testRouteOut($route, [ class RouterObject { - /** @var int */ - private $id; + private int $id; public function __construct($id) 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.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/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..54aef1817 100644 --- a/tests/UI/Component.isLinkCurrent().asserts.php +++ b/tests/UI/Component.isLinkCurrent().asserts.php @@ -30,11 +30,10 @@ function callIsComponentLinkCurrent( $presenterFactory->shouldReceive('getPresenterClass')->andReturn('TestPresenter'); $presenter->injectPrimary( - null, $presenterFactory, new Application\Routers\SimpleRouter, new Http\Request($url), - new Http\Response + new Http\Response, ); $presenter->run($request); @@ -45,31 +44,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 +77,7 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -87,7 +86,7 @@ function callIsComponentLinkCurrent( [ 'bool' => false, 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -96,7 +95,7 @@ function callIsComponentLinkCurrent( [ 'bool' => false, 'int' => 2, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -105,7 +104,7 @@ function callIsComponentLinkCurrent( [ 'bool' => true, 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( @@ -114,31 +113,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 +145,7 @@ function callIsComponentLinkCurrent( 'Test:*', [ 'int' => 1, - ] + ], )); Assert::false(callIsLinkCurrent( @@ -154,7 +153,7 @@ function callIsComponentLinkCurrent( 'Test:*', [ 'int' => 1, - ] + ], )); Assert::true(callIsLinkCurrent( @@ -164,7 +163,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'Test:default', - [] + [], )); Assert::true(callIsLinkCurrent( @@ -174,7 +173,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'signal!', - [] + [], )); Assert::false(callIsLinkCurrent( @@ -184,7 +183,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'otherSignal!', - [] + [], )); @@ -198,7 +197,7 @@ function callIsComponentLinkCurrent( 'Test:default', [ Application\UI\Presenter::ACTION_KEY => 'otherAction', - ] + ], )); Assert::false(callIsLinkCurrent( @@ -210,7 +209,7 @@ function callIsComponentLinkCurrent( 'Test:otherAction', [ Application\UI\Presenter::ACTION_KEY => 'default', - ] + ], )); @@ -224,7 +223,7 @@ function callIsComponentLinkCurrent( 'signal!', [ Application\UI\Presenter::SIGNAL_KEY => 'otherSignal', - ] + ], )); Assert::false(callIsLinkCurrent( @@ -236,7 +235,7 @@ function callIsComponentLinkCurrent( 'otherSignal!', [ Application\UI\Presenter::SIGNAL_KEY => 'signal', - ] + ], )); @@ -253,7 +252,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'click!', - [] + [], )); $testPresenter = new TestPresenter; @@ -268,7 +267,7 @@ function callIsComponentLinkCurrent( 'bool' => true, ]), 'otherSignal!', - [] + [], )); $testPresenter = new TestPresenter; @@ -286,7 +285,7 @@ function callIsComponentLinkCurrent( 'click!', [ 'x' => 1, - ] + ], )); $testPresenter = new TestPresenter; @@ -304,7 +303,7 @@ function callIsComponentLinkCurrent( 'click!', [ 'x' => 2, - ] + ], )); $testPresenter = new TestPresenter; @@ -323,7 +322,7 @@ function callIsComponentLinkCurrent( 'test:click!', [ 'x' => 1, - ] + ], )); $testPresenter = new TestPresenter; @@ -342,5 +341,5 @@ function callIsComponentLinkCurrent( 'test:click!', [ 'x' => 2, - ] + ], )); diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt index 2a749c432..e4e53f09b 100644 --- a/tests/UI/Component.redirect().phpt +++ b/tests/UI/Component.redirect().phpt @@ -34,11 +34,10 @@ 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')), - new Http\Response + new Http\Response, ); 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.'); +}); 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 d519f2673..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(); @@ -138,17 +138,14 @@ $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( - null, $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..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; @@ -299,17 +299,14 @@ $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( - null, $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..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; @@ -285,17 +285,14 @@ $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( - null, $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..a2754b9a8 100644 --- a/tests/UI/Presenter.paramChecking.phpt +++ b/tests/UI/Presenter.paramChecking.phpt @@ -17,11 +17,10 @@ require __DIR__ . '/../bootstrap.php'; $presenter = new ParamPresenter; $presenter->injectPrimary( - null, null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), - new Http\Response + new Http\Response, ); diff --git a/tests/UI/Presenter.parameters.phpt b/tests/UI/Presenter.parameters.phpt index c55be4093..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; @@ -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 d32861228..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'; } @@ -118,13 +119,12 @@ class MockUser extends Security\User test('', function () { $presenter = new TestPresenter; $presenter->injectPrimary( - null, null, new Application\Routers\SimpleRouter, new Http\Request(new Http\UrlScript), new Http\Response, $session = new MockSession, - $user = new MockUser + $user = new MockUser, ); $section = $session->testSection = new MockSessionSection($session); @@ -145,12 +145,11 @@ test('', function () { test('', function () { $presenter = new TestPresenter; $presenter->injectPrimary( - null, null, 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); 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