From a7de8dd0c206ce5d94672151c42fc19395d8b849 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 22 Apr 2022 14:26:03 +0200 Subject: [PATCH] Update a few more callable to Closure --- src/Monolog/Handler/FilterHandler.php | 6 +++--- src/Monolog/Handler/FingersCrossedHandler.php | 8 ++++---- src/Monolog/Handler/SamplingHandler.php | 8 ++++---- src/Monolog/Logger.php | 8 ++++++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Monolog/Handler/FilterHandler.php b/src/Monolog/Handler/FilterHandler.php index c697e72f..e23742c1 100644 --- a/src/Monolog/Handler/FilterHandler.php +++ b/src/Monolog/Handler/FilterHandler.php @@ -55,7 +55,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese /** * @phpstan-param (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * - * @param Closure|HandlerInterface $handler Handler or factory callable($record|null, $filterHandler). + * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $filterHandler). * @param int|string|Level|LevelName|array $minLevelOrList A list of levels to accept or a minimum level if maxLevel is provided * @param int|string|Level|LevelName|LogLevel::* $maxLevel Maximum level to accept, only used if $minLevelOrList is not an array * @param bool $bubble Whether the messages that are handled can bubble up the stack or not @@ -148,14 +148,14 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese /** * Return the nested handler * - * If the handler was provided as a factory callable, this will trigger the handler's instantiation. + * If the handler was provided as a factory, this will trigger the handler's instantiation. */ public function getHandler(LogRecord $record = null): HandlerInterface { if (!$this->handler instanceof HandlerInterface) { $handler = ($this->handler)($record, $this); if (!$handler instanceof HandlerInterface) { - throw new \RuntimeException("The factory callable should return a HandlerInterface"); + throw new \RuntimeException("The factory Closure should return a HandlerInterface"); } $this->handler = $handler; } diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 633233e2..6a3e2391 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -43,7 +43,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa use ProcessableHandlerTrait; /** - * Handler or factory callable($record, $this) + * Handler or factory Closure($record, $this) * * @phpstan-var (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface */ @@ -67,7 +67,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa /** * @phpstan-param (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * - * @param Closure|HandlerInterface $handler Handler or factory callable($record|null, $fingersCrossedHandler). + * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $fingersCrossedHandler). * @param int|string|Level|LevelName|LogLevel::* $activationStrategy Strategy which determines when this handler takes action, or a level name/value at which the handler is activated * @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer. * @param bool $bubble Whether the messages that are handled can bubble up the stack or not @@ -198,14 +198,14 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa /** * Return the nested handler * - * If the handler was provided as a factory callable, this will trigger the handler's instantiation. + * If the handler was provided as a factory, this will trigger the handler's instantiation. */ public function getHandler(LogRecord $record = null): HandlerInterface { if (!$this->handler instanceof HandlerInterface) { $handler = ($this->handler)($record, $this); if (!$handler instanceof HandlerInterface) { - throw new \RuntimeException("The factory callable should return a HandlerInterface"); + throw new \RuntimeException("The factory Closure should return a HandlerInterface"); } $this->handler = $handler; } diff --git a/src/Monolog/Handler/SamplingHandler.php b/src/Monolog/Handler/SamplingHandler.php index 917413ef..1301a63d 100644 --- a/src/Monolog/Handler/SamplingHandler.php +++ b/src/Monolog/Handler/SamplingHandler.php @@ -34,7 +34,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter use ProcessableHandlerTrait; /** - * Handler or factory callable($record, $this) + * Handler or factory Closure($record, $this) * * @phpstan-var (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface */ @@ -45,7 +45,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter /** * @phpstan-param (Closure(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * - * @param Closure|HandlerInterface $handler Handler or factory callable($record|null, $samplingHandler). + * @param Closure|HandlerInterface $handler Handler or factory Closure($record|null, $samplingHandler). * @param int $factor Sample factor (e.g. 10 means every ~10th record is sampled) */ public function __construct(Closure|HandlerInterface $handler, int $factor) @@ -76,14 +76,14 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter /** * Return the nested handler * - * If the handler was provided as a factory callable, this will trigger the handler's instantiation. + * If the handler was provided as a factory, this will trigger the handler's instantiation. */ public function getHandler(LogRecord $record = null): HandlerInterface { if (!$this->handler instanceof HandlerInterface) { $handler = ($this->handler)($record, $this); if (!$handler instanceof HandlerInterface) { - throw new \RuntimeException("The factory callable should return a HandlerInterface"); + throw new \RuntimeException("The factory Closure should return a HandlerInterface"); } $this->handler = $handler; } diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index fa38923a..5c75e28f 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -212,8 +212,10 @@ class Logger implements LoggerInterface, ResettableInterface /** * Adds a processor on to the stack. + * + * @phpstan-param ProcessorInterface|(callable(LogRecord): LogRecord) $callback */ - public function pushProcessor(callable $callback): self + public function pushProcessor(ProcessorInterface|callable $callback): self { array_unshift($this->processors, $callback); @@ -223,6 +225,7 @@ class Logger implements LoggerInterface, ResettableInterface /** * Removes the processor on top of the stack and returns it. * + * @phpstan-return ProcessorInterface|(callable(LogRecord): LogRecord) * @throws \LogicException If empty processor stack */ public function popProcessor(): callable @@ -236,6 +239,7 @@ class Logger implements LoggerInterface, ResettableInterface /** * @return callable[] + * @phpstan-return array */ public function getProcessors(): array { @@ -433,7 +437,7 @@ class Logger implements LoggerInterface, ResettableInterface /** * Set a custom exception handler that will be called if adding a new record fails * - * The callable will receive an exception object and the record that failed to be logged + * The Closure will receive an exception object and the record that failed to be logged */ public function setExceptionHandler(Closure|null $callback): self {