Przeglądaj źródła

add some @throws in constructors (#1779)

Thomas Müller 2 lat temu
rodzic
commit
616c675160

+ 2 - 0
src/Monolog/Formatter/ElasticaFormatter.php

@@ -34,6 +34,8 @@ class ElasticaFormatter extends NormalizerFormatter
     /**
      * @param string  $index Elastic Search index name
      * @param ?string $type  Elastic Search document type, deprecated as of Elastica 7
+     *
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(string $index, ?string $type)
     {

+ 2 - 0
src/Monolog/Formatter/ElasticsearchFormatter.php

@@ -34,6 +34,8 @@ class ElasticsearchFormatter extends NormalizerFormatter
     /**
      * @param string $index Elasticsearch index name
      * @param string $type  Elasticsearch record type
+     *
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(string $index, string $type)
     {

+ 3 - 0
src/Monolog/Formatter/FluentdFormatter.php

@@ -42,6 +42,9 @@ class FluentdFormatter implements FormatterInterface
      */
     protected bool $levelTag = false;
 
+    /**
+     * @throws \RuntimeException If the function json_encode does not exist
+     */
     public function __construct(bool $levelTag = false)
     {
         if (!function_exists('json_encode')) {

+ 3 - 0
src/Monolog/Formatter/GelfMessageFormatter.php

@@ -63,6 +63,9 @@ class GelfMessageFormatter extends NormalizerFormatter
         };
     }
 
+    /**
+     * @throws \RuntimeException
+     */
     public function __construct(?string $systemName = null, ?string $extraPrefix = null, string $contextPrefix = 'ctxt_', ?int $maxLength = null)
     {
         if (!class_exists(Message::class)) {

+ 1 - 0
src/Monolog/Formatter/HtmlFormatter.php

@@ -43,6 +43,7 @@ class HtmlFormatter extends NormalizerFormatter
 
     /**
      * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(?string $dateFormat = null)
     {

+ 2 - 0
src/Monolog/Formatter/JsonFormatter.php

@@ -38,6 +38,8 @@ class JsonFormatter extends NormalizerFormatter
 
     /**
      * @param self::BATCH_MODE_* $batchMode
+     *
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(int $batchMode = self::BATCH_MODE_JSON, bool $appendNewline = true, bool $ignoreEmptyContextAndExtra = false, bool $includeStacktraces = false)
     {

+ 2 - 0
src/Monolog/Formatter/LineFormatter.php

@@ -37,6 +37,8 @@ class LineFormatter extends NormalizerFormatter
      * @param string|null $format                The format of the message
      * @param string|null $dateFormat            The format of the timestamp: one supported by DateTime::format
      * @param bool        $allowInlineLineBreaks Whether to allow inline line breaks in log entries
+     *
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(?string $format = null, ?string $dateFormat = null, bool $allowInlineLineBreaks = false, bool $ignoreEmptyContextAndExtra = false, bool $includeStacktraces = false)
     {

+ 2 - 0
src/Monolog/Formatter/LogstashFormatter.php

@@ -48,6 +48,8 @@ class LogstashFormatter extends NormalizerFormatter
      * @param string|null $systemName      The system/machine name, used as the "source" field of logstash, defaults to the hostname of the machine
      * @param string      $extraKey        The key for extra keys inside logstash "fields", defaults to extra
      * @param string      $contextKey      The key for context keys inside logstash "fields", defaults to context
+     *
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(string $applicationName, ?string $systemName = null, string $extraKey = 'extra', string $contextKey = 'context')
     {

+ 1 - 0
src/Monolog/Formatter/NormalizerFormatter.php

@@ -33,6 +33,7 @@ class NormalizerFormatter implements FormatterInterface
 
     /**
      * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(?string $dateFormat = null)
     {

+ 2 - 0
src/Monolog/Formatter/WildfireFormatter.php

@@ -25,6 +25,8 @@ class WildfireFormatter extends NormalizerFormatter
 {
     /**
      * @param string|null $dateFormat The format of the timestamp: one supported by DateTime::format
+     *
+     * @throws \RuntimeException If the function json_encode does not exist
      */
     public function __construct(?string $dateFormat = null)
     {

+ 3 - 0
src/Monolog/Handler/ChromePHPHandler.php

@@ -62,6 +62,9 @@ class ChromePHPHandler extends AbstractProcessingHandler
 
     protected static bool $sendHeaders = true;
 
+    /**
+     * @throws \RuntimeException If the function json_encode does not exist
+     */
     public function __construct(int|string|Level $level = Level::Debug, bool $bubble = true)
     {
         parent::__construct($level, $bubble);

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

@@ -33,6 +33,8 @@ 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
+     *
+     * @throws \InvalidArgumentException If an unsupported message type is set
      */
     public function __construct(int $messageType = self::OPERATING_SYSTEM, int|string|Level $level = Level::Debug, bool $bubble = true, bool $expandNewlines = false)
     {

+ 1 - 1
src/Monolog/Handler/FleepHookHandler.php

@@ -42,7 +42,7 @@ class FleepHookHandler extends SocketHandler
      * see https://fleep.io/integrations/webhooks/
      *
      * @param  string                    $token Webhook token
-     * @throws MissingExtensionException
+     * @throws MissingExtensionException if OpenSSL is missing
      */
     public function __construct(
         string $token,

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

@@ -31,6 +31,8 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset
     /**
      * @param HandlerInterface[] $handlers Array of Handlers.
      * @param bool               $bubble   Whether the messages that are handled can bubble up the stack or not
+     *
+     * @throws \InvalidArgumentException if an unsupported handler is set
      */
     public function __construct(array $handlers, bool $bubble = true)
     {

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

@@ -34,6 +34,8 @@ 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
+     *
+     * @throws MissingExtensionException If the curl extension is missing
      */
     public function __construct(string $eventName, string $secretKey, int|string|Level $level = Level::Error, bool $bubble = true)
     {

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

@@ -30,6 +30,8 @@ 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
+     *
+     * @throws \InvalidArgumentException if not a Swift Message is set
      */
     public function __construct(string $apiKey, callable|Swift_Message $message, int|string|Level $level = Level::Error, bool $bubble = true)
     {

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

@@ -52,6 +52,8 @@ class SendGridHandler extends MailHandler
      * @param string          $from    The sender of the email
      * @param string|string[] $to      The recipients of the email
      * @param string          $subject The subject of the mail
+     *
+     * @throws MissingExtensionException If the curl extension is missing
      */
     public function __construct(string $apiUser, string $apiKey, string $from, string|array $to, string $subject, int|string|Level $level = Level::Error, bool $bubble = true)
     {

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

@@ -44,6 +44,8 @@ class SlackWebhookHandler extends AbstractProcessingHandler
      * @param bool        $useShortAttachment     Whether the the context/extra messages added to Slack as attachments are in a short style
      * @param bool        $includeContextAndExtra Whether the attachment should include context and extra data
      * @param string[]    $excludeFields          Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
+     *
+     * @throws MissingExtensionException If the curl extension is missing
      */
     public function __construct(
         string $webhookUrl,

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

@@ -48,7 +48,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler
      * @param  bool                      $bubble   Whether the messages that are handled can bubble up the stack or not
      * @param  string                    $ident    Program name or tag for each log message.
      * @param  int                       $rfc      RFC to format the message for.
-     * @throws MissingExtensionException
+     * @throws MissingExtensionException when there is no socket extension
      *
      * @phpstan-param self::RFC* $rfc
      */

+ 1 - 1
src/Monolog/Handler/TelegramBotHandler.php

@@ -93,7 +93,7 @@ class TelegramBotHandler extends AbstractProcessingHandler
      * @param  string                    $channel              Telegram channel name
      * @param  bool                      $splitLongMessages    Split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages
      * @param  bool                      $delayBetweenMessages Adds delay between sending a split message according to Telegram API
-     * @throws MissingExtensionException
+     * @throws MissingExtensionException If the curl extension is missing
      */
     public function __construct(
         string $apiKey,