Просмотр исходного кода

Add missing types to constructor args

Jordi Boggiano 3 лет назад
Родитель
Сommit
bd5968a567

+ 1 - 1
doc/04-extending.md

@@ -30,7 +30,7 @@ class PDOHandler extends AbstractProcessingHandler
     private PDO $pdo;
     private PDOStatement $statement;
 
-    public function __construct(PDO $pdo, $level = Level::Debug, bool $bubble = true)
+    public function __construct(PDO $pdo, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         $this->pdo = $pdo;
         parent::__construct($level, $bubble);

+ 2 - 1
src/Monolog/Handler/AbstractSyslogHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Level;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Formatter\LineFormatter;
+use Monolog\LevelName;
 
 /**
  * Common syslog functionality
@@ -60,7 +61,7 @@ abstract class AbstractSyslogHandler extends AbstractProcessingHandler
     /**
      * @param string|int $facility Either one of the names of the keys in $this->facilities, or a LOG_* facility constant
      */
-    public function __construct($facility = \LOG_USER, $level = Level::Debug, bool $bubble = true)
+    public function __construct(string|int $facility = \LOG_USER, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/ChromePHPHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Formatter\ChromePHPFormatter;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 use Monolog\DateTimeImmutable;
@@ -62,7 +63,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
 
     protected static bool $sendHeaders = true;
 
-    public function __construct($level = Level::Debug, bool $bubble = true)
+    public function __construct(int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
         if (!function_exists('json_encode')) {

+ 2 - 1
src/Monolog/Handler/CouchDBHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Formatter\JsonFormatter;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -48,7 +49,7 @@ class CouchDBHandler extends AbstractProcessingHandler
      *
      * @phpstan-param InputOptions $options
      */
-    public function __construct(array $options = [], $level = Level::Debug, bool $bubble = true)
+    public function __construct(array $options = [], int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         $this->options = array_merge([
             'host'     => 'localhost',

+ 2 - 1
src/Monolog/Handler/CubeHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -38,7 +39,7 @@ class CubeHandler extends AbstractProcessingHandler
      *                                   A valid url must consist of three parts : protocol://host:port
      *                                   Only valid protocols used by Cube are http and udp
      */
-    public function __construct(string $url, $level = Level::Debug, bool $bubble = true)
+    public function __construct(string $url, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         $urlInfo = parse_url($url);
 

+ 2 - 1
src/Monolog/Handler/DoctrineCouchDBHandler.php

@@ -15,6 +15,7 @@ use Monolog\Level;
 use Monolog\Formatter\NormalizerFormatter;
 use Monolog\Formatter\FormatterInterface;
 use Doctrine\CouchDB\CouchDBClient;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -26,7 +27,7 @@ class DoctrineCouchDBHandler extends AbstractProcessingHandler
 {
     private CouchDBClient $client;
 
-    public function __construct(CouchDBClient $client, $level = Level::Debug, bool $bubble = true)
+    public function __construct(CouchDBClient $client, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         $this->client = $client;
         parent::__construct($level, $bubble);

+ 2 - 1
src/Monolog/Handler/DynamoDbHandler.php

@@ -17,6 +17,7 @@ use Monolog\Formatter\FormatterInterface;
 use Aws\DynamoDb\Marshaler;
 use Monolog\Formatter\ScalarFormatter;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -35,7 +36,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
 
     protected Marshaler $marshaler;
 
-    public function __construct(DynamoDbClient $client, string $table, $level = Level::Debug, bool $bubble = true)
+    public function __construct(DynamoDbClient $client, string $table, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         $this->marshaler = new Marshaler;
 

+ 2 - 1
src/Monolog/Handler/ElasticaHandler.php

@@ -17,6 +17,7 @@ use Monolog\Formatter\ElasticaFormatter;
 use Monolog\Level;
 use Elastica\Client;
 use Elastica\Exception\ExceptionInterface;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -61,7 +62,7 @@ class ElasticaHandler extends AbstractProcessingHandler
      *
      * @phpstan-param InputOptions $options
      */
-    public function __construct(Client $client, array $options = [], $level = Level::Debug, bool $bubble = true)
+    public function __construct(Client $client, array $options = [], int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
         $this->client = $client;

+ 2 - 1
src/Monolog/Handler/ElasticsearchHandler.php

@@ -11,6 +11,7 @@
 
 namespace Monolog\Handler;
 
+use Monolog\LevelName;
 use Throwable;
 use RuntimeException;
 use Monolog\Level;
@@ -68,7 +69,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler
      *
      * @phpstan-param InputOptions $options
      */
-    public function __construct(Client $client, array $options = [], $level = Level::Debug, bool $bubble = true)
+    public function __construct(Client $client, array $options = [], int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
         $this->client = $client;

+ 2 - 1
src/Monolog/Handler/ErrorLogHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Formatter\LineFormatter;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -34,7 +35,7 @@ class ErrorLogHandler extends AbstractProcessingHandler
      * @param int  $messageType    Says where the error should go.
      * @param bool $expandNewlines If set to true, newlines in the message will be expanded to be take multiple log entries
      */
-    public function __construct(int $messageType = self::OPERATING_SYSTEM, $level = Level::Debug, bool $bubble = true, bool $expandNewlines = false)
+    public function __construct(int $messageType = self::OPERATING_SYSTEM, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true, bool $expandNewlines = false)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/GelfHandler.php

@@ -15,6 +15,7 @@ use Gelf\PublisherInterface;
 use Monolog\Level;
 use Monolog\Formatter\GelfMessageFormatter;
 use Monolog\Formatter\FormatterInterface;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -33,7 +34,7 @@ class GelfHandler extends AbstractProcessingHandler
     /**
      * @param PublisherInterface $publisher a gelf publisher object
      */
-    public function __construct(PublisherInterface $publisher, $level = Level::Debug, bool $bubble = true)
+    public function __construct(PublisherInterface $publisher, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/IFTTTHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -35,7 +36,7 @@ class IFTTTHandler extends AbstractProcessingHandler
      * @param string $eventName The name of the IFTTT Maker event that should be triggered
      * @param string $secretKey A valid IFTTT secret key
      */
-    public function __construct(string $eventName, string $secretKey, $level = Level::Error, bool $bubble = true)
+    public function __construct(string $eventName, string $secretKey, int|string|Level|LevelName $level = Level::Error, bool $bubble = true)
     {
         if (!extension_loaded('curl')) {
             throw new MissingExtensionException('The curl extension is needed to use the IFTTTHandler');

+ 2 - 1
src/Monolog/Handler/LogglyHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Level;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Formatter\LogglyFormatter;
+use Monolog\LevelName;
 use function array_key_exists;
 use CurlHandle;
 use Monolog\LogRecord;
@@ -48,7 +49,7 @@ class LogglyHandler extends AbstractProcessingHandler
      *
      * @throws MissingExtensionException If the curl extension is missing
      */
-    public function __construct(string $token, $level = Level::Debug, bool $bubble = true)
+    public function __construct(string $token, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         if (!extension_loaded('curl')) {
             throw new MissingExtensionException('The curl extension is needed to use the LogglyHandler');

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

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Swift;
 use Swift_Message;
 
@@ -31,7 +32,7 @@ class MandrillHandler extends MailHandler
      * @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
      */
-    public function __construct(string $apiKey, callable|Swift_Message $message, $level = Level::Error, bool $bubble = true)
+    public function __construct(string $apiKey, callable|Swift_Message $message, int|string|Level|LevelName $level = Level::Error, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 5
src/Monolog/Handler/MongoDBHandler.php

@@ -17,6 +17,7 @@ use MongoDB\Client;
 use Monolog\Level;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Formatter\MongoDBFormatter;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -47,12 +48,8 @@ class MongoDBHandler extends AbstractProcessingHandler
      * @param string         $database   Database name
      * @param string         $collection Collection name
      */
-    public function __construct($mongodb, string $database, string $collection, $level = Level::Debug, bool $bubble = true)
+    public function __construct(Client|Manager $mongodb, string $database, string $collection, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
-        if (!($mongodb instanceof Client || $mongodb instanceof Manager)) {
-            throw new \InvalidArgumentException('MongoDB\Client or MongoDB\Driver\Manager instance required');
-        }
-
         if ($mongodb instanceof Client) {
             $this->collection = $mongodb->selectCollection($database, $collection);
         } else {

+ 2 - 1
src/Monolog/Handler/NativeMailerHandler.php

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
 
 use Monolog\Level;
 use Monolog\Formatter\LineFormatter;
+use Monolog\LevelName;
 
 /**
  * NativeMailerHandler uses the mail() function to send the emails
@@ -66,7 +67,7 @@ class NativeMailerHandler extends MailHandler
      * @param string          $from           The sender of the mail
      * @param int             $maxColumnWidth The maximum column width that the message lines will have
      */
-    public function __construct($to, string $subject, string $from, $level = Level::Error, bool $bubble = true, int $maxColumnWidth = 70)
+    public function __construct(string|array $to, string $subject, string $from, int|string|Level|LevelName $level = Level::Error, bool $bubble = true, int $maxColumnWidth = 70)
     {
         parent::__construct($level, $bubble);
         $this->to = (array) $to;

+ 2 - 1
src/Monolog/Handler/PHPConsoleHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Formatter\LineFormatter;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use PhpConsole\Connector;
 use PhpConsole\Handler as VendorPhpConsoleHandler;
@@ -120,7 +121,7 @@ class PHPConsoleHandler extends AbstractProcessingHandler
      * @throws \RuntimeException
      * @phpstan-param InputOptions $options
      */
-    public function __construct(array $options = [], ?Connector $connector = null, $level = Level::Debug, bool $bubble = true)
+    public function __construct(array $options = [], ?Connector $connector = null, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         if (!class_exists('PhpConsole\Connector')) {
             throw new \RuntimeException('PHP Console library not found. See https://github.com/barbushin/php-console#installation');

+ 2 - 1
src/Monolog/Handler/ProcessHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -58,7 +59,7 @@ class ProcessHandler extends AbstractProcessingHandler
      * @param  string|null               $cwd     "Current working directory" (CWD) for the process to be executed in.
      * @throws \InvalidArgumentException
      */
-    public function __construct(string $command, $level = Level::Debug, bool $bubble = true, ?string $cwd = null)
+    public function __construct(string $command, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true, ?string $cwd = null)
     {
         if ($command === '') {
             throw new \InvalidArgumentException('The command argument must be a non-empty string.');

+ 2 - 1
src/Monolog/Handler/PsrHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Psr\Log\LoggerInterface;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\LogRecord;
@@ -37,7 +38,7 @@ class PsrHandler extends AbstractHandler implements FormattableHandlerInterface
     /**
      * @param LoggerInterface $logger The underlying PSR-3 compliant logger to which messages will be proxied
      */
-    public function __construct(LoggerInterface $logger, $level = Level::Debug, bool $bubble = true)
+    public function __construct(LoggerInterface $logger, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/RotatingFileHandler.php

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
 
 use InvalidArgumentException;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -43,7 +44,7 @@ class RotatingFileHandler extends StreamHandler
      * @param int|null $filePermission Optional file permissions (default (0644) are only for owner read/write)
      * @param bool     $useLocking     Try to lock log file before doing any writes
      */
-    public function __construct(string $filename, int $maxFiles = 0, $level = Level::Debug, bool $bubble = true, ?int $filePermission = null, bool $useLocking = false)
+    public function __construct(string $filename, int $maxFiles = 0, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true, ?int $filePermission = null, bool $useLocking = false)
     {
         $this->filename = Utils::canonicalizePath($filename);
         $this->maxFiles = $maxFiles;

+ 2 - 1
src/Monolog/Handler/SendGridHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 
 /**
  * SendGridrHandler uses the SendGrid API v2 function to send Log emails, more information in https://sendgrid.com/docs/API_Reference/Web_API/mail.html
@@ -53,7 +54,7 @@ class SendGridHandler extends MailHandler
      * @param string|string[] $to      The recipients of the email
      * @param string          $subject The subject of the mail
      */
-    public function __construct(string $apiUser, string $apiKey, string $from, $to, string $subject, $level = Level::Error, bool $bubble = true)
+    public function __construct(string $apiUser, string $apiKey, string $from, string|array $to, string $subject, int|string|Level|LevelName $level = Level::Error, bool $bubble = true)
     {
         if (!extension_loaded('curl')) {
             throw new MissingExtensionException('The curl extension is needed to use the SendGridHandler');

+ 2 - 1
src/Monolog/Handler/SqsHandler.php

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
 
 use Aws\Sqs\SqsClient;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -31,7 +32,7 @@ class SqsHandler extends AbstractProcessingHandler
     private SqsClient $client;
     private string $queueUrl;
 
-    public function __construct(SqsClient $sqsClient, string $queueUrl, $level = Level::Debug, bool $bubble = true)
+    public function __construct(SqsClient $sqsClient, string $queueUrl, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/StreamHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -44,7 +45,7 @@ class StreamHandler extends AbstractProcessingHandler
      *
      * @throws \InvalidArgumentException If stream is not a resource or string
      */
-    public function __construct($stream, $level = Level::Debug, bool $bubble = true, ?int $filePermission = null, bool $useLocking = false)
+    public function __construct($stream, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true, ?int $filePermission = null, bool $useLocking = false)
     {
         parent::__construct($level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/SyslogHandler.php

@@ -12,6 +12,7 @@
 namespace Monolog\Handler;
 
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -37,7 +38,7 @@ class SyslogHandler extends AbstractSyslogHandler
      * @param string|int $facility Either one of the names of the keys in $this->facilities, or a LOG_* facility constant
      * @param int        $logopts  Option flags for the openlog() call, defaults to LOG_PID
      */
-    public function __construct(string $ident, $facility = LOG_USER, $level = Level::Debug, bool $bubble = true, int $logopts = LOG_PID)
+    public function __construct(string $ident, string|int $facility = LOG_USER, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true, int $logopts = LOG_PID)
     {
         parent::__construct($facility, $level, $bubble);
 

+ 2 - 1
src/Monolog/Handler/SyslogUdpHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use DateTimeInterface;
 use Monolog\Level;
 use Monolog\Handler\SyslogUdp\UdpSocket;
+use Monolog\LevelName;
 use Monolog\Utils;
 use Monolog\LogRecord;
 
@@ -52,7 +53,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler
      *
      * @phpstan-param self::RFC* $rfc
      */
-    public function __construct(string $host, int $port = 514, $facility = LOG_USER, $level = Level::Debug, bool $bubble = true, string $ident = 'php', int $rfc = self::RFC5424)
+    public function __construct(string $host, int $port = 514, string|int $facility = LOG_USER, int|string|Level|LevelName $level = Level::Debug, bool $bubble = true, string $ident = 'php', int $rfc = self::RFC5424)
     {
         if (!extension_loaded('sockets')) {
             throw new MissingExtensionException('The sockets extension is required to use the SyslogUdpHandler');

+ 2 - 1
src/Monolog/Handler/ZendMonitorHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Formatter\FormatterInterface;
 use Monolog\Formatter\NormalizerFormatter;
 use Monolog\Level;
+use Monolog\LevelName;
 use Monolog\LogRecord;
 
 /**
@@ -27,7 +28,7 @@ class ZendMonitorHandler extends AbstractProcessingHandler
     /**
      * @throws MissingExtensionException
      */
-    public function __construct($level = Level::Debug, bool $bubble = true)
+    public function __construct(int|string|Level|LevelName $level = Level::Debug, bool $bubble = true)
     {
         if (!function_exists('zend_monitor_custom_event')) {
             throw new MissingExtensionException(

+ 1 - 1
tests/Monolog/Handler/MongoDBHandlerTest.php

@@ -18,7 +18,7 @@ class MongoDBHandlerTest extends TestCase
 {
     public function testConstructorShouldThrowExceptionForInvalidMongo()
     {
-        $this->expectException(\InvalidArgumentException::class);
+        $this->expectException(\TypeError::class);
 
         new MongoDBHandler(new \stdClass, 'db', 'collection');
     }