From 23901a91f1a6ee8ea0f791836b4ac197573797bd Mon Sep 17 00:00:00 2001 From: krejzyeu Date: Thu, 21 Dec 2023 13:32:24 +0100 Subject: [PATCH] =?UTF-8?q?doplnen=C3=AD=20striktn=C3=ADch=20typ=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- phpstan.neon | 2 ++ src/UI/AsyncControlLink.php | 43 +++++++++++++++++++----------- src/UI/AsyncControlTrait.php | 11 +++++--- tests/UI/AsyncControlLinkTest.phpt | 2 +- tests/UI/AsyncControlTest.phpt | 18 +++++++------ 6 files changed, 48 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 42182e2..c24a2ee 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ composer: composer update --no-interaction --prefer-dist phpstan: - vendor/bin/phpstan analyse -l 5 -c phpstan.neon src/ + vendor/bin/phpstan analyse -l 9 -c phpstan.neon src/ run-tests: vendor/bin/tester tests -d extension=tokenizer.so diff --git a/phpstan.neon b/phpstan.neon index 65c46ea..67ed4fa 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,7 @@ parameters: ignoreErrors: + - '#Cannot call method getParameter\(\) on Nette\\Application\\UI\\Presenter\|null\.#' + - '#Cannot cast mixed to string#' fileExtensions: - phpt diff --git a/src/UI/AsyncControlLink.php b/src/UI/AsyncControlLink.php index 01b5b06..8310f14 100644 --- a/src/UI/AsyncControlLink.php +++ b/src/UI/AsyncControlLink.php @@ -5,42 +5,53 @@ final class AsyncControlLink { - private static $defaultMessage = 'Load content'; - private static $defaultAttributes = []; + private static string $defaultMessage = 'Load content'; + /** - * @var string + * @var array */ - private $message; + private static array $defaultAttributes = []; + + private string $message; + /** - * @var array + * @var array */ - private $attributes; - + private array $attributes; + /** + * @param string|null $message + * @param array $attributes + */ public function __construct( - string $message = NULL, - array $attributes = NULL - ) { - $this->message = $message === NULL ? self::$defaultMessage : $message; - $this->attributes = $attributes === NULL ? self::$defaultAttributes : $attributes; + ?string $message = null, + ?array $attributes = null + ) + { + $this->message = $message === null ? self::$defaultMessage : $message; + $this->attributes = $attributes === null ? self::$defaultAttributes : $attributes; } - - public static function setDefault(string $message, array $attributes = []) + /** + * @param array $attributes + */ + public static function setDefault(string $message, array $attributes = []): void { self::$defaultMessage = $message; self::$defaultAttributes = $attributes; } - public function getMessage(): string { return $this->message; } - + /** + * @return array + */ public function getAttributes(): array { return $this->attributes; } + } diff --git a/src/UI/AsyncControlTrait.php b/src/UI/AsyncControlTrait.php index af66002..7b84c66 100644 --- a/src/UI/AsyncControlTrait.php +++ b/src/UI/AsyncControlTrait.php @@ -19,7 +19,7 @@ trait AsyncControlTrait protected $asyncRenderer; - public function handleAsyncLoad() + public function handleAsyncLoad(): void { if ( ! $this instanceof Control || ! ($presenter = $this->getPresenter(FALSE)) || ! $presenter->isAjax()) { return; @@ -37,8 +37,11 @@ public function handleAsyncLoad() $presenter->sendPayload(); } - - public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL) + /** + * @param array $linkAttributes + * @return void + */ + public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL): void { if ( $this instanceof Control @@ -59,7 +62,7 @@ public function renderAsync(string $linkMessage = NULL, array $linkAttributes = } - public function setAsyncRenderer(callable $renderer) + public function setAsyncRenderer(callable $renderer): void { $this->asyncRenderer = $renderer; } diff --git a/tests/UI/AsyncControlLinkTest.phpt b/tests/UI/AsyncControlLinkTest.phpt index 4ba35d6..39d5775 100644 --- a/tests/UI/AsyncControlLinkTest.phpt +++ b/tests/UI/AsyncControlLinkTest.phpt @@ -12,7 +12,7 @@ require_once __DIR__ . '/../../vendor/autoload.php'; final class AsyncControlLinkTest extends TestCase { - public function testLink() + public function testLink(): void { $link = new AsyncControlLink; Assert::equal('Load content', $link->getMessage()); diff --git a/tests/UI/AsyncControlTest.phpt b/tests/UI/AsyncControlTest.phpt index 076ddf8..ae69bdc 100644 --- a/tests/UI/AsyncControlTest.phpt +++ b/tests/UI/AsyncControlTest.phpt @@ -12,7 +12,9 @@ use Tester\TestCase; require_once __DIR__ . '/../../vendor/autoload.php'; - +/** + * @testCase + */ final class AsyncControlTest extends TestCase { @@ -20,7 +22,7 @@ final class AsyncControlTest extends TestCase const FRAGMENT_PARAMETER = '_escaped_fragment_'; - public function testHandleAjax() + public function testHandleAjax(): void { $presenter = Mockery::mock(Presenter::class); $presenter->shouldReceive('isAjax')->once()->andReturn(TRUE); @@ -43,7 +45,7 @@ final class AsyncControlTest extends TestCase } - public function testHandleNoAjax() + public function testHandleNoAjax(): void { $presenter = Mockery::mock(Presenter::class); $presenter->shouldReceive('isAjax')->once()->andReturn(FALSE); @@ -60,7 +62,7 @@ final class AsyncControlTest extends TestCase } - public function testRenderAsyncLoadLink() + public function testRenderAsyncLoadLink(): void { /** * @var AsyncControl|Mockery\Mock $control @@ -85,7 +87,7 @@ final class AsyncControlTest extends TestCase } - public function testRenderWithSignal() + public function testRenderWithSignal(): void { $presenter = Mockery::mock(Presenter::class); $presenter->shouldReceive('getParameter')->once()->with(self::FRAGMENT_PARAMETER)->andReturn(NULL); @@ -101,7 +103,7 @@ final class AsyncControlTest extends TestCase } - public function testRenderWithFragment() + public function testRenderWithFragment(): void { $presenter = Mockery::mock(Presenter::class); $presenter->shouldReceive('getParameter')->once()->with(self::FRAGMENT_PARAMETER)->andReturn(''); @@ -115,7 +117,7 @@ final class AsyncControlTest extends TestCase } - public function testRenderAsyncRenderer() + public function testRenderAsyncRenderer(): void { $presenter = Mockery::mock(Presenter::class); $presenter->shouldReceive('getParameter')->once()->with(self::FRAGMENT_PARAMETER)->andReturn(NULL); @@ -135,7 +137,7 @@ final class AsyncControlTest extends TestCase } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); Mockery::close();