Răsfoiți Sursa

Static analysis improvements (#1475)

* Static analysis improvements

* Fix review issues
Mponos George 5 ani în urmă
părinte
comite
53e2c97b0b

+ 2 - 0
src/Monolog/Handler/FilterHandler.php

@@ -49,6 +49,8 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
     protected $bubble;
 
     /**
+     * @psalm-param HandlerInterface|callable(?array, HandlerInterface): HandlerInterface $handler
+     *
      * @param callable|HandlerInterface $handler        Handler or factory callable($record|null, $filterHandler).
      * @param int|array                 $minLevelOrList A list of levels to accept or a minimum level if maxLevel is provided
      * @param int|string                $maxLevel       Maximum level to accept, only used if $minLevelOrList is not an array

+ 2 - 0
src/Monolog/Handler/FingersCrossedHandler.php

@@ -47,6 +47,8 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
     protected $bubble;
 
     /**
+     * @psalm-param HandlerInterface|callable(?array, FingersCrossedHandler): HandlerInterface $handler
+     *
      * @param callable|HandlerInterface              $handler            Handler or factory callable($record|null, $fingersCrossedHandler).
      * @param int|string|ActivationStrategyInterface $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.

+ 2 - 0
src/Monolog/Handler/MandrillHandler.php

@@ -25,6 +25,8 @@ class MandrillHandler extends MailHandler
     protected $apiKey;
 
     /**
+     * @psalm-param Swift_Message|callable(string, array): Swift_Message $message
+     *
      * @param string                  $apiKey  A valid Mandrill API key
      * @param callable|\Swift_Message $message An example message for real messages, only the body will be replaced
      * @param string|int              $level   The minimum logging level at which this handler will be triggered

+ 4 - 0
src/Monolog/Handler/ProcessableHandlerInterface.php

@@ -23,6 +23,8 @@ interface ProcessableHandlerInterface
     /**
      * Adds a processor in the stack.
      *
+     * @psalm-param ProcessorInterface|callable(array): array $callback
+     *
      * @param  ProcessorInterface|callable $callback
      * @return HandlerInterface            self
      */
@@ -31,6 +33,8 @@ interface ProcessableHandlerInterface
     /**
      * Removes the processor on top of the stack and returns it.
      *
+     * @psalm-return callable(array): array
+     *
      * @throws \LogicException In case the processor stack is empty
      * @return callable
      */

+ 2 - 0
src/Monolog/Handler/SamplingHandler.php

@@ -42,6 +42,8 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
     protected $factor;
 
     /**
+     * @psalm-param HandlerInterface|callable(array, HandlerInterface): HandlerInterface $handler
+     *
      * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $samplingHandler).
      * @param int                       $factor  Sample factor (e.g. 10 means every ~10th record is sampled)
      */

+ 2 - 0
src/Monolog/Handler/SwiftMailerHandler.php

@@ -28,6 +28,8 @@ class SwiftMailerHandler extends MailHandler
     private $messageTemplate;
 
     /**
+     * @psalm-param Swift_Message|callable(string, array): Swift_Message $message
+     *
      * @param \Swift_Mailer          $mailer  The mailer to use
      * @param callable|Swift_Message $message An example message for real messages, only the body will be replaced
      * @param string|int             $level   The minimum logging level at which this handler will be triggered

+ 4 - 1
src/Monolog/Handler/TestHandler.php

@@ -139,13 +139,16 @@ class TestHandler extends AbstractProcessingHandler
      */
     public function hasRecordThatMatches(string $regex, $level): bool
     {
-        return $this->hasRecordThatPasses(function ($rec) use ($regex) {
+        return $this->hasRecordThatPasses(function (array $rec) use ($regex): bool {
             return preg_match($regex, $rec['message']) > 0;
         }, $level);
     }
 
     /**
+     * @psalm-param callable(array, int): mixed $predicate
+     *
      * @param string|int $level Logging level value or name
+     * @return bool
      */
     public function hasRecordThatPasses(callable $predicate, $level)
     {

+ 2 - 0
src/Monolog/Logger.php

@@ -140,6 +140,8 @@ class Logger implements LoggerInterface, ResettableInterface
     protected $exceptionHandler;
 
     /**
+     * @psalm-param array<callable(array): array> $processors
+     *
      * @param string             $name       The logging channel, a simple descriptive name that is attached to all log records
      * @param HandlerInterface[] $handlers   Optional stack of handlers, the first one in the array is called first, etc.
      * @param callable[]         $processors Optional array of processors