Skip to content

Commit

Permalink
Minor refactoring of CallableFactory and `ListenerCollectionFactory…
Browse files Browse the repository at this point in the history
…` + Improve psalm (#65)
  • Loading branch information
vjik authored Feb 4, 2024
1 parent c456517 commit 669f2a2
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1', '8.2']
['8.0', '8.1', '8.2', '8.3']
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.1.1 under development

- no changes in this release.
- Enh #65: Minor refactoring of `CallableFactory` and `ListenerCollectionFactory` (@vjik)

## 2.1.0 November 04, 2023

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"rector/rector": "^0.19.0",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.6",
"vimeo/psalm": "^4.30|^5.21",
"yiisoft/config": "^1.3",
"yiisoft/di": "^1.2",
"yiisoft/test-support": "^1.3"
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
6 changes: 1 addition & 5 deletions src/CallableFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct(
*/
public function create(mixed $definition): callable
{
/** @var mixed */
$callable = $this->prepare($definition);

if (is_callable($callable)) {
Expand All @@ -45,10 +44,8 @@ public function create(mixed $definition): callable

/**
* @throws ContainerExceptionInterface Error while retrieving the entry from container.
*
* @return mixed
*/
private function prepare(mixed $definition)
private function prepare(mixed $definition): mixed
{
if (is_string($definition) && $this->container->has($definition)) {
return $this->container->get($definition);
Expand All @@ -62,7 +59,6 @@ private function prepare(mixed $definition)
[$className, $methodName] = $definition;

if (!class_exists($className) && $this->container->has($className)) {
/** @var mixed */
return [
$this->container->get($className),
$methodName,
Expand Down
4 changes: 1 addition & 3 deletions src/ListenerCollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ public function create(array $eventListeners): ListenerCollection
);
}

/** @var mixed */
foreach ($listeners as $callable) {
$listener =
/** @return mixed */
fn (object $event) => $this->injector->invoke(
fn (object $event): mixed => $this->injector->invoke(
$this->callableFactory->create($callable),
[$event]
);
Expand Down
1 change: 0 additions & 1 deletion src/ListenerConfigurationChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function check(array $configuration): void
);
}

/** @var mixed */
foreach ($listeners as $listener) {
try {
if (!$this->isCallable($listener)) {
Expand Down

0 comments on commit 669f2a2

Please sign in to comment.