Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring of CallableFactory and ListenerCollectionFactory + Improve psalm #65

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
);
}

/** @var mixed */
foreach ($listeners as $listener) {
try {
if (!$this->isCallable($listener)) {
Expand All @@ -61,7 +60,7 @@
}
} catch (ContainerExceptionInterface $exception) {
throw new InvalidListenerConfigurationException(
'Could not instantiate event listener or listener class has invalid configuration. Got ' .

Check warning on line 63 in src/ListenerConfigurationChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ throw new InvalidListenerConfigurationException($this->createNotCallableMessage($listener)); } } catch (ContainerExceptionInterface $exception) { - throw new InvalidListenerConfigurationException('Could not instantiate event listener or listener class has invalid configuration. Got ' . $this->listenerDump($listener) . '.', 0, $exception); + throw new InvalidListenerConfigurationException('Could not instantiate event listener or listener class has invalid configuration. Got ' . $this->listenerDump($listener), 0, $exception); } } }

Check warning on line 63 in src/ListenerConfigurationChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ throw new InvalidListenerConfigurationException($this->createNotCallableMessage($listener)); } } catch (ContainerExceptionInterface $exception) { - throw new InvalidListenerConfigurationException('Could not instantiate event listener or listener class has invalid configuration. Got ' . $this->listenerDump($listener) . '.', 0, $exception); + throw new InvalidListenerConfigurationException('Could not instantiate event listener or listener class has invalid configuration. Got ' . $this->listenerDump($listener), 0, $exception); } } }
$this->listenerDump($listener) . '.',
0,
$exception
Expand Down Expand Up @@ -107,7 +106,7 @@
}
}

return 'Listener must be a callable. Got ' . $this->listenerDump($definition) . '.';

Check warning on line 109 in src/ListenerConfigurationChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ return sprintf('"%s" method is not defined in "%s" class.', $definition[1], $definition[0]::class); } } - return 'Listener must be a callable. Got ' . $this->listenerDump($definition) . '.'; + return 'Listener must be a callable. Got ' . $this->listenerDump($definition); } /** * @throws ContainerExceptionInterface Error while retrieving the entry from container.

Check warning on line 109 in src/ListenerConfigurationChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ return sprintf('"%s" method is not defined in "%s" class.', $definition[1], $definition[0]::class); } } - return 'Listener must be a callable. Got ' . $this->listenerDump($definition) . '.'; + return 'Listener must be a callable. Got ' . $this->listenerDump($definition); } /** * @throws ContainerExceptionInterface Error while retrieving the entry from container.
}

/**
Expand Down
Loading