diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 3e0d577..f95e62c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,44 +1,44 @@ - + - is_string($eventName) - is_string($eventName) + + - $force + - $identifiers + - $listOfListenersByPriority[$priority][] - $listener - $listeners - $listeners - $response + + + + + - $listener($event) + - (int) $priority + - EventManagerAwareInterface + - $events + - setEventManager + - getEventManager + eventIdentifier)) @@ -62,20 +62,20 @@ - getEventManager + - attach + - $value + - mixed + @@ -87,49 +87,52 @@ - $value + + + + - Filter\FilterIterator - null|ResponseCollection + + - $callback + - CallbackHandler + - $next($context, $argv, $chain) + - $argv + - $next($context, $argv, $chain) + - CallbackHandler + - $method + listener]]> listener]]> - callable - callable + + {$method}($event)]]> @@ -137,53 +140,53 @@ listener]]> - callable + - $listener + - $container - $env + + - setStopped + - (bool) $flag + - ! is_string($event) - ! is_string($eventName) - ! is_string($eventName) - ! is_string($identifier) - ! is_string($identifier) - ! is_string($identifier) + + + + + + - $force + - clearListeners + - $listOfListeners + identifiers[$identifier]]]> - $eventName - $identifier + + - $listenersByIdentifier[$eventName] + identifiers[$identifier][$eventName]]]> identifiers[$identifier][$eventName]]]> @@ -193,7 +196,7 @@ identifiers[$identifier][$eventName][$priority]]]> identifiers[$identifier][$eventName][$priority]]]> identifiers[$identifier][$eventName][$priority][$index]]]> - $wildcardIdentifier[$eventName] + @@ -201,111 +204,111 @@ identifiers[$identifier][$event][(int) $priority]]]> - $returnListeners[$priority] - $returnListeners[$priority] - $returnListeners[$priority] - $returnListeners[$priority] + + + + identifiers[$identifier][$eventName][$priority]]]> identifiers[$identifier][$eventName][$priority]]]> identifiers[$identifier][$eventName][$priority]]]> identifiers[$identifier][$eventName][$priority][$index]]]> - $evaluatedListener - $index - $listeners - $listeners - $listeners - $listeners - $listeners - $listenersByIdentifier - $priority - $priority - $priority - $priority - $priority - $returnListeners[$priority][] - $returnListeners[$priority][] - $returnListeners[$priority][] - $returnListeners[$priority][] - $wildcardIdentifier + + + + + + + + + + + + + + + + + + - $identifiers + - $event + - (int) $priority + - attach - clearListeners + + - Traversable + - assertListenerAtPriority + - $l - $listeners - $listeners[$p] + + + - $internal[$event] + - $listeners[$p] - $listeners[$p] + + - $internal - $l - $listOfListeners - $listener - $listener - $listeners - $listeners - $listeners[$p] - $p - $priority + + + + + + + + + + - callable[] - string[] + + - $type + - getObjectForTrait - getObjectForTrait + + - EventManagerAwareTrait::class - EventManagerAwareTrait::class + + - getEventManager - getEventManager - setEventManager - setEventManager + + + + - $event + getParam('accumulator')]]> @@ -318,19 +321,19 @@ getParam('accumulator')]]> - $compare - $original - $original + + + - enqueue - getParam + + - $result - $result + + @@ -338,38 +341,38 @@ - $default + - assertSame + - $handle - $handle1 + + - $chain - $chain - $context - $context - $context - $context - $context - $params - $params + + + + + + + + + - function ($context, $params, $chain) { - function ($context, $params, $chain) { + + - $string - $string - $string + + + @@ -380,82 +383,82 @@ - $string - $string - $string - $value - $value - $value + + + + + + - next - next + + - function () { - function () { - function () { + + + - testInsertShouldRaiseExceptionOnNonCallableDatum + - $filter + - $listener + - testCanRetrieveEventFromListener - testCanRetrievePriorityFromListener - testConstructorRaisesExceptionForInvalidEventType + + + - getPriority + container)]]> container)]]> container)]]> container)]]> - LazyListener + - testAttachAttachesLazyListenersViaClosures - testPassingInvalidListenerTypesAtInstantiationRaisesException - testPassingInvalidListenersAtInstantiationRaisesException + + + - $test[0] - $test[1] + + - $listener - $listeners - $test + + + - $lazyListener($event) - $lazyListener($event) + + - $listener + - testConstructorRaisesExceptionForInvalidListenerType - testConstructorRaisesExceptionForInvalidMethodType - testInstatiationSetsListenerMethod + + + - new $class($struct, $container, $env) + container)]]> container)]]> container)]]> @@ -464,52 +467,52 @@ container)]]> - LazyListener + - testAttachRaisesExceptionForInvalidEvent - testAttachRaisesExceptionForInvalidIdentifer - testCanDetachFromSharedManagerUsingIdentifierAndEvent - testDetachingWithInvalidEventTypeRaisesException - testDetachingWithInvalidIdentifierTypeRaisesException - testGetListenersRaisesExceptionForInvalidEventName - testGetListenersRaisesExceptionForInvalidIdentifier + + + + + + + - $event - $eventName - $eventName - $identifier - $identifier + + + + + - $identifiers - [$identifier] + + - $listeners[$priority] - callable[] + + - $event + - $event + - (int) $priority + - assertIsArray - assertIsArray + + - assertIsArray + - $callback + @@ -519,105 +522,105 @@ - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e + + + + + + + + + + + + + + + + + + + + + + + + - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} - function ($e) {} + + + + + + + + + + + + + + + + + + + + + - assertIsArray + - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e - $e + + + + + + + + + + + + + + + + + + + + + + + + - build + - build + - $index + - doFoo + - doFoo + diff --git a/src/EventManager.php b/src/EventManager.php index bf0e057..ed0837b 100644 --- a/src/EventManager.php +++ b/src/EventManager.php @@ -8,6 +8,7 @@ use function array_merge; use function array_unique; use function get_debug_type; +use function is_callable; use function is_string; use function krsort; use function sprintf; @@ -135,7 +136,7 @@ public function trigger($eventName, $target = null, $argv = []) $event->setTarget($target); } - if ($argv) { + if ($argv !== []) { $event->setParams($argv); } @@ -154,7 +155,7 @@ public function triggerUntil(callable $callback, $eventName, $target = null, $ar $event->setTarget($target); } - if ($argv) { + if ($argv !== []) { $event->setParams($argv); } @@ -281,7 +282,7 @@ protected function triggerListeners(EventInterface $event, ?callable $callback = { $name = $event->getName(); - if (empty($name)) { + if ($name === null || $name === '' || $name === '0') { throw new Exception\RuntimeException('Event is missing a name; cannot trigger!'); } @@ -327,7 +328,7 @@ protected function triggerListeners(EventInterface $event, ?callable $callback = // If the result causes our validation callback to return true, // stop propagation - if ($callback && $callback($response)) { + if (is_callable($callback) && $callback($response)) { $responses->setStopped(true); return $responses; } diff --git a/test/EventManagerTest.php b/test/EventManagerTest.php index 45b1494..6ed4d35 100644 --- a/test/EventManagerTest.php +++ b/test/EventManagerTest.php @@ -813,7 +813,7 @@ public function testTriggeringAnEventWithAnEmptyNameRaisesAnException( $this->expectException(Exception\RuntimeException::class); $this->expectExceptionMessage('missing a name'); - if ($callback) { + if ($callback !== null) { $this->events->$method($callback, $event); } else { $this->events->$method($event);