Skip to content

Commit

Permalink
Test factory callability more simply, so psalm understands what's hap…
Browse files Browse the repository at this point in the history
…pening

Signed-off-by: Tim Lieberman <[email protected]>
  • Loading branch information
timdev authored and Ocramius committed Sep 14, 2022
1 parent 0ac6b3a commit 4100b64
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/FlashMessageMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function class_exists;
use function class_implements;
use function in_array;
use function is_callable;

class FlashMessageMiddleware implements MiddlewareInterface
{
Expand All @@ -22,10 +20,7 @@ class FlashMessageMiddleware implements MiddlewareInterface
/** @var string */
private $attributeKey;

/**
* @var callable
* @psalm-var callable(SessionInterface, string):array
*/
/** @psalm-var callable(SessionInterface, string): FlashMessagesInterface */
private $flashMessageFactory;

/** @var string */
Expand All @@ -36,15 +31,12 @@ public function __construct(
string $sessionKey = FlashMessagesInterface::FLASH_NEXT,
string $attributeKey = self::FLASH_ATTRIBUTE
) {
if (
! class_exists($flashMessagesClass)
|| ! in_array(FlashMessagesInterface::class, class_implements($flashMessagesClass), true)
) {
$factory = [$flashMessagesClass, 'createFromSession'];
if (! is_callable($factory)) {
throw Exception\InvalidFlashMessagesImplementationException::forClass($flashMessagesClass);
}

/** @psalm-var callable(SessionInterface, string):array */
$this->flashMessageFactory = [$flashMessagesClass, 'createFromSession'];
$this->flashMessageFactory = $factory;
$this->sessionKey = $sessionKey;
$this->attributeKey = $attributeKey;
}
Expand Down

0 comments on commit 4100b64

Please sign in to comment.