Skip to content

Commit 33b0e9d

Browse files
committed
Tests: add types
1 parent 2c1c867 commit 33b0e9d

18 files changed

+52
-79
lines changed

src/DI/EventBridgesExtension.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
class EventBridgesExtension extends CompilerExtension
1414
{
1515

16+
/** @var array<string, class-string<CompilerExtension>> */
17+
private array $map = [
18+
'application' => EventApplicationBridgeExtension::class,
19+
'latte' => EventLatteBridgeExtension::class,
20+
'security' => EventSecurityBridgeExtension::class,
21+
];
22+
23+
/** @var array<string, CompilerExtension> */
24+
private array $passes = [];
25+
1626
public function getConfigSchema(): Schema
1727
{
1828
return Expect::structure([
@@ -22,16 +32,6 @@ public function getConfigSchema(): Schema
2232
])->castTo('array');
2333
}
2434

25-
/** @var array<string, class-string<CompilerExtension>> */
26-
private $map = [
27-
'application' => EventApplicationBridgeExtension::class,
28-
'latte' => EventLatteBridgeExtension::class,
29-
'security' => EventSecurityBridgeExtension::class,
30-
];
31-
32-
/** @var array<string, CompilerExtension> */
33-
private $passes = [];
34-
3535
/**
3636
* Register services
3737
*/
@@ -74,7 +74,7 @@ public function beforeCompile(): void
7474
/**
7575
* Decorate initialize method
7676
*/
77-
public function afterCompile(ClassType $class)
77+
public function afterCompile(ClassType $class): void
7878
{
7979
foreach ($this->passes as $pass) {
8080
$pass->afterCompile($class);

src/DI/EventLatteBridgeExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Contributte\Events\Extra\Event\Latte\LatteCompileEvent;
66
use Contributte\Events\Extra\Event\Latte\TemplateCreateEvent;
77
use LogicException;
8-
use Nette\Application\UI\TemplateFactory;
98
use Nette\Bridges\ApplicationLatte\LatteFactory;
9+
use Nette\Bridges\ApplicationLatte\TemplateFactory;
1010
use Nette\DI\CompilerExtension;
1111
use Nette\DI\Definitions\FactoryDefinition;
1212
use Nette\DI\Definitions\ServiceDefinition;
@@ -44,9 +44,6 @@ public function beforeCompile(): void
4444
$templateFactories = $builder->findByType(TemplateFactory::class);
4545
foreach ($templateFactories as $templateFactory) {
4646
assert($templateFactory instanceof ServiceDefinition);
47-
if ($templateFactory->factory === null || $templateFactory->factory->entity !== TemplateFactory::class) {
48-
continue;
49-
}
5047

5148
$templateFactory->addSetup('?->onCreate[] = function() {?->dispatch(new ?(...func_get_args()));}', [
5249
'@self',

src/Event/Application/ErrorEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class ErrorEvent extends Event
1010
{
1111

12-
/** @var Application */
13-
private $application;
12+
private Application $application;
1413

15-
/** @var Throwable */
16-
private $throwable;
14+
private Throwable $throwable;
1715

1816
public function __construct(Application $application, Throwable $throwable)
1917
{

src/Event/Application/PresenterEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class PresenterEvent extends Event
1010
{
1111

12-
/** @var Application */
13-
private $application;
12+
private Application $application;
1413

15-
/** @var IPresenter */
16-
private $presenter;
14+
private IPresenter $presenter;
1715

1816
public function __construct(Application $application, IPresenter $presenter)
1917
{

src/Event/Application/PresenterShutdownEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class PresenterShutdownEvent extends Event
1010
{
1111

12-
/** @var Presenter */
13-
private $presenter;
12+
private Presenter $presenter;
1413

15-
/** @var Response */
16-
private $response;
14+
private Response $response;
1715

1816
public function __construct(Presenter $presenter, Response $response)
1917
{

src/Event/Application/PresenterStartupEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
class PresenterStartupEvent extends Event
99
{
1010

11-
/** @var Presenter */
12-
private $presenter;
11+
private Presenter $presenter;
1312

1413
public function __construct(Presenter $presenter)
1514
{

src/Event/Application/RequestEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class RequestEvent extends Event
1010
{
1111

12-
/** @var Application */
13-
private $application;
12+
private Application $application;
1413

15-
/** @var Request */
16-
private $request;
14+
private Request $request;
1715

1816
public function __construct(Application $application, Request $request)
1917
{

src/Event/Application/ResponseEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class ResponseEvent extends Event
1010
{
1111

12-
/** @var Application */
13-
private $application;
12+
private Application $application;
1413

15-
/** @var Response */
16-
private $response;
14+
private Response $response;
1715

1816
public function __construct(Application $application, Response $response)
1917
{

src/Event/Application/ShutdownEvent.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
class ShutdownEvent extends Event
1010
{
1111

12-
/** @var Application */
13-
private $application;
12+
private Application $application;
1413

15-
/** @var Throwable|null */
16-
private $throwable;
14+
private ?Throwable $throwable = null;
1715

1816
public function __construct(Application $application, ?Throwable $throwable = null)
1917
{

src/Event/Application/StartupEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
class StartupEvent extends Event
99
{
1010

11-
/** @var Application */
12-
private $application;
11+
private Application $application;
1312

1413
public function __construct(Application $application)
1514
{

src/Event/Latte/LatteCompileEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
class LatteCompileEvent extends Event
99
{
1010

11-
/** @var Engine */
12-
private $engine;
11+
private Engine $engine;
1312

1413
public function __construct(Engine $engine)
1514
{

src/Event/Latte/TemplateCreateEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
class TemplateCreateEvent extends Event
99
{
1010

11-
/** @var Template */
12-
private $template;
11+
private Template $template;
1312

1413
public function __construct(Template $template)
1514
{

src/Event/Security/LoggedInEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
class LoggedInEvent extends Event
99
{
1010

11-
/** @var User */
12-
private $user;
11+
private User $user;
1312

1413
public function __construct(User $user)
1514
{

src/Event/Security/LoggedOutEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
class LoggedOutEvent extends Event
99
{
1010

11-
/** @var User */
12-
private $user;
11+
private User $user;
1312

1413
public function __construct(User $user)
1514
{

src/Event/UI/Changeset.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Contributte\Events\Extra\Event\UI;
44

55
use ArrayIterator;
6-
use Contributte\EventDispatcher\Exceptions\Logical\InvalidStateException;
6+
use Contributte\Events\Extra\Exceptions\LogicalException;
77
use IteratorAggregate;
88

99
/**
@@ -13,33 +13,22 @@ class Changeset implements IteratorAggregate
1313
{
1414

1515
/** @var mixed[] */
16-
private $changeset = [];
16+
private array $changeset = [];
1717

18-
/**
19-
* @param string|int $key
20-
* @param mixed $value
21-
*/
22-
public function add($key, $value): void
18+
public function add(string|int $key, mixed $value): void
2319
{
2420
$this->changeset[$key] = $value;
2521
}
2622

27-
/**
28-
* @param string|int $key
29-
*/
30-
public function has($key): bool
23+
public function has(string|int $key): bool
3124
{
3225
return array_key_exists($key, $this->changeset);
3326
}
3427

35-
/**
36-
* @param string|int $key
37-
* @return mixed
38-
*/
39-
public function get($key)
28+
public function get(string|int $key): mixed
4029
{
4130
if (!$this->has($key)) {
42-
throw new InvalidStateException(sprintf('Key %s does not exist in this changeset', (string) $key));
31+
throw new LogicalException(sprintf('Key %s does not exist in this changeset', (string) $key));
4332
}
4433

4534
return $this->changeset[$key];

src/Event/UI/UI.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ class UI
99
{
1010

1111
/** @var array<int, stdClass> */
12-
private $messages = [];
12+
private array $messages = [];
1313

1414
/** @var string[] */
15-
private $snippets = [];
15+
private array $snippets = [];
1616

17-
/** @var stdClass */
18-
private $redirect;
17+
private ?stdClass $redirect = null;
1918

2019
/**
2120
* @return array<int, stdClass>
@@ -74,10 +73,7 @@ public function redrawSnippet(string $snippet): void
7473
$this->snippets[] = $snippet;
7574
}
7675

77-
/**
78-
* @return mixed
79-
*/
80-
public function getRedirect()
76+
public function getRedirect(): ?stdClass
8177
{
8278
return $this->redirect;
8379
}

src/Event/UI/UIEvent.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
abstract class UIEvent extends Event
88
{
99

10-
/** @var UI */
11-
private $ui;
10+
private ?UI $ui = null;
1211

1312
/** @var Changeset<mixed> */
14-
private $changeset;
13+
private ?Changeset $changeset = null;
1514

1615
public function getUi(): UI
1716
{

src/Exceptions/LogicalException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Contributte\Events\Extra\Exceptions;
4+
5+
use LogicException;
6+
7+
final class LogicalException extends LogicException
8+
{
9+
10+
}

0 commit comments

Comments
 (0)