Skip to content

Commit 23901a9

Browse files
committed
doplnení striktních typů
1 parent 2a33b47 commit 23901a9

6 files changed

+48
-30
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ composer:
33
composer update --no-interaction --prefer-dist
44

55
phpstan:
6-
vendor/bin/phpstan analyse -l 5 -c phpstan.neon src/
6+
vendor/bin/phpstan analyse -l 9 -c phpstan.neon src/
77

88
run-tests:
99
vendor/bin/tester tests -d extension=tokenizer.so

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
ignoreErrors:
3+
- '#Cannot call method getParameter\(\) on Nette\\Application\\UI\\Presenter\|null\.#'
4+
- '#Cannot cast mixed to string#'
35
fileExtensions:
46
- phpt
57

src/UI/AsyncControlLink.php

+27-16
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,53 @@
55
final class AsyncControlLink
66
{
77

8-
private static $defaultMessage = 'Load content';
9-
private static $defaultAttributes = [];
8+
private static string $defaultMessage = 'Load content';
9+
1010
/**
11-
* @var string
11+
* @var array<string, string>
1212
*/
13-
private $message;
13+
private static array $defaultAttributes = [];
14+
15+
private string $message;
16+
1417
/**
15-
* @var array
18+
* @var array<string, string>
1619
*/
17-
private $attributes;
18-
20+
private array $attributes;
1921

22+
/**
23+
* @param string|null $message
24+
* @param array<string, string> $attributes
25+
*/
2026
public function __construct(
21-
string $message = NULL,
22-
array $attributes = NULL
23-
) {
24-
$this->message = $message === NULL ? self::$defaultMessage : $message;
25-
$this->attributes = $attributes === NULL ? self::$defaultAttributes : $attributes;
27+
?string $message = null,
28+
?array $attributes = null
29+
)
30+
{
31+
$this->message = $message === null ? self::$defaultMessage : $message;
32+
$this->attributes = $attributes === null ? self::$defaultAttributes : $attributes;
2633
}
2734

28-
29-
public static function setDefault(string $message, array $attributes = [])
35+
/**
36+
* @param array<string, string> $attributes
37+
*/
38+
public static function setDefault(string $message, array $attributes = []): void
3039
{
3140
self::$defaultMessage = $message;
3241
self::$defaultAttributes = $attributes;
3342
}
3443

35-
3644
public function getMessage(): string
3745
{
3846
return $this->message;
3947
}
4048

41-
49+
/**
50+
* @return array<string, string>
51+
*/
4252
public function getAttributes(): array
4353
{
4454
return $this->attributes;
4555
}
56+
4657
}

src/UI/AsyncControlTrait.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait AsyncControlTrait
1919
protected $asyncRenderer;
2020

2121

22-
public function handleAsyncLoad()
22+
public function handleAsyncLoad(): void
2323
{
2424
if ( ! $this instanceof Control || ! ($presenter = $this->getPresenter(FALSE)) || ! $presenter->isAjax()) {
2525
return;
@@ -37,8 +37,11 @@ public function handleAsyncLoad()
3737
$presenter->sendPayload();
3838
}
3939

40-
41-
public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL)
40+
/**
41+
* @param array<string, string> $linkAttributes
42+
* @return void
43+
*/
44+
public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL): void
4245
{
4346
if (
4447
$this instanceof Control
@@ -59,7 +62,7 @@ public function renderAsync(string $linkMessage = NULL, array $linkAttributes =
5962
}
6063

6164

62-
public function setAsyncRenderer(callable $renderer)
65+
public function setAsyncRenderer(callable $renderer): void
6366
{
6467
$this->asyncRenderer = $renderer;
6568
}

tests/UI/AsyncControlLinkTest.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require_once __DIR__ . '/../../vendor/autoload.php';
1212
final class AsyncControlLinkTest extends TestCase
1313
{
1414

15-
public function testLink()
15+
public function testLink(): void
1616
{
1717
$link = new AsyncControlLink;
1818
Assert::equal('Load content', $link->getMessage());

tests/UI/AsyncControlTest.phpt

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ use Tester\TestCase;
1212

1313
require_once __DIR__ . '/../../vendor/autoload.php';
1414

15-
15+
/**
16+
* @testCase
17+
*/
1618
final class AsyncControlTest extends TestCase
1719
{
1820

1921
const VALID_SIGNAL = 'control-form-submit';
2022
const FRAGMENT_PARAMETER = '_escaped_fragment_';
2123

2224

23-
public function testHandleAjax()
25+
public function testHandleAjax(): void
2426
{
2527
$presenter = Mockery::mock(Presenter::class);
2628
$presenter->shouldReceive('isAjax')->once()->andReturn(TRUE);
@@ -43,7 +45,7 @@ final class AsyncControlTest extends TestCase
4345
}
4446

4547

46-
public function testHandleNoAjax()
48+
public function testHandleNoAjax(): void
4749
{
4850
$presenter = Mockery::mock(Presenter::class);
4951
$presenter->shouldReceive('isAjax')->once()->andReturn(FALSE);
@@ -60,7 +62,7 @@ final class AsyncControlTest extends TestCase
6062
}
6163

6264

63-
public function testRenderAsyncLoadLink()
65+
public function testRenderAsyncLoadLink(): void
6466
{
6567
/**
6668
* @var AsyncControl|Mockery\Mock $control
@@ -85,7 +87,7 @@ final class AsyncControlTest extends TestCase
8587
}
8688

8789

88-
public function testRenderWithSignal()
90+
public function testRenderWithSignal(): void
8991
{
9092
$presenter = Mockery::mock(Presenter::class);
9193
$presenter->shouldReceive('getParameter')->once()->with(self::FRAGMENT_PARAMETER)->andReturn(NULL);
@@ -101,7 +103,7 @@ final class AsyncControlTest extends TestCase
101103
}
102104

103105

104-
public function testRenderWithFragment()
106+
public function testRenderWithFragment(): void
105107
{
106108
$presenter = Mockery::mock(Presenter::class);
107109
$presenter->shouldReceive('getParameter')->once()->with(self::FRAGMENT_PARAMETER)->andReturn('');
@@ -115,7 +117,7 @@ final class AsyncControlTest extends TestCase
115117
}
116118

117119

118-
public function testRenderAsyncRenderer()
120+
public function testRenderAsyncRenderer(): void
119121
{
120122
$presenter = Mockery::mock(Presenter::class);
121123
$presenter->shouldReceive('getParameter')->once()->with(self::FRAGMENT_PARAMETER)->andReturn(NULL);
@@ -135,7 +137,7 @@ final class AsyncControlTest extends TestCase
135137
}
136138

137139

138-
protected function tearDown()
140+
protected function tearDown(): void
139141
{
140142
parent::tearDown();
141143
Mockery::close();

0 commit comments

Comments
 (0)