Skip to content

Commit

Permalink
doplnení striktních typů
Browse files Browse the repository at this point in the history
  • Loading branch information
krejzyeu committed Jan 10, 2024
1 parent 2a33b47 commit 23901a9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
parameters:
ignoreErrors:
- '#Cannot call method getParameter\(\) on Nette\\Application\\UI\\Presenter\|null\.#'
- '#Cannot cast mixed to string#'
fileExtensions:
- phpt

Expand Down
43 changes: 27 additions & 16 deletions src/UI/AsyncControlLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
*/
private $message;
private static array $defaultAttributes = [];

private string $message;

/**
* @var array
* @var array<string, string>
*/
private $attributes;

private array $attributes;

/**
* @param string|null $message
* @param array<string, string> $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<string, string> $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<string, string>
*/
public function getAttributes(): array
{
return $this->attributes;
}

}
11 changes: 7 additions & 4 deletions src/UI/AsyncControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,8 +37,11 @@ public function handleAsyncLoad()
$presenter->sendPayload();
}


public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL)
/**
* @param array<string, string> $linkAttributes
* @return void
*/
public function renderAsync(string $linkMessage = NULL, array $linkAttributes = NULL): void
{
if (
$this instanceof Control
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/UI/AsyncControlLinkTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
18 changes: 10 additions & 8 deletions tests/UI/AsyncControlTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ use Tester\TestCase;

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


/**
* @testCase
*/
final class AsyncControlTest extends TestCase
{

const VALID_SIGNAL = 'control-form-submit';
const FRAGMENT_PARAMETER = '_escaped_fragment_';


public function testHandleAjax()
public function testHandleAjax(): void
{
$presenter = Mockery::mock(Presenter::class);
$presenter->shouldReceive('isAjax')->once()->andReturn(TRUE);
Expand All @@ -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);
Expand All @@ -60,7 +62,7 @@ final class AsyncControlTest extends TestCase
}


public function testRenderAsyncLoadLink()
public function testRenderAsyncLoadLink(): void
{
/**
* @var AsyncControl|Mockery\Mock $control
Expand All @@ -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);
Expand All @@ -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('');
Expand All @@ -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);
Expand All @@ -135,7 +137,7 @@ final class AsyncControlTest extends TestCase
}


protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
Mockery::close();
Expand Down

0 comments on commit 23901a9

Please sign in to comment.