diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 2638adc7..83936849 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -21,9 +21,10 @@ $config = new PhpCsFixer\Config(); return $config->setRules(array( '@PSR2' => true, // some rules disabled as long as 1.x branch is maintained - 'binary_operator_spaces' => array( + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => [ 'default' => null, - ), + ], 'blank_line_before_statement' => ['statements' => ['continue', 'declare', 'return', 'throw', 'try']], 'cast_spaces' => ['space' => 'single'], 'header_comment' => ['header' => $header], @@ -35,6 +36,7 @@ return $config->setRules(array( 'no_extra_blank_lines' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], 'no_trailing_comma_in_singleline_array' => true, 'no_unused_imports' => true, 'no_whitespace_in_blank_line' => true, @@ -48,7 +50,6 @@ return $config->setRules(array( 'phpdoc_trim' => true, //'phpdoc_types' => true, 'psr_autoloading' => ['dir' => 'src'], - //'array_syntax' => array('syntax' => 'short'), 'declare_strict_types' => true, 'single_blank_line_before_namespace' => true, 'standardize_not_equals' => true, diff --git a/src/Monolog/Attribute/AsMonologProcessor.php b/src/Monolog/Attribute/AsMonologProcessor.php index b52d0776..9781efe0 100644 --- a/src/Monolog/Attribute/AsMonologProcessor.php +++ b/src/Monolog/Attribute/AsMonologProcessor.php @@ -13,9 +13,9 @@ namespace Monolog\Attribute; /** * A reusable attribute to help configure a class or a method as a processor. - * + * * Using it offers no guarantee: it needs to be leveraged by a Monolog third-party consumer. - * + * * Using it with the Monolog library only has no effect at all: processors should still be turned into a callable if * needed and manually pushed to the loggers and to the processable handlers. */ @@ -23,9 +23,9 @@ namespace Monolog\Attribute; class AsMonologProcessor { /** - * @param string|null $channel The logging channel the processor should be pushed to. - * @param string|null $handler The handler the processor should be pushed to. - * @param string|null $method The method that processes the records (if the attribute is used at the class level). + * @param string|null $channel The logging channel the processor should be pushed to. + * @param string|null $handler The handler the processor should be pushed to. + * @param string|null $method The method that processes the records (if the attribute is used at the class level). */ public function __construct( public ?string $channel = null, @@ -33,4 +33,4 @@ class AsMonologProcessor public ?string $method = null, ) { } -} \ No newline at end of file +} diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index aecef20b..78c36342 100644 --- a/src/Monolog/ErrorHandler.php +++ b/src/Monolog/ErrorHandler.php @@ -61,7 +61,6 @@ class ErrorHandler * * By default it will handle errors, exceptions and fatal errors * - * @param LoggerInterface $logger * @param array|false $errorLevelMap an array of E_* constant to LogLevel::* constant mapping, or false to disable error handling * @param array|false $exceptionLevelMap an array of class name to LogLevel::* constant mapping, or false to disable exception handling * @param LogLevel::*|null|false $fatalLevel a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling diff --git a/src/Monolog/Formatter/ChromePHPFormatter.php b/src/Monolog/Formatter/ChromePHPFormatter.php index 0551e1a2..8cc5abc8 100644 --- a/src/Monolog/Formatter/ChromePHPFormatter.php +++ b/src/Monolog/Formatter/ChromePHPFormatter.php @@ -12,7 +12,6 @@ namespace Monolog\Formatter; use Monolog\Level; -use Monolog\Logger; use Monolog\LogRecord; /** diff --git a/src/Monolog/Formatter/ElasticsearchFormatter.php b/src/Monolog/Formatter/ElasticsearchFormatter.php index 67d03f09..0709a8fe 100644 --- a/src/Monolog/Formatter/ElasticsearchFormatter.php +++ b/src/Monolog/Formatter/ElasticsearchFormatter.php @@ -56,8 +56,6 @@ class ElasticsearchFormatter extends NormalizerFormatter /** * Getter index - * - * @return string */ public function getIndex(): string { @@ -66,8 +64,6 @@ class ElasticsearchFormatter extends NormalizerFormatter /** * Getter type - * - * @return string */ public function getType(): string { diff --git a/src/Monolog/Formatter/FormatterInterface.php b/src/Monolog/Formatter/FormatterInterface.php index d65ae365..3413a4b0 100644 --- a/src/Monolog/Formatter/FormatterInterface.php +++ b/src/Monolog/Formatter/FormatterInterface.php @@ -24,7 +24,7 @@ interface FormatterInterface * Formats a log record. * * @param LogRecord $record A record to format - * @return mixed The formatted record + * @return mixed The formatted record */ public function format(LogRecord $record); @@ -32,7 +32,7 @@ interface FormatterInterface * Formats a set of log records. * * @param array $records A set of records to format - * @return mixed The formatted set of records + * @return mixed The formatted set of records */ public function formatBatch(array $records); } diff --git a/src/Monolog/Formatter/GelfMessageFormatter.php b/src/Monolog/Formatter/GelfMessageFormatter.php index 5d2d9de8..d6c5d673 100644 --- a/src/Monolog/Formatter/GelfMessageFormatter.php +++ b/src/Monolog/Formatter/GelfMessageFormatter.php @@ -12,7 +12,6 @@ namespace Monolog\Formatter; use Monolog\Level; -use Monolog\Logger; use Gelf\Message; use Monolog\Utils; use Monolog\LogRecord; diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index 2841a38e..8a8c2ccb 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -12,7 +12,6 @@ namespace Monolog\Formatter; use Monolog\Level; -use Monolog\Logger; use Monolog\Utils; use Monolog\LogRecord; @@ -70,8 +69,7 @@ class HtmlFormatter extends NormalizerFormatter /** * Create a HTML h1 tag * - * @param string $title Text to be in the h1 - * @return string + * @param string $title Text to be in the h1 */ protected function addTitle(string $title, Level $level): string { diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index 13bb1943..8f8fd7e7 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -105,7 +105,6 @@ class JsonFormatter extends NormalizerFormatter } /** - * @return self */ public function includeStacktraces(bool $include = true): self { @@ -142,10 +141,6 @@ class JsonFormatter extends NormalizerFormatter /** * Normalizes given $data. - * - * @param mixed $data - * - * @return mixed */ protected function normalize(mixed $data, int $depth = 0): mixed { diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 71307183..99cd6037 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -36,10 +36,9 @@ class LineFormatter extends NormalizerFormatter protected $includeStacktraces; /** - * @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 - * @param bool $ignoreEmptyContextAndExtra + * @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 */ public function __construct(?string $format = null, ?string $dateFormat = null, bool $allowInlineLineBreaks = false, bool $ignoreEmptyContextAndExtra = false, bool $includeStacktraces = false) { @@ -119,6 +118,7 @@ class LineFormatter extends NormalizerFormatter $output = preg_replace('/%(?:extra|context)\..+?%/', '', $output); if (null === $output) { $pcreErrorCode = preg_last_error(); + throw new \RuntimeException('Failed to run preg_replace: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode)); } } @@ -177,7 +177,7 @@ class LineFormatter extends NormalizerFormatter { if ($this->allowInlineLineBreaks) { if (0 === strpos($str, '{')) { - return str_replace(array('\r', '\n'), array("\r", "\n"), $str); + return str_replace(['\r', '\n'], ["\r", "\n"], $str); } return $str; diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index cc45fe50..2a92221e 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -149,7 +149,6 @@ class NormalizerFormatter implements FormatterInterface } /** - * @param mixed $data * @return null|scalar|array */ protected function normalize(mixed $data, int $depth = 0): mixed diff --git a/src/Monolog/Formatter/WildfireFormatter.php b/src/Monolog/Formatter/WildfireFormatter.php index 7badab35..ae2b85ee 100644 --- a/src/Monolog/Formatter/WildfireFormatter.php +++ b/src/Monolog/Formatter/WildfireFormatter.php @@ -12,7 +12,6 @@ namespace Monolog\Formatter; use Monolog\Level; -use Monolog\Logger; use Monolog\LogRecord; /** @@ -56,8 +55,6 @@ class WildfireFormatter extends NormalizerFormatter /** * {@inheritDoc} - * - * @return string */ public function format(LogRecord $record): string { diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index 8d248693..53b9600c 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/src/Monolog/Handler/AbstractHandler.php @@ -31,7 +31,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface /** * @param int|string|Level|LevelName|LogLevel::* $level The minimum logging level at which this handler will be triggered - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $level */ @@ -52,8 +52,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface /** * Sets minimum logging level at which this handler will be triggered. * - * @param Level|LevelName|LogLevel::* $level Level or level name - * @return self + * @param Level|LevelName|LogLevel::* $level Level or level name * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $level */ @@ -75,9 +74,8 @@ abstract class AbstractHandler extends Handler implements ResettableInterface /** * Sets the bubbling behavior. * - * @param bool $bubble true means that this handler allows bubbling. - * false means that bubbling is not permitted. - * @return self + * @param bool $bubble true means that this handler allows bubbling. + * false means that bubbling is not permitted. */ public function setBubble(bool $bubble): self { diff --git a/src/Monolog/Handler/BrowserConsoleHandler.php b/src/Monolog/Handler/BrowserConsoleHandler.php index 7c560de8..e75e3650 100644 --- a/src/Monolog/Handler/BrowserConsoleHandler.php +++ b/src/Monolog/Handler/BrowserConsoleHandler.php @@ -19,9 +19,6 @@ use Monolog\LogRecord; use function count; use function headers_list; use function stripos; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Handler sending logs to browser's javascript console with no browser extension required @@ -235,6 +232,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler if (null === $style) { $pcreErrorCode = preg_last_error(); + throw new \RuntimeException('Failed to run preg_replace_callback: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode)); } diff --git a/src/Monolog/Handler/Curl/Util.php b/src/Monolog/Handler/Curl/Util.php index 73a7660b..a8c02da9 100644 --- a/src/Monolog/Handler/Curl/Util.php +++ b/src/Monolog/Handler/Curl/Util.php @@ -34,10 +34,8 @@ final class Util /** * Executes a CURL request with optional retries and exception on failure * - * @param CurlHandle $ch curl handler - * @param int $retries - * @param bool $closeAfterDone - * @return bool|string @see curl_exec + * @param CurlHandle $ch curl handler + * @return bool|string @see curl_exec */ public static function execute($ch, int $retries = 5, bool $closeAfterDone = true) { diff --git a/src/Monolog/Handler/DeduplicationHandler.php b/src/Monolog/Handler/DeduplicationHandler.php index f1f01e3b..e8c171cc 100644 --- a/src/Monolog/Handler/DeduplicationHandler.php +++ b/src/Monolog/Handler/DeduplicationHandler.php @@ -60,11 +60,11 @@ class DeduplicationHandler extends BufferHandler private $gc = false; /** - * @param HandlerInterface $handler Handler. - * @param string $deduplicationStore The file/path where the deduplication log should be kept + * @param HandlerInterface $handler Handler. + * @param string $deduplicationStore The file/path where the deduplication log should be kept * @param int|string|Level|LevelName|LogLevel::* $deduplicationLevel The minimum logging level for log records to be looked at for deduplication purposes - * @param int $time The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through - * @param bool $bubble Whether the messages that are handled can bubble up the stack or not + * @param int $time The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $deduplicationLevel */ diff --git a/src/Monolog/Handler/ErrorLogHandler.php b/src/Monolog/Handler/ErrorLogHandler.php index a80b63ad..6847e690 100644 --- a/src/Monolog/Handler/ErrorLogHandler.php +++ b/src/Monolog/Handler/ErrorLogHandler.php @@ -83,6 +83,7 @@ class ErrorLogHandler extends AbstractProcessingHandler $lines = preg_split('{[\r\n]+}', (string) $record->formatted); if ($lines === false) { $pcreErrorCode = preg_last_error(); + throw new \RuntimeException('Failed to preg_split formatted string: ' . $pcreErrorCode . ' / '. Utils::pcreLastErrorMessage($pcreErrorCode)); } foreach ($lines as $line) { diff --git a/src/Monolog/Handler/FilterHandler.php b/src/Monolog/Handler/FilterHandler.php index b5dec938..908216a1 100644 --- a/src/Monolog/Handler/FilterHandler.php +++ b/src/Monolog/Handler/FilterHandler.php @@ -57,10 +57,10 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese /** * @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * - * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $filterHandler). + * @param callable|HandlerInterface $handler Handler or factory callable($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 + * @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 * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::*|array|value-of|Level|LevelName|LogLevel::*> $minLevelOrList * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $maxLevel @@ -81,12 +81,12 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese */ public function getAcceptedLevels(): array { - return array_map(fn(int $level) => Level::from($level), array_keys($this->acceptedLevels)); + return array_map(fn (int $level) => Level::from($level), array_keys($this->acceptedLevels)); } /** * @param int|string|Level|LevelName|LogLevel::*|array $minLevelOrList A list of levels to accept or a minimum level or level name if maxLevel is provided - * @param int|string|Level|LevelName|LogLevel::* $maxLevel Maximum level or level name to accept, only used if $minLevelOrList is not an array + * @param int|string|Level|LevelName|LogLevel::* $maxLevel Maximum level or level name to accept, only used if $minLevelOrList is not an array * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::*|array|value-of|Level|LevelName|LogLevel::*> $minLevelOrList * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $maxLevel diff --git a/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php b/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php index 4da75dff..0aafa7b2 100644 --- a/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php +++ b/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php @@ -47,7 +47,7 @@ class ChannelLevelActivationStrategy implements ActivationStrategyInterface private array $channelToActionLevel; /** - * @param int|string|Level|LevelName|LogLevel::* $defaultActionLevel The default action level to be used if the record's category doesn't match any + * @param int|string|Level|LevelName|LogLevel::* $defaultActionLevel The default action level to be used if the record's category doesn't match any * @param array $channelToActionLevel An array that maps channel names to action levels. * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $defaultActionLevel diff --git a/src/Monolog/Handler/FleepHookHandler.php b/src/Monolog/Handler/FleepHookHandler.php index 9f84c5bb..4b51b6a9 100644 --- a/src/Monolog/Handler/FleepHookHandler.php +++ b/src/Monolog/Handler/FleepHookHandler.php @@ -41,7 +41,7 @@ class FleepHookHandler extends SocketHandler * For instructions on how to create a new web hook in your conversations * see https://fleep.io/integrations/webhooks/ * - * @param string $token Webhook token + * @param string $token Webhook token * @throws MissingExtensionException */ public function __construct( diff --git a/src/Monolog/Handler/FormattableHandlerInterface.php b/src/Monolog/Handler/FormattableHandlerInterface.php index fc1693cd..72da59e1 100644 --- a/src/Monolog/Handler/FormattableHandlerInterface.php +++ b/src/Monolog/Handler/FormattableHandlerInterface.php @@ -23,15 +23,12 @@ interface FormattableHandlerInterface /** * Sets the formatter. * - * @param FormatterInterface $formatter - * @return HandlerInterface self + * @return HandlerInterface self */ public function setFormatter(FormatterInterface $formatter): HandlerInterface; /** * Gets the formatter. - * - * @return FormatterInterface */ public function getFormatter(): FormatterInterface; } diff --git a/src/Monolog/Handler/HandlerInterface.php b/src/Monolog/Handler/HandlerInterface.php index 53bf28bf..83905c32 100644 --- a/src/Monolog/Handler/HandlerInterface.php +++ b/src/Monolog/Handler/HandlerInterface.php @@ -30,8 +30,6 @@ interface HandlerInterface * for a given record. * * @param LogRecord $record Partial log record having only a level initialized - * - * @return bool */ public function isHandling(LogRecord $record): bool; @@ -46,8 +44,8 @@ interface HandlerInterface * calling further handlers in the stack with a given log record. * * @param LogRecord $record The record to handle - * @return bool true means that this handler handled the record, and that bubbling is not permitted. - * false means the record was either not processed or that this handler allows bubbling. + * @return bool true means that this handler handled the record, and that bubbling is not permitted. + * false means the record was either not processed or that this handler allows bubbling. */ public function handle(LogRecord $record): bool; diff --git a/src/Monolog/Handler/InsightOpsHandler.php b/src/Monolog/Handler/InsightOpsHandler.php index f6632187..ca120e1e 100644 --- a/src/Monolog/Handler/InsightOpsHandler.php +++ b/src/Monolog/Handler/InsightOpsHandler.php @@ -28,9 +28,9 @@ class InsightOpsHandler extends SocketHandler protected $logToken; /** - * @param string $token Log token supplied by InsightOps - * @param string $region Region where InsightOps account is hosted. Could be 'us' or 'eu'. - * @param bool $useSSL Whether or not SSL encryption should be used + * @param string $token Log token supplied by InsightOps + * @param string $region Region where InsightOps account is hosted. Could be 'us' or 'eu'. + * @param bool $useSSL Whether or not SSL encryption should be used * * @throws MissingExtensionException If SSL encryption is set to true and OpenSSL is missing */ diff --git a/src/Monolog/Handler/LogEntriesHandler.php b/src/Monolog/Handler/LogEntriesHandler.php index ffa2b0a9..5695f524 100644 --- a/src/Monolog/Handler/LogEntriesHandler.php +++ b/src/Monolog/Handler/LogEntriesHandler.php @@ -25,9 +25,9 @@ class LogEntriesHandler extends SocketHandler protected $logToken; /** - * @param string $token Log token supplied by LogEntries - * @param bool $useSSL Whether or not SSL encryption should be used. - * @param string $host Custom hostname to send the data to if needed + * @param string $token Log token supplied by LogEntries + * @param bool $useSSL Whether or not SSL encryption should be used. + * @param string $host Custom hostname to send the data to if needed * * @throws MissingExtensionException If SSL encryption is set to true and OpenSSL is missing */ diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index 07cad391..e451ddf0 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -63,7 +63,6 @@ class LogglyHandler extends AbstractProcessingHandler /** * Loads and returns the shared curl handler for the given endpoint. * - * @param string $endpoint * * @return CurlHandle */ @@ -79,7 +78,6 @@ class LogglyHandler extends AbstractProcessingHandler /** * Starts a fresh curl session for the given endpoint and returns its handler. * - * @param string $endpoint * * @return CurlHandle */ diff --git a/src/Monolog/Handler/LogmaticHandler.php b/src/Monolog/Handler/LogmaticHandler.php index b82bfbf1..45364726 100644 --- a/src/Monolog/Handler/LogmaticHandler.php +++ b/src/Monolog/Handler/LogmaticHandler.php @@ -37,10 +37,10 @@ class LogmaticHandler extends SocketHandler private $appname; /** - * @param string $token Log token supplied by Logmatic. - * @param string $hostname Host name supplied by Logmatic. - * @param string $appname Application name supplied by Logmatic. - * @param bool $useSSL Whether or not SSL encryption should be used. + * @param string $token Log token supplied by Logmatic. + * @param string $hostname Host name supplied by Logmatic. + * @param string $appname Application name supplied by Logmatic. + * @param bool $useSSL Whether or not SSL encryption should be used. * * @throws MissingExtensionException If SSL encryption is set to true and OpenSSL is missing */ diff --git a/src/Monolog/Handler/MailHandler.php b/src/Monolog/Handler/MailHandler.php index decd260c..69808899 100644 --- a/src/Monolog/Handler/MailHandler.php +++ b/src/Monolog/Handler/MailHandler.php @@ -83,8 +83,6 @@ abstract class MailHandler extends AbstractProcessingHandler /** * Gets the default formatter. - * - * @return FormatterInterface */ protected function getDefaultFormatter(): FormatterInterface { diff --git a/src/Monolog/Handler/NewRelicHandler.php b/src/Monolog/Handler/NewRelicHandler.php index 3b3ae758..39760665 100644 --- a/src/Monolog/Handler/NewRelicHandler.php +++ b/src/Monolog/Handler/NewRelicHandler.php @@ -52,10 +52,6 @@ class NewRelicHandler extends AbstractProcessingHandler /** * {@inheritDoc} - * - * @param string|null $appName - * @param bool $explodeArrays - * @param string|null $transactionName */ public function __construct( $level = Level::Error, @@ -123,8 +119,6 @@ class NewRelicHandler extends AbstractProcessingHandler /** * Checks whether the NewRelic extension is enabled in the system. - * - * @return bool */ protected function isNewRelicEnabled(): bool { @@ -178,8 +172,7 @@ class NewRelicHandler extends AbstractProcessingHandler } /** - * @param string $key - * @param mixed $value + * @param mixed $value */ protected function setNewRelicParameter(string $key, $value): void { diff --git a/src/Monolog/Handler/OverflowHandler.php b/src/Monolog/Handler/OverflowHandler.php index d1f42781..bd62316e 100644 --- a/src/Monolog/Handler/OverflowHandler.php +++ b/src/Monolog/Handler/OverflowHandler.php @@ -51,8 +51,7 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter private $buffer = []; /** - * @param HandlerInterface $handler - * @param array $thresholdMap Dictionary of log level value => threshold + * @param array $thresholdMap Dictionary of log level value => threshold */ public function __construct( HandlerInterface $handler, diff --git a/src/Monolog/Handler/PsrHandler.php b/src/Monolog/Handler/PsrHandler.php index 30369e27..6b45c3d6 100644 --- a/src/Monolog/Handler/PsrHandler.php +++ b/src/Monolog/Handler/PsrHandler.php @@ -70,8 +70,6 @@ class PsrHandler extends AbstractHandler implements FormattableHandlerInterface /** * Sets the formatter. - * - * @param FormatterInterface $formatter */ public function setFormatter(FormatterInterface $formatter): HandlerInterface { @@ -82,8 +80,6 @@ class PsrHandler extends AbstractHandler implements FormattableHandlerInterface /** * Gets the formatter. - * - * @return FormatterInterface */ public function getFormatter(): FormatterInterface { diff --git a/src/Monolog/Handler/PushoverHandler.php b/src/Monolog/Handler/PushoverHandler.php index 0e3db9dc..c2a3129a 100644 --- a/src/Monolog/Handler/PushoverHandler.php +++ b/src/Monolog/Handler/PushoverHandler.php @@ -77,15 +77,15 @@ class PushoverHandler extends SocketHandler ]; /** - * @param string $token Pushover api token - * @param string|array $users Pushover user id or array of ids the message will be sent to - * @param string|null $title Title sent to the Pushover API - * @param bool $useSSL Whether to connect via SSL. Required when pushing messages to users that are not - * the pushover.net app owner. OpenSSL is required for this option. - * @param int $retry The retry parameter specifies how often (in seconds) the Pushover servers will - * send the same notification to the user. - * @param int $expire The expire parameter specifies how many seconds your notification will continue - * to be retried for (every retry seconds). + * @param string $token Pushover api token + * @param string|array $users Pushover user id or array of ids the message will be sent to + * @param string|null $title Title sent to the Pushover API + * @param bool $useSSL Whether to connect via SSL. Required when pushing messages to users that are not + * the pushover.net app owner. OpenSSL is required for this option. + * @param int $retry The retry parameter specifies how often (in seconds) the Pushover servers will + * send the same notification to the user. + * @param int $expire The expire parameter specifies how many seconds your notification will continue + * to be retried for (every retry seconds). * * @param int|string|Level|LevelName|LogLevel::* $highPriorityLevel The minimum logging level at which this handler will start * sending "high priority" requests to the Pushover API diff --git a/src/Monolog/Handler/RedisHandler.php b/src/Monolog/Handler/RedisHandler.php index eecbf837..a559f5ff 100644 --- a/src/Monolog/Handler/RedisHandler.php +++ b/src/Monolog/Handler/RedisHandler.php @@ -38,8 +38,8 @@ class RedisHandler extends AbstractProcessingHandler /** * @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance - * @param string $key The key name to push records to - * @param int $capSize Number of entries to limit list size to, 0 = unlimited + * @param string $key The key name to push records to + * @param int $capSize Number of entries to limit list size to, 0 = unlimited */ public function __construct($redis, string $key, $level = Level::Debug, bool $bubble = true, int $capSize = 0) { diff --git a/src/Monolog/Handler/RedisPubSubHandler.php b/src/Monolog/Handler/RedisPubSubHandler.php index 01138cc7..004ca605 100644 --- a/src/Monolog/Handler/RedisPubSubHandler.php +++ b/src/Monolog/Handler/RedisPubSubHandler.php @@ -36,7 +36,7 @@ class RedisPubSubHandler extends AbstractProcessingHandler /** * @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance - * @param string $key The channel key to publish records to + * @param string $key The channel key to publish records to */ public function __construct($redis, string $key, $level = Level::Debug, bool $bubble = true) { diff --git a/src/Monolog/Handler/RollbarHandler.php b/src/Monolog/Handler/RollbarHandler.php index 1f082cd6..fd5d127d 100644 --- a/src/Monolog/Handler/RollbarHandler.php +++ b/src/Monolog/Handler/RollbarHandler.php @@ -86,7 +86,7 @@ class RollbarHandler extends AbstractProcessingHandler { if (!$this->initialized) { // __destructor() doesn't get called on Fatal errors - register_shutdown_function(array($this, 'close')); + register_shutdown_function([$this, 'close']); $this->initialized = true; } diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index e7d27aac..c0d491db 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -45,10 +45,9 @@ class RotatingFileHandler extends StreamHandler protected $dateFormat; /** - * @param string $filename - * @param int $maxFiles The maximal amount of files to keep (0 means unlimited) - * @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 + * @param int $maxFiles The maximal amount of files to keep (0 means unlimited) + * @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) { diff --git a/src/Monolog/Handler/Slack/SlackRecord.php b/src/Monolog/Handler/Slack/SlackRecord.php index 0a87babf..141342bd 100644 --- a/src/Monolog/Handler/Slack/SlackRecord.php +++ b/src/Monolog/Handler/Slack/SlackRecord.php @@ -97,7 +97,7 @@ class SlackRecord ?string $userIcon = null, bool $useShortAttachment = false, bool $includeContextAndExtra = false, - array $excludeFields = array(), + array $excludeFields = [], FormatterInterface $formatter = null ) { $this @@ -123,7 +123,7 @@ class SlackRecord */ public function getSlackData(LogRecord $record): array { - $dataArray = array(); + $dataArray = []; if ($this->username) { $dataArray['username'] = $this->username; @@ -142,16 +142,16 @@ class SlackRecord $recordData = $this->removeExcludedFields($record); if ($this->useAttachment) { - $attachment = array( + $attachment = [ 'fallback' => $message, 'text' => $message, 'color' => $this->getAttachmentColor($record->level), - 'fields' => array(), - 'mrkdwn_in' => array('fields'), + 'fields' => [], + 'mrkdwn_in' => ['fields'], 'ts' => $recordData['datetime']->getTimestamp(), 'footer' => $this->username, 'footer_icon' => $this->userIcon, - ); + ]; if ($this->useShortAttachment) { $attachment['title'] = $recordData['level_name']; @@ -161,7 +161,7 @@ class SlackRecord } if ($this->includeContextAndExtra) { - foreach (array('extra', 'context') as $key) { + foreach (['extra', 'context'] as $key) { if (empty($recordData[$key])) { continue; } @@ -181,7 +181,7 @@ class SlackRecord } } - $dataArray['attachments'] = array($attachment); + $dataArray['attachments'] = [$attachment]; } else { $dataArray['text'] = $message; } @@ -323,11 +323,11 @@ class SlackRecord ? sprintf('```%s```', substr($this->stringify($value), 0, 1990)) : $value; - return array( + return [ 'title' => ucfirst($title), 'value' => $value, 'short' => false, - ); + ]; } /** @@ -342,7 +342,7 @@ class SlackRecord /** @var array $normalized */ $normalized = $this->normalizerFormatter->normalizeValue($data); - $fields = array(); + $fields = []; foreach ($normalized as $key => $value) { $fields[] = $this->generateAttachmentField((string) $key, $value); } diff --git a/src/Monolog/Handler/SlackHandler.php b/src/Monolog/Handler/SlackHandler.php index fb85cd01..063606a4 100644 --- a/src/Monolog/Handler/SlackHandler.php +++ b/src/Monolog/Handler/SlackHandler.php @@ -58,7 +58,7 @@ class SlackHandler extends SocketHandler bool $bubble = true, bool $useShortAttachment = false, bool $includeContextAndExtra = false, - array $excludeFields = array(), + array $excludeFields = [], bool $persistent = false, float $timeout = 0.0, float $writingTimeout = 10.0, diff --git a/src/Monolog/Handler/SlackWebhookHandler.php b/src/Monolog/Handler/SlackWebhookHandler.php index c98c1c3d..c0f2aaba 100644 --- a/src/Monolog/Handler/SlackWebhookHandler.php +++ b/src/Monolog/Handler/SlackWebhookHandler.php @@ -57,7 +57,7 @@ class SlackWebhookHandler extends AbstractProcessingHandler bool $includeContextAndExtra = false, $level = Level::Critical, bool $bubble = true, - array $excludeFields = array() + array $excludeFields = [] ) { if (!extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the SlackWebhookHandler'); @@ -97,13 +97,13 @@ class SlackWebhookHandler extends AbstractProcessingHandler $postString = Utils::jsonEncode($postData); $ch = curl_init(); - $options = array( + $options = [ CURLOPT_URL => $this->webhookUrl, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER => array('Content-type: application/json'), + CURLOPT_HTTPHEADER => ['Content-type: application/json'], CURLOPT_POSTFIELDS => $postString, - ); + ]; if (defined('CURLOPT_SAFE_UPLOAD')) { $options[CURLOPT_SAFE_UPLOAD] = true; } diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index 727666c4..517c12f8 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -54,7 +54,7 @@ class SocketHandler extends AbstractProcessingHandler * established * @param int|null $chunkSize Sets the chunk size. Only has effect during connection in the writing cycle * - * @throws \InvalidArgumentException If an invalid timeout value (less than 0) is passed. + * @throws \InvalidArgumentException If an invalid timeout value (less than 0) is passed. */ public function __construct( string $connectionString, @@ -211,8 +211,6 @@ class SocketHandler extends AbstractProcessingHandler /** * Get current local writing timeout - * - * @return float */ public function getWritingTimeout(): float { diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 328c4ea6..a63d0140 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -105,8 +105,6 @@ class StreamHandler extends AbstractProcessingHandler /** * Return the stream URL if it was configured with a URL and not an active resource - * - * @return string|null */ public function getUrl(): ?string { @@ -114,7 +112,6 @@ class StreamHandler extends AbstractProcessingHandler } /** - * @return int */ public function getStreamChunkSize(): int { diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index 73d28681..04b3f07e 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -36,7 +36,6 @@ class SyslogHandler extends AbstractSyslogHandler protected $logopts; /** - * @param string $ident * @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 */ diff --git a/src/Monolog/Handler/SyslogUdpHandler.php b/src/Monolog/Handler/SyslogUdpHandler.php index 7fe92b14..3c070521 100644 --- a/src/Monolog/Handler/SyslogUdpHandler.php +++ b/src/Monolog/Handler/SyslogUdpHandler.php @@ -30,11 +30,11 @@ class SyslogUdpHandler extends AbstractSyslogHandler const RFC5424e = 2; /** @var array */ - private $dateFormats = array( + private $dateFormats = [ self::RFC3164 => 'M d H:i:s', self::RFC5424 => \DateTime::RFC3339, self::RFC5424e => \DateTime::RFC3339_EXTENDED, - ); + ]; /** @var UdpSocket */ protected $socket; @@ -44,12 +44,12 @@ class SyslogUdpHandler extends AbstractSyslogHandler protected $rfc; /** - * @param string $host Either IP/hostname or a path to a unix socket (port must be 0 then) - * @param int $port Port number, or 0 if $host is a unix socket - * @param string|int $facility Either one of the names of the keys in $this->facilities, or a LOG_* facility constant - * @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. + * @param string $host Either IP/hostname or a path to a unix socket (port must be 0 then) + * @param int $port Port number, or 0 if $host is a unix socket + * @param string|int $facility Either one of the names of the keys in $this->facilities, or a LOG_* facility constant + * @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 * * @phpstan-param self::RFC* $rfc @@ -97,6 +97,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler $lines = preg_split('/$\R?^/m', (string) $message, -1, PREG_SPLIT_NO_EMPTY); if (false === $lines) { $pcreErrorCode = preg_last_error(); + throw new \RuntimeException('Could not preg_split: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode)); } diff --git a/src/Monolog/Handler/TelegramBotHandler.php b/src/Monolog/Handler/TelegramBotHandler.php index 0d22455c..3125e8e6 100644 --- a/src/Monolog/Handler/TelegramBotHandler.php +++ b/src/Monolog/Handler/TelegramBotHandler.php @@ -96,24 +96,23 @@ class TelegramBotHandler extends AbstractProcessingHandler private $delayBetweenMessages; /** - * @param string $apiKey Telegram bot access token provided by BotFather - * @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 + * @param string $apiKey Telegram bot access token provided by BotFather + * @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 */ public function __construct( string $apiKey, string $channel, - $level = Level::Debug, + $level = Level::Debug, bool $bubble = true, string $parseMode = null, bool $disableWebPagePreview = null, bool $disableNotification = null, bool $splitLongMessages = false, bool $delayBetweenMessages = false - ) - { + ) { if (!extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the TelegramBotHandler'); } @@ -157,7 +156,6 @@ class TelegramBotHandler extends AbstractProcessingHandler /** * True - split a message longer than MAX_MESSAGE_LENGTH into parts and send in multiple messages. * False - truncates a message that is too long. - * @param bool $splitLongMessages * @return $this */ public function splitLongMessages(bool $splitLongMessages = false): self @@ -169,7 +167,6 @@ class TelegramBotHandler extends AbstractProcessingHandler /** * Adds 1-second delay between sending a split message (according to Telegram API to avoid 429 Too Many Requests). - * @param bool $delayBetweenMessages * @return $this */ public function delayBetweenMessages(bool $delayBetweenMessages = false): self @@ -199,7 +196,7 @@ class TelegramBotHandler extends AbstractProcessingHandler } if (!empty($messages)) { - $this->send((string)$this->getFormatter()->formatBatch($messages)); + $this->send((string) $this->getFormatter()->formatBatch($messages)); } } @@ -213,7 +210,6 @@ class TelegramBotHandler extends AbstractProcessingHandler /** * Send request to @link https://api.telegram.org/bot on SendMessage action. - * @param string $message */ protected function send(string $message): void { @@ -256,7 +252,6 @@ class TelegramBotHandler extends AbstractProcessingHandler /** * Handle a message that is too long: truncates or splits into several - * @param string $message * @return string[] */ private function handleMessageLength(string $message): array diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index 53143598..8c23d416 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/src/Monolog/Handler/TestHandler.php @@ -198,6 +198,7 @@ class TestHandler extends AbstractProcessingHandler $callback = [$this, $genericMethod]; if (is_callable($callback)) { $args[] = $level; + return call_user_func_array($callback, $args); } } diff --git a/src/Monolog/Handler/WebRequestRecognizerTrait.php b/src/Monolog/Handler/WebRequestRecognizerTrait.php index c8183528..9c12c3d5 100644 --- a/src/Monolog/Handler/WebRequestRecognizerTrait.php +++ b/src/Monolog/Handler/WebRequestRecognizerTrait.php @@ -15,7 +15,6 @@ trait WebRequestRecognizerTrait { /** * Checks if PHP's serving a web request - * @return bool */ protected function isWebRequest(): bool { diff --git a/src/Monolog/Handler/WhatFailureGroupHandler.php b/src/Monolog/Handler/WhatFailureGroupHandler.php index b26f21f6..8d4dd2b8 100644 --- a/src/Monolog/Handler/WhatFailureGroupHandler.php +++ b/src/Monolog/Handler/WhatFailureGroupHandler.php @@ -48,7 +48,7 @@ class WhatFailureGroupHandler extends GroupHandler public function handleBatch(array $records): void { if ($this->processors) { - $processed = array(); + $processed = []; foreach ($records as $record) { $processed[] = $this->processRecord($record); } diff --git a/src/Monolog/Handler/ZendMonitorHandler.php b/src/Monolog/Handler/ZendMonitorHandler.php index 32f9c611..e6335633 100644 --- a/src/Monolog/Handler/ZendMonitorHandler.php +++ b/src/Monolog/Handler/ZendMonitorHandler.php @@ -55,7 +55,6 @@ class ZendMonitorHandler extends AbstractProcessingHandler }; } - /** * {@inheritDoc} */ @@ -71,10 +70,10 @@ class ZendMonitorHandler extends AbstractProcessingHandler /** * Write to Zend Monitor Events - * @param string $type Text displayed in "Class Name (custom)" field - * @param string $message Text displayed in "Error String" + * @param string $type Text displayed in "Class Name (custom)" field + * @param string $message Text displayed in "Error String" * @param array $formatted Displayed in Custom Variables tab - * @param int $severity Set the event severity level (-1,0,1) + * @param int $severity Set the event severity level (-1,0,1) */ protected function writeZendMonitorCustomEvent(string $type, string $message, array $formatted, int $severity): void { diff --git a/src/Monolog/Level.php b/src/Monolog/Level.php index 70c39486..a4c29536 100644 --- a/src/Monolog/Level.php +++ b/src/Monolog/Level.php @@ -1,4 +1,13 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Monolog; @@ -97,7 +106,6 @@ enum Level: int } /** - * @return string * @phpstan-return \Psr\Log\LogLevel::* */ public function toPsrLogLevel(): string diff --git a/src/Monolog/LevelName.php b/src/Monolog/LevelName.php index 7d26d9f1..b7ff371c 100644 --- a/src/Monolog/LevelName.php +++ b/src/Monolog/LevelName.php @@ -1,4 +1,13 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Monolog; diff --git a/src/Monolog/LogRecord.php b/src/Monolog/LogRecord.php index 47fc66c7..df6d0cf8 100644 --- a/src/Monolog/LogRecord.php +++ b/src/Monolog/LogRecord.php @@ -50,11 +50,13 @@ class LogRecord implements ArrayAccess } $this->extra = $value; + return; } if ($offset === 'formatted') { $this->formatted = $value; + return; } diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index bf985d2c..e38f87d1 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -237,7 +237,6 @@ class Logger implements LoggerInterface, ResettableInterface * Removes the processor on top of the stack and returns it. * * @throws \LogicException If empty processor stack - * @return callable */ public function popProcessor(): callable { @@ -379,7 +378,7 @@ class Logger implements LoggerInterface, ResettableInterface * Converts PSR-3 levels to Monolog ones if necessary * * @param int|string|Level|LevelName|LogLevel::* $level Level number (monolog) or name (PSR-3) - * @throws \Psr\Log\InvalidArgumentException If level is not defined + * @throws \Psr\Log\InvalidArgumentException If level is not defined * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $level */ diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index 357bd71f..8ff10818 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -44,7 +44,7 @@ class IntrospectionProcessor implements ProcessorInterface /** * @param string|int|Level|LevelName $level The minimum logging level at which this Processor will be triggered - * @param string[] $skipClassesPartials + * @param string[] $skipClassesPartials * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $level */ diff --git a/src/Monolog/Processor/MemoryProcessor.php b/src/Monolog/Processor/MemoryProcessor.php index 227deb7c..89baadbf 100644 --- a/src/Monolog/Processor/MemoryProcessor.php +++ b/src/Monolog/Processor/MemoryProcessor.php @@ -41,7 +41,6 @@ abstract class MemoryProcessor implements ProcessorInterface /** * Formats bytes into a human readable string if $this->useFormatting is true, otherwise return $bytes as is * - * @param int $bytes * @return string|int Formatted string if $this->useFormatting is true, otherwise return $bytes as int */ protected function formatBytes(int $bytes) diff --git a/src/Monolog/Processor/UidProcessor.php b/src/Monolog/Processor/UidProcessor.php index 973b317e..835307ef 100644 --- a/src/Monolog/Processor/UidProcessor.php +++ b/src/Monolog/Processor/UidProcessor.php @@ -57,7 +57,7 @@ class UidProcessor implements ProcessorInterface, ResettableInterface } /** - * @param positive-int $length + * @param positive-int $length * @return non-empty-string */ private function generateUid(int $length): string diff --git a/src/Monolog/SignalHandler.php b/src/Monolog/SignalHandler.php index b9f92abd..8c022730 100644 --- a/src/Monolog/SignalHandler.php +++ b/src/Monolog/SignalHandler.php @@ -38,10 +38,7 @@ class SignalHandler } /** - * @param int|string|Level|LevelName $level Level or level name - * @param bool $callPrevious - * @param bool $restartSyscalls - * @param bool|null $async + * @param int|string|Level|LevelName $level Level or level name * @return $this * * @phpstan-param value-of|value-of|Level|LevelName|LogLevel::* $level diff --git a/src/Monolog/Utils.php b/src/Monolog/Utils.php index 1df3a355..4a1d9e98 100644 --- a/src/Monolog/Utils.php +++ b/src/Monolog/Utils.php @@ -122,7 +122,7 @@ final class Utils if (is_string($data)) { self::detectAndCleanUtf8($data); } elseif (is_array($data)) { - array_walk_recursive($data, array('Monolog\Utils', 'detectAndCleanUtf8')); + array_walk_recursive($data, ['Monolog\Utils', 'detectAndCleanUtf8']); } else { self::throwEncodeError($code, $data); } @@ -206,6 +206,7 @@ final class Utils ); if (!is_string($data)) { $pcreErrorCode = preg_last_error(); + throw new \RuntimeException('Failed to preg_replace_callback: ' . $pcreErrorCode . ' / ' . self::pcreLastErrorMessage($pcreErrorCode)); } $data = str_replace( @@ -219,8 +220,8 @@ final class Utils /** * Converts a string with a valid 'memory_limit' format, to bytes. * - * @param string|false $val - * @return int|false Returns an integer representing bytes. Returns FALSE in case of error. + * @param string|false $val + * @return int|false Returns an integer representing bytes. Returns FALSE in case of error. */ public static function expandIniShorthandBytes($val) { @@ -241,8 +242,10 @@ final class Utils switch (strtolower($match['unit'] ?? '')) { case 'g': $val *= 1024; + // no break case 'm': $val *= 1024; + // no break case 'k': $val *= 1024; } @@ -254,6 +257,7 @@ final class Utils { $context = ''; $extra = ''; + try { if ($record->context) { $context = "\nContext: " . json_encode($record->context, JSON_THROW_ON_ERROR); diff --git a/tests/Monolog/Attribute/AsMonologProcessorTest.php b/tests/Monolog/Attribute/AsMonologProcessorTest.php index fe93d280..b0af8f6f 100644 --- a/tests/Monolog/Attribute/AsMonologProcessorTest.php +++ b/tests/Monolog/Attribute/AsMonologProcessorTest.php @@ -30,4 +30,4 @@ final class AsMonologProcessorTest extends TestCase $this->assertNull($asMonologProcessor->handler); $this->assertNull($asMonologProcessor->method); } -} \ No newline at end of file +} diff --git a/tests/Monolog/Formatter/ElasticaFormatterTest.php b/tests/Monolog/Formatter/ElasticaFormatterTest.php index 64b64286..2698b60a 100644 --- a/tests/Monolog/Formatter/ElasticaFormatterTest.php +++ b/tests/Monolog/Formatter/ElasticaFormatterTest.php @@ -12,7 +12,6 @@ namespace Monolog\Formatter; use Monolog\Level; -use Monolog\LogRecord; use Monolog\Test\TestCase; class ElasticaFormatterTest extends TestCase diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index b33687a6..eb72aa64 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -219,7 +219,7 @@ class GelfMessageFormatterTest extends TestCase $length = 200; foreach ($messageArray as $key => $value) { - if (!in_array($key, array('level', 'timestamp'))) { + if (!in_array($key, ['level', 'timestamp'])) { $length += strlen($value); } } diff --git a/tests/Monolog/Formatter/JsonFormatterTest.php b/tests/Monolog/Formatter/JsonFormatterTest.php index cab71f93..d8334f13 100644 --- a/tests/Monolog/Formatter/JsonFormatterTest.php +++ b/tests/Monolog/Formatter/JsonFormatterTest.php @@ -205,9 +205,6 @@ class JsonFormatterTest extends TestCase } /** - * @param JsonFormatter $formatter - * @param \Throwable $exception - * * @return string */ private function formatRecordWithExceptionInContext(JsonFormatter $formatter, \Throwable $exception) @@ -265,7 +262,7 @@ class JsonFormatterTest extends TestCase Level::Critical, 'bar', channel: 'test', - context: array($largeArray), + context: [$largeArray], )); $this->assertCount(1000, $res['context'][0]); @@ -281,7 +278,7 @@ class JsonFormatterTest extends TestCase Level::Critical, 'bar', channel: 'test', - context: array($largeArray), + context: [$largeArray], )); $this->assertCount(1001, $res['context'][0]); diff --git a/tests/Monolog/Formatter/MongoDBFormatterTest.php b/tests/Monolog/Formatter/MongoDBFormatterTest.php index 73d7ea99..2a58190d 100644 --- a/tests/Monolog/Formatter/MongoDBFormatterTest.php +++ b/tests/Monolog/Formatter/MongoDBFormatterTest.php @@ -274,6 +274,5 @@ class MongoDBFormatterTest extends TestCase $this->assertInstanceOf(ObjectId::class, $formattedRecord['context']['objectid']); $this->assertInstanceOf(UTCDateTime::class, $formattedRecord['context']['nest']['timestamp']); $this->assertInstanceOf(Regex::class, $formattedRecord['context']['nest']['regex']); - } } diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index e13bb2ce..0c61cf22 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -338,7 +338,7 @@ class NormalizerFormatterTest extends TestCase 'message' => 'Foo', 'code' => 0, ]], - "..." => "Over 2 items (7 total), aborting normalization" + "..." => "Over 2 items (7 total), aborting normalization", ], $message ); @@ -372,9 +372,6 @@ class NormalizerFormatterTest extends TestCase } /** - * @param NormalizerFormatter $formatter - * @param \Throwable $exception - * * @return string */ private function formatRecordWithExceptionInContext(NormalizerFormatter $formatter, \Throwable $exception) @@ -393,7 +390,7 @@ class NormalizerFormatterTest extends TestCase { try { $arg = new TestInfoLeak; - call_user_func(array($this, 'throwHelper'), $arg, $dt = new \DateTime()); + call_user_func([$this, 'throwHelper'], $arg, $dt = new \DateTime()); } catch (\Exception $e) { } diff --git a/tests/Monolog/Formatter/ScalarFormatterTest.php b/tests/Monolog/Formatter/ScalarFormatterTest.php index 21f9d6cd..e75dd5d2 100644 --- a/tests/Monolog/Formatter/ScalarFormatterTest.php +++ b/tests/Monolog/Formatter/ScalarFormatterTest.php @@ -95,7 +95,7 @@ class ScalarFormatterTest extends TestCase 'code' => $exception->getCode(), 'file' => $exception->getFile() . ':' . $exception->getLine(), 'trace' => $this->buildTrace($exception), - ] + ], ]), $formatted['context']); } } diff --git a/tests/Monolog/Handler/ChromePHPHandlerTest.php b/tests/Monolog/Handler/ChromePHPHandlerTest.php index 5600cd28..722e0350 100644 --- a/tests/Monolog/Handler/ChromePHPHandlerTest.php +++ b/tests/Monolog/Handler/ChromePHPHandlerTest.php @@ -54,12 +54,12 @@ class ChromePHPHandlerTest extends TestCase public static function agentsProvider() { - return array( - array('Monolog Test; Chrome/1.0'), - array('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'), - array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/56.0.2924.76 Chrome/56.0.2924.76 Safari/537.36'), - array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36'), - ); + return [ + ['Monolog Test; Chrome/1.0'], + ['Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'], + ['Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/56.0.2924.76 Chrome/56.0.2924.76 Safari/537.36'], + ['Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36'], + ]; } public function testHeadersOverflow() diff --git a/tests/Monolog/Handler/DynamoDbHandlerTest.php b/tests/Monolog/Handler/DynamoDbHandlerTest.php index 2b237bfa..b206ef84 100644 --- a/tests/Monolog/Handler/DynamoDbHandlerTest.php +++ b/tests/Monolog/Handler/DynamoDbHandlerTest.php @@ -70,7 +70,7 @@ class DynamoDbHandlerTest extends TestCase $handler->setFormatter($formatter); if ($this->isV3) { - $expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2)); + $expFormatted = ['foo' => ['N' => 1], 'bar' => ['N' => 2]]; } else { $expFormatted = $formatted; } diff --git a/tests/Monolog/Handler/ElasticaHandlerTest.php b/tests/Monolog/Handler/ElasticaHandlerTest.php index 706e417f..8791c705 100644 --- a/tests/Monolog/Handler/ElasticaHandlerTest.php +++ b/tests/Monolog/Handler/ElasticaHandlerTest.php @@ -15,7 +15,6 @@ use Monolog\Formatter\ElasticaFormatter; use Monolog\Formatter\NormalizerFormatter; use Monolog\Test\TestCase; use Monolog\Level; -use Monolog\LogRecord; use Elastica\Client; use Elastica\Request; use Elastica\Response; diff --git a/tests/Monolog/Handler/FilterHandlerTest.php b/tests/Monolog/Handler/FilterHandlerTest.php index 4fa2eb79..799ee169 100644 --- a/tests/Monolog/Handler/FilterHandlerTest.php +++ b/tests/Monolog/Handler/FilterHandlerTest.php @@ -178,8 +178,8 @@ class FilterHandlerTest extends TestCase { $test = new TestHandler(); $handler = new FilterHandler($test); - $handler->handleBatch(array()); - $this->assertSame(array(), $test->getRecords()); + $handler->handleBatch([]); + $this->assertSame([], $test->getRecords()); } /** @@ -202,6 +202,6 @@ class FilterHandlerTest extends TestCase $this->assertFalse($test->hasInfoRecords()); $this->assertFalse($test->hasInfoRecords()); - $this->assertSame(array(), $test->getRecords()); + $this->assertSame([], $test->getRecords()); } } diff --git a/tests/Monolog/Handler/InsightOpsHandlerTest.php b/tests/Monolog/Handler/InsightOpsHandlerTest.php index 8663d777..d7e884e0 100644 --- a/tests/Monolog/Handler/InsightOpsHandlerTest.php +++ b/tests/Monolog/Handler/InsightOpsHandlerTest.php @@ -55,10 +55,10 @@ class InsightOpsHandlerTest extends TestCase private function createHandler() { $useSSL = extension_loaded('openssl'); - $args = array('testToken', 'us', $useSSL, Level::Debug, true); + $args = ['testToken', 'us', $useSSL, Level::Debug, true]; $this->resource = fopen('php://memory', 'a'); $this->handler = $this->getMockBuilder(InsightOpsHandler::class) - ->onlyMethods(array('fsockopen', 'streamSetTimeout', 'closeSocket')) + ->onlyMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setConstructorArgs($args) ->getMock(); diff --git a/tests/Monolog/Handler/PsrHandlerTest.php b/tests/Monolog/Handler/PsrHandlerTest.php index e06aa20e..919261e1 100644 --- a/tests/Monolog/Handler/PsrHandlerTest.php +++ b/tests/Monolog/Handler/PsrHandlerTest.php @@ -24,7 +24,7 @@ class PsrHandlerTest extends TestCase public function logLevelProvider() { return array_map( - fn(Level $level) => [$level->toLevelName(), $level], + fn (Level $level) => [$level->toLevelName(), $level], Level::cases() ); } diff --git a/tests/Monolog/Handler/RollbarHandlerTest.php b/tests/Monolog/Handler/RollbarHandlerTest.php index da267a87..2b252ef5 100644 --- a/tests/Monolog/Handler/RollbarHandlerTest.php +++ b/tests/Monolog/Handler/RollbarHandlerTest.php @@ -59,14 +59,14 @@ class RollbarHandlerTest extends TestCase private function setupRollbarLoggerMock() { - $config = array( + $config = [ 'access_token' => 'ad865e76e7fb496fab096ac07b1dbabb', 'environment' => 'test', - ); + ]; $this->rollbarLogger = $this->getMockBuilder(RollbarLogger::class) - ->setConstructorArgs(array($config)) - ->onlyMethods(array('log')) + ->setConstructorArgs([$config]) + ->onlyMethods(['log']) ->getMock(); $this->rollbarLogger diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index 5446f40e..8e131cd6 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -218,16 +218,16 @@ class RotatingFileHandlerTest extends TestCase public function rotationWhenSimilarFilesExistTests() { - return array( + return [ 'Rotation is triggered when the file of the current day is not present but similar exists' - => array(RotatingFileHandler::FILE_PER_DAY), + => [RotatingFileHandler::FILE_PER_DAY], 'Rotation is triggered when the file of the current month is not present but similar exists' - => array(RotatingFileHandler::FILE_PER_MONTH), + => [RotatingFileHandler::FILE_PER_MONTH], 'Rotation is triggered when the file of the current year is not present but similar exists' - => array(RotatingFileHandler::FILE_PER_YEAR), - ); + => [RotatingFileHandler::FILE_PER_YEAR], + ]; } public function testReuseCurrentFile() diff --git a/tests/Monolog/Handler/Slack/SlackRecordTest.php b/tests/Monolog/Handler/Slack/SlackRecordTest.php index e6c88fe0..eaa0ae5a 100644 --- a/tests/Monolog/Handler/Slack/SlackRecordTest.php +++ b/tests/Monolog/Handler/Slack/SlackRecordTest.php @@ -22,16 +22,16 @@ class SlackRecordTest extends TestCase { public function dataGetAttachmentColor() { - return array( - array(Level::Debug, SlackRecord::COLOR_DEFAULT), - array(Level::Info, SlackRecord::COLOR_GOOD), - array(Level::Notice, SlackRecord::COLOR_GOOD), - array(Level::Warning, SlackRecord::COLOR_WARNING), - array(Level::Error, SlackRecord::COLOR_DANGER), - array(Level::Critical, SlackRecord::COLOR_DANGER), - array(Level::Alert, SlackRecord::COLOR_DANGER), - array(Level::Emergency, SlackRecord::COLOR_DANGER), - ); + return [ + [Level::Debug, SlackRecord::COLOR_DEFAULT], + [Level::Info, SlackRecord::COLOR_GOOD], + [Level::Notice, SlackRecord::COLOR_GOOD], + [Level::Warning, SlackRecord::COLOR_WARNING], + [Level::Error, SlackRecord::COLOR_DANGER], + [Level::Critical, SlackRecord::COLOR_DANGER], + [Level::Alert, SlackRecord::COLOR_DANGER], + [Level::Emergency, SlackRecord::COLOR_DANGER], + ]; } /** @@ -70,16 +70,16 @@ class SlackRecordTest extends TestCase */ public function dataStringify() { - $multipleDimensions = array(array(1, 2)); - $numericKeys = array('library' => 'monolog'); - $singleDimension = array(1, 'Hello', 'Jordi'); + $multipleDimensions = [[1, 2]]; + $numericKeys = ['library' => 'monolog']; + $singleDimension = [1, 'Hello', 'Jordi']; - return array( - array(array(), '[]'), - array($multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)), - array($numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)), - array($singleDimension, json_encode($singleDimension)), - ); + return [ + [[], '[]'], + [$multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)], + [$numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)], + [$singleDimension, json_encode($singleDimension)], + ]; } /** @@ -179,7 +179,7 @@ class SlackRecordTest extends TestCase })); $message = 'Test message'; - $record = new SlackRecord(null, null, false, null, false, false, array(), $formatter); + $record = new SlackRecord(null, null, false, null, false, false, [], $formatter); $data = $record->getSlackData($this->getRecord(Level::Warning, $message)); $this->assertArrayHasKey('text', $data); @@ -232,21 +232,21 @@ class SlackRecordTest extends TestCase $level = Level::Error; $levelName = LevelName::fromLevel($level)->value; $record = new SlackRecord(null, null, true, null, true); - $data = $record->getSlackData($this->getRecord($level, 'test', array('test' => 1))); + $data = $record->getSlackData($this->getRecord($level, 'test', ['test' => 1])); $attachment = $data['attachments'][0]; $this->assertArrayHasKey('title', $attachment); $this->assertArrayHasKey('fields', $attachment); $this->assertSame($levelName, $attachment['title']); - $this->assertSame(array(), $attachment['fields']); + $this->assertSame([], $attachment['fields']); } public function testAddsShortAttachmentWithContextAndExtra() { $level = Level::Error; $levelName = LevelName::fromLevel($level)->value; - $context = array('test' => 1); - $extra = array('tags' => array('web')); + $context = ['test' => 1]; + $extra = ['tags' => ['web']]; $record = new SlackRecord(null, null, true, null, true, true); $loggerRecord = $this->getRecord($level, 'test', $context); $loggerRecord['extra'] = $extra; @@ -258,18 +258,18 @@ class SlackRecordTest extends TestCase $this->assertCount(2, $attachment['fields']); $this->assertSame($levelName, $attachment['title']); $this->assertSame( - array( - array( + [ + [ 'title' => 'Extra', 'value' => sprintf('```%s```', json_encode($extra, JSON_PRETTY_PRINT)), 'short' => false, - ), - array( + ], + [ 'title' => 'Context', 'value' => sprintf('```%s```', json_encode($context, JSON_PRETTY_PRINT)), 'short' => false, - ), - ), + ], + ], $attachment['fields'] ); } @@ -279,7 +279,7 @@ class SlackRecordTest extends TestCase $level = Level::Error; $levelName = LevelName::fromLevel($level)->value; $record = new SlackRecord(null, null, true, null); - $data = $record->getSlackData($this->getRecord($level, 'test', array('test' => 1))); + $data = $record->getSlackData($this->getRecord($level, 'test', ['test' => 1])); $attachment = $data['attachments'][0]; $this->assertArrayHasKey('title', $attachment); @@ -287,11 +287,11 @@ class SlackRecordTest extends TestCase $this->assertCount(1, $attachment['fields']); $this->assertSame('Message', $attachment['title']); $this->assertSame( - array(array( + [[ 'title' => 'Level', 'value' => $levelName, 'short' => false, - )), + ]], $attachment['fields'] ); } @@ -300,30 +300,30 @@ class SlackRecordTest extends TestCase { $level = Level::Error; $levelName = LevelName::fromLevel($level)->value; - $context = array('test' => 1); - $extra = array('tags' => array('web')); + $context = ['test' => 1]; + $extra = ['tags' => ['web']]; $record = new SlackRecord(null, null, true, null, false, true); $loggerRecord = $this->getRecord($level, 'test', $context); $loggerRecord['extra'] = $extra; $data = $record->getSlackData($loggerRecord); - $expectedFields = array( - array( + $expectedFields = [ + [ 'title' => 'Level', 'value' => $levelName, 'short' => false, - ), - array( + ], + [ 'title' => 'Tags', 'value' => sprintf('```%s```', json_encode($extra['tags'])), 'short' => false, - ), - array( + ], + [ 'title' => 'Test', 'value' => $context['test'], 'short' => false, - ), - ); + ], + ]; $attachment = $data['attachments'][0]; $this->assertArrayHasKey('title', $attachment); @@ -349,7 +349,7 @@ class SlackRecordTest extends TestCase public function testContextHasException() { - $record = $this->getRecord(Level::Critical, 'This is a critical message.', array('exception' => new \Exception())); + $record = $this->getRecord(Level::Critical, 'This is a critical message.', ['exception' => new \Exception()]); $slackRecord = new SlackRecord(null, null, true, null, false, true); $data = $slackRecord->getSlackData($record); $this->assertIsString($data['attachments'][0]['fields'][1]['value']); @@ -360,26 +360,26 @@ class SlackRecordTest extends TestCase $record = $this->getRecord( Level::Warning, 'test', - context: array('info' => array('library' => 'monolog', 'author' => 'Jordi')), - extra: array('tags' => array('web', 'cli')), + context: ['info' => ['library' => 'monolog', 'author' => 'Jordi']], + extra: ['tags' => ['web', 'cli']], ); - $slackRecord = new SlackRecord(null, null, true, null, false, true, array('context.info.library', 'extra.tags.1')); + $slackRecord = new SlackRecord(null, null, true, null, false, true, ['context.info.library', 'extra.tags.1']); $data = $slackRecord->getSlackData($record); $attachment = $data['attachments'][0]; - $expected = array( - array( + $expected = [ + [ 'title' => 'Info', - 'value' => sprintf('```%s```', json_encode(array('author' => 'Jordi'), JSON_PRETTY_PRINT)), + 'value' => sprintf('```%s```', json_encode(['author' => 'Jordi'], JSON_PRETTY_PRINT)), 'short' => false, - ), - array( + ], + [ 'title' => 'Tags', - 'value' => sprintf('```%s```', json_encode(array('web'))), + 'value' => sprintf('```%s```', json_encode(['web'])), 'short' => false, - ), - ); + ], + ]; foreach ($expected as $field) { $this->assertNotFalse(array_search($field, $attachment['fields'])); diff --git a/tests/Monolog/Handler/SlackHandlerTest.php b/tests/Monolog/Handler/SlackHandlerTest.php index 45b439dd..dd63a401 100644 --- a/tests/Monolog/Handler/SlackHandlerTest.php +++ b/tests/Monolog/Handler/SlackHandlerTest.php @@ -114,16 +114,16 @@ class SlackHandlerTest extends TestCase public function provideLevelColors() { - return array( - array(Level::Debug, urlencode(SlackRecord::COLOR_DEFAULT)), - array(Level::Info, SlackRecord::COLOR_GOOD), - array(Level::Notice, SlackRecord::COLOR_GOOD), - array(Level::Warning, SlackRecord::COLOR_WARNING), - array(Level::Error, SlackRecord::COLOR_DANGER), - array(Level::Critical, SlackRecord::COLOR_DANGER), - array(Level::Alert, SlackRecord::COLOR_DANGER), - array(Level::Emergency,SlackRecord::COLOR_DANGER), - ); + return [ + [Level::Debug, urlencode(SlackRecord::COLOR_DEFAULT)], + [Level::Info, SlackRecord::COLOR_GOOD], + [Level::Notice, SlackRecord::COLOR_GOOD], + [Level::Warning, SlackRecord::COLOR_WARNING], + [Level::Error, SlackRecord::COLOR_DANGER], + [Level::Critical, SlackRecord::COLOR_DANGER], + [Level::Alert, SlackRecord::COLOR_DANGER], + [Level::Emergency,SlackRecord::COLOR_DANGER], + ]; } private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $useAttachment = true, $iconEmoji = null, $useShortAttachment = false, $includeExtra = false) diff --git a/tests/Monolog/Handler/SlackWebhookHandlerTest.php b/tests/Monolog/Handler/SlackWebhookHandlerTest.php index 2dfb5444..31d23e54 100644 --- a/tests/Monolog/Handler/SlackWebhookHandlerTest.php +++ b/tests/Monolog/Handler/SlackWebhookHandlerTest.php @@ -36,27 +36,27 @@ class SlackWebhookHandlerTest extends TestCase $record = $this->getRecord(); $slackRecord = $handler->getSlackRecord(); $this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord); - $this->assertEquals(array( - 'attachments' => array( - array( + $this->assertEquals([ + 'attachments' => [ + [ 'fallback' => 'test', 'text' => 'test', 'color' => SlackRecord::COLOR_WARNING, - 'fields' => array( - array( + 'fields' => [ + [ 'title' => 'Level', 'value' => 'WARNING', 'short' => false, - ), - ), + ], + ], 'title' => 'Message', - 'mrkdwn_in' => array('fields'), + 'mrkdwn_in' => ['fields'], 'ts' => $record->datetime->getTimestamp(), 'footer' => null, 'footer_icon' => null, - ), - ), - ), $slackRecord->getSlackData($record)); + ], + ], + ], $slackRecord->getSlackData($record)); } /** @@ -79,12 +79,12 @@ class SlackWebhookHandlerTest extends TestCase $slackRecord = $handler->getSlackRecord(); $this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord); - $this->assertEquals(array( + $this->assertEquals([ 'username' => 'test-username', 'text' => 'test', 'channel' => 'test-channel', 'icon_emoji' => ':ghost:', - ), $slackRecord->getSlackData($this->getRecord())); + ], $slackRecord->getSlackData($this->getRecord())); } /** @@ -108,30 +108,30 @@ class SlackWebhookHandlerTest extends TestCase $record = $this->getRecord(); $slackRecord = $handler->getSlackRecord(); $this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord); - $this->assertEquals(array( + $this->assertEquals([ 'username' => 'test-username-with-attachment', 'channel' => 'test-channel-with-attachment', - 'attachments' => array( - array( + 'attachments' => [ + [ 'fallback' => 'test', 'text' => 'test', 'color' => SlackRecord::COLOR_WARNING, - 'fields' => array( - array( + 'fields' => [ + [ 'title' => 'Level', 'value' => LevelName::Warning->value, 'short' => false, - ), - ), - 'mrkdwn_in' => array('fields'), + ], + ], + 'mrkdwn_in' => ['fields'], 'ts' => $record['datetime']->getTimestamp(), 'footer' => 'test-username-with-attachment', 'footer_icon' => 'https://www.example.com/example.png', 'title' => 'Message', - ), - ), + ], + ], 'icon_url' => 'https://www.example.com/example.png', - ), $slackRecord->getSlackData($record)); + ], $slackRecord->getSlackData($record)); } /** diff --git a/tests/Monolog/Handler/SocketHandlerTest.php b/tests/Monolog/Handler/SocketHandlerTest.php index ddc7597a..192cfbe0 100644 --- a/tests/Monolog/Handler/SocketHandlerTest.php +++ b/tests/Monolog/Handler/SocketHandlerTest.php @@ -128,7 +128,7 @@ class SocketHandlerTest extends TestCase public function testExceptionIsThrownIfCannotSetChunkSize() { - $this->setMockHandler(array('streamSetChunkSize')); + $this->setMockHandler(['streamSetChunkSize']); $this->handler->setChunkSize(8192); $this->handler->expects($this->once()) ->method('streamSetChunkSize') diff --git a/tests/Monolog/Handler/StreamHandlerTest.php b/tests/Monolog/Handler/StreamHandlerTest.php index c0f4979f..a55981ea 100644 --- a/tests/Monolog/Handler/StreamHandlerTest.php +++ b/tests/Monolog/Handler/StreamHandlerTest.php @@ -11,7 +11,6 @@ namespace Monolog\Handler; -use Monolog\Handler\StreamHandler; use Monolog\Test\TestCase; use Monolog\Level; diff --git a/tests/Monolog/Handler/SyslogUdpHandlerTest.php b/tests/Monolog/Handler/SyslogUdpHandlerTest.php index 530a9d53..f27d5ad5 100644 --- a/tests/Monolog/Handler/SyslogUdpHandlerTest.php +++ b/tests/Monolog/Handler/SyslogUdpHandlerTest.php @@ -75,15 +75,15 @@ class SyslogUdpHandlerTest extends TestCase $host = gethostname(); $handler = $this->getMockBuilder('\Monolog\Handler\SyslogUdpHandler') - ->setConstructorArgs(array("127.0.0.1", 514, "authpriv", 'debug', true, "php", \Monolog\Handler\SyslogUdpHandler::RFC3164)) + ->setConstructorArgs(["127.0.0.1", 514, "authpriv", 'debug', true, "php", \Monolog\Handler\SyslogUdpHandler::RFC3164]) ->onlyMethods([]) ->getMock(); $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter()); $socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket') - ->setConstructorArgs(array('lol', 999)) - ->onlyMethods(array('write')) + ->setConstructorArgs(['lol', 999]) + ->onlyMethods(['write']) ->getMock(); $socket->expects($this->atLeast(2)) ->method('write') diff --git a/tests/Monolog/Handler/TelegramBotHandlerTest.php b/tests/Monolog/Handler/TelegramBotHandlerTest.php index 754af333..2a055bce 100644 --- a/tests/Monolog/Handler/TelegramBotHandlerTest.php +++ b/tests/Monolog/Handler/TelegramBotHandlerTest.php @@ -32,8 +32,6 @@ class TelegramBotHandlerTest extends TestCase } /** - * @param string $apiKey - * @param string $channel */ private function createHandler( string $apiKey = 'testKey', diff --git a/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php b/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php index 77bc932b..e28403ae 100644 --- a/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php +++ b/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php @@ -93,7 +93,7 @@ class WhatFailureGroupHandlerTest extends TestCase */ public function testHandleBatchUsesProcessors() { - $testHandlers = array(new TestHandler(), new TestHandler()); + $testHandlers = [new TestHandler(), new TestHandler()]; $handler = new WhatFailureGroupHandler($testHandlers); $handler->pushProcessor(function ($record) { $record->extra['foo'] = true; @@ -105,7 +105,7 @@ class WhatFailureGroupHandlerTest extends TestCase return $record; }); - $handler->handleBatch(array($this->getRecord(Level::Debug), $this->getRecord(Level::Info))); + $handler->handleBatch([$this->getRecord(Level::Debug), $this->getRecord(Level::Info)]); foreach ($testHandlers as $test) { $this->assertTrue($test->hasDebugRecords()); $this->assertTrue($test->hasInfoRecords()); diff --git a/tests/Monolog/Handler/ZendMonitorHandlerTest.php b/tests/Monolog/Handler/ZendMonitorHandlerTest.php index 217a6e55..446bedb5 100644 --- a/tests/Monolog/Handler/ZendMonitorHandlerTest.php +++ b/tests/Monolog/Handler/ZendMonitorHandlerTest.php @@ -12,7 +12,6 @@ namespace Monolog\Handler; use Monolog\Test\TestCase; -use Monolog\Level; class ZendMonitorHandlerTest extends TestCase { diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index 70b4a9ff..75fdb1f9 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -276,7 +276,7 @@ class LoggerTest extends TestCase public function testHandlersNotCalledBeforeFirstHandlingWhenProcessorsPresent() { $logger = new Logger(__METHOD__); - $logger->pushProcessor(fn($record) => $record); + $logger->pushProcessor(fn ($record) => $record); $handler1 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler1->expects($this->never()) @@ -348,7 +348,7 @@ class LoggerTest extends TestCase ; $logger = new Logger(__METHOD__, ['last' => $handler3, 'second' => $handler2, 'first' => $handler1]); - $logger->pushProcessor(fn($record) => $record); + $logger->pushProcessor(fn ($record) => $record); $logger->debug('test'); } @@ -652,7 +652,7 @@ class LoggerTest extends TestCase $testHandler = new Handler\TestHandler(); $testHandler->setSkipReset(true); $bufferHandler = new Handler\BufferHandler($testHandler); - $groupHandler = new Handler\GroupHandler(array($bufferHandler)); + $groupHandler = new Handler\GroupHandler([$bufferHandler]); $fingersCrossedHandler = new Handler\FingersCrossedHandler($groupHandler); $logger->pushHandler($fingersCrossedHandler); diff --git a/tests/Monolog/Processor/WebProcessorTest.php b/tests/Monolog/Processor/WebProcessorTest.php index 5a7ac299..59cc52e2 100644 --- a/tests/Monolog/Processor/WebProcessorTest.php +++ b/tests/Monolog/Processor/WebProcessorTest.php @@ -90,15 +90,15 @@ class WebProcessorTest extends TestCase public function testProcessorAddsOnlyRequestedExtraFieldsIncludingOptionalFields() { - $server = array( + $server = [ 'REQUEST_URI' => 'A', 'UNIQUE_ID' => 'X', - ); + ]; - $processor = new WebProcessor($server, array('url')); + $processor = new WebProcessor($server, ['url']); $record = $processor($this->getRecord()); - $this->assertSame(array('url' => 'A'), $record->extra); + $this->assertSame(['url' => 'A'], $record->extra); } public function testProcessorConfiguringOfExtraFields() diff --git a/tests/Monolog/PsrLogCompatTest.php b/tests/Monolog/PsrLogCompatTest.php index 529b7d29..c1b4a1e6 100644 --- a/tests/Monolog/PsrLogCompatTest.php +++ b/tests/Monolog/PsrLogCompatTest.php @@ -19,7 +19,6 @@ use PHPUnit\Framework\TestCase; use Psr\Log\InvalidArgumentException; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; -use Psr\Log\Test\LoggerInterfaceTest; class PsrLogCompatTest extends TestCase { @@ -61,28 +60,28 @@ class PsrLogCompatTest extends TestCase public function testLogsAtAllLevels($level, $message) { $logger = $this->getLogger(); - $logger->{$level}($message, array('user' => 'Bob')); - $logger->log($level, $message, array('user' => 'Bob')); + $logger->{$level}($message, ['user' => 'Bob']); + $logger->log($level, $message, ['user' => 'Bob']); - $expected = array( + $expected = [ "$level message of level $level with context: Bob", "$level message of level $level with context: Bob", - ); + ]; $this->assertEquals($expected, $this->getLogs()); } public function provideLevelsAndMessages() { - return array( - LogLevel::EMERGENCY => array(LogLevel::EMERGENCY, 'message of level emergency with context: {user}'), - LogLevel::ALERT => array(LogLevel::ALERT, 'message of level alert with context: {user}'), - LogLevel::CRITICAL => array(LogLevel::CRITICAL, 'message of level critical with context: {user}'), - LogLevel::ERROR => array(LogLevel::ERROR, 'message of level error with context: {user}'), - LogLevel::WARNING => array(LogLevel::WARNING, 'message of level warning with context: {user}'), - LogLevel::NOTICE => array(LogLevel::NOTICE, 'message of level notice with context: {user}'), - LogLevel::INFO => array(LogLevel::INFO, 'message of level info with context: {user}'), - LogLevel::DEBUG => array(LogLevel::DEBUG, 'message of level debug with context: {user}'), - ); + return [ + LogLevel::EMERGENCY => [LogLevel::EMERGENCY, 'message of level emergency with context: {user}'], + LogLevel::ALERT => [LogLevel::ALERT, 'message of level alert with context: {user}'], + LogLevel::CRITICAL => [LogLevel::CRITICAL, 'message of level critical with context: {user}'], + LogLevel::ERROR => [LogLevel::ERROR, 'message of level error with context: {user}'], + LogLevel::WARNING => [LogLevel::WARNING, 'message of level warning with context: {user}'], + LogLevel::NOTICE => [LogLevel::NOTICE, 'message of level notice with context: {user}'], + LogLevel::INFO => [LogLevel::INFO, 'message of level info with context: {user}'], + LogLevel::DEBUG => [LogLevel::DEBUG, 'message of level debug with context: {user}'], + ]; } public function testThrowsOnInvalidLevel() @@ -96,9 +95,9 @@ class PsrLogCompatTest extends TestCase public function testContextReplacement() { $logger = $this->getLogger(); - $logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar')); + $logger->info('{Message {nothing} {user} {foo.bar} a}', ['user' => 'Bob', 'foo.bar' => 'Bar']); - $expected = array('info {Message {nothing} Bob Bar a}'); + $expected = ['info {Message {nothing} Bob Bar a}']; $this->assertEquals($expected, $this->getLogs()); } @@ -111,7 +110,7 @@ class PsrLogCompatTest extends TestCase $this->getLogger()->warning($dummy); - $expected = array("warning $string"); + $expected = ["warning $string"]; $this->assertEquals($expected, $this->getLogs()); } @@ -120,47 +119,47 @@ class PsrLogCompatTest extends TestCase $closed = fopen('php://memory', 'r'); fclose($closed); - $context = array( + $context = [ 'bool' => true, 'null' => null, 'string' => 'Foo', 'int' => 0, 'float' => 0.5, - 'nested' => array('with object' => $this->createStringable()), + 'nested' => ['with object' => $this->createStringable()], 'object' => new \DateTime('now', new DateTimeZone('Europe/London')), 'resource' => fopen('php://memory', 'r'), 'closed' => $closed, - ); + ]; $this->getLogger()->warning('Crazy context data', $context); - $expected = array('warning Crazy context data'); + $expected = ['warning Crazy context data']; $this->assertEquals($expected, $this->getLogs()); } public function testContextExceptionKeyCanBeExceptionOrOtherValues() { $logger = $this->getLogger(); - $logger->warning('Random message', array('exception' => 'oops')); - $logger->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail'))); + $logger->warning('Random message', ['exception' => 'oops']); + $logger->critical('Uncaught Exception!', ['exception' => new \LogicException('Fail')]); - $expected = array( + $expected = [ 'warning Random message', - 'critical Uncaught Exception!' - ); + 'critical Uncaught Exception!', + ]; $this->assertEquals($expected, $this->getLogs()); } /** * Creates a mock of a `Stringable`. * - * @param string $string The string that must be represented by the stringable. + * @param string $string The string that must be represented by the stringable. * @return \PHPUnit_Framework_MockObject_MockObject A mock of an object that has a `__toString()` method. */ protected function createStringable($string = '') { $mock = $this->getMockBuilder('Stringable') - ->setMethods(array('__toString')) + ->setMethods(['__toString']) ->getMock(); $mock->method('__toString') diff --git a/tests/Monolog/SignalHandlerTest.php b/tests/Monolog/SignalHandlerTest.php index e73ad8fd..0c406bb8 100644 --- a/tests/Monolog/SignalHandlerTest.php +++ b/tests/Monolog/SignalHandlerTest.php @@ -28,13 +28,13 @@ class SignalHandlerTest extends TestCase protected function setUp(): void { - $this->signalHandlers = array(); + $this->signalHandlers = []; if (extension_loaded('pcntl')) { if (function_exists('pcntl_async_signals')) { $this->asyncSignalHandling = pcntl_async_signals(); } if (function_exists('pcntl_sigprocmask')) { - pcntl_sigprocmask(SIG_BLOCK, array(), $this->blockedSignals); + pcntl_sigprocmask(SIG_BLOCK, [], $this->blockedSignals); } } } @@ -67,10 +67,10 @@ class SignalHandlerTest extends TestCase public function testHandleSignal() { - $logger = new Logger('test', array($handler = new TestHandler)); + $logger = new Logger('test', [$handler = new TestHandler]); $errHandler = new SignalHandler($logger); $signo = 2; // SIGINT. - $siginfo = array('signo' => $signo, 'errno' => 0, 'code' => 0); + $siginfo = ['signo' => $signo, 'errno' => 0, 'code' => 0]; $errHandler->handleSignal($signo, $siginfo); $this->assertCount(1, $handler->getRecords()); $this->assertTrue($handler->hasCriticalRecords()); @@ -97,7 +97,7 @@ class SignalHandlerTest extends TestCase $this->setSignalHandler(SIGCONT, SIG_IGN); $this->setSignalHandler(SIGURG, SIG_IGN); - $logger = new Logger('test', array($handler = new TestHandler)); + $logger = new Logger('test', [$handler = new TestHandler]); $errHandler = new SignalHandler($logger); $pid = posix_getpid(); @@ -135,14 +135,14 @@ class SignalHandlerTest extends TestCase if ($pid === 0) { // Child. $streamHandler = new StreamHandler($path); $streamHandler->setFormatter($this->getIdentityFormatter()); - $logger = new Logger('test', array($streamHandler)); + $logger = new Logger('test', [$streamHandler]); $errHandler = new SignalHandler($logger); $errHandler->registerSignalHandler($signo, LogLevel::INFO, $callPrevious, false, false); - pcntl_sigprocmask(SIG_SETMASK, array(SIGCONT)); + pcntl_sigprocmask(SIG_SETMASK, [SIGCONT]); posix_kill(posix_getpid(), $signo); pcntl_signal_dispatch(); // If $callPrevious is true, SIGINT should terminate by this line. - pcntl_sigprocmask(SIG_BLOCK, array(), $oldset); + pcntl_sigprocmask(SIG_BLOCK, [], $oldset); file_put_contents($path, implode(' ', $oldset), FILE_APPEND); posix_kill(posix_getpid(), $signo); pcntl_signal_dispatch(); @@ -158,15 +158,15 @@ class SignalHandlerTest extends TestCase public function defaultPreviousProvider() { if (!defined('SIGCONT') || !defined('SIGINT') || !defined('SIGURG')) { - return array(); + return []; } - return array( - array(SIGINT, false, 'Program received signal SIGINT'.SIGCONT.'Program received signal SIGINT'), - array(SIGINT, true, 'Program received signal SIGINT'), - array(SIGURG, false, 'Program received signal SIGURG'.SIGCONT.'Program received signal SIGURG'), - array(SIGURG, true, 'Program received signal SIGURG'.SIGCONT.'Program received signal SIGURG'), - ); + return [ + [SIGINT, false, 'Program received signal SIGINT'.SIGCONT.'Program received signal SIGINT'], + [SIGINT, true, 'Program received signal SIGINT'], + [SIGURG, false, 'Program received signal SIGURG'.SIGCONT.'Program received signal SIGURG'], + [SIGURG, true, 'Program received signal SIGURG'.SIGCONT.'Program received signal SIGURG'], + ]; } /** @@ -178,7 +178,7 @@ class SignalHandlerTest extends TestCase { $this->setSignalHandler(SIGURG, SIG_IGN); - $logger = new Logger('test', array($handler = new TestHandler)); + $logger = new Logger('test', [$handler = new TestHandler]); $errHandler = new SignalHandler($logger); $previousCalled = 0; pcntl_signal(SIGURG, function ($signo, array $siginfo = null) use (&$previousCalled) { @@ -194,10 +194,10 @@ class SignalHandlerTest extends TestCase public function callablePreviousProvider() { - return array( - array(false), - array(true), - ); + return [ + [false], + [true], + ]; } /** @@ -222,7 +222,7 @@ class SignalHandlerTest extends TestCase } $this->assertNotSame(-1, $pid); - $logger = new Logger('test', array($handler = new TestHandler)); + $logger = new Logger('test', [$handler = new TestHandler]); $errHandler = new SignalHandler($logger); $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO, false, $restartSyscalls, false); if ($restartSyscalls) { @@ -246,12 +246,12 @@ class SignalHandlerTest extends TestCase public function restartSyscallsProvider() { - return array( - array(false), - array(true), - array(false), - array(true), - ); + return [ + [false], + [true], + [false], + [true], + ]; } /** @@ -264,7 +264,7 @@ class SignalHandlerTest extends TestCase $this->setSignalHandler(SIGURG, SIG_IGN); pcntl_async_signals($initialAsync); - $logger = new Logger('test', array($handler = new TestHandler)); + $logger = new Logger('test', [$handler = new TestHandler]); $errHandler = new SignalHandler($logger); $errHandler->registerSignalHandler(SIGURG, LogLevel::INFO, false, false, $desiredAsync); $this->assertTrue(posix_kill(posix_getpid(), SIGURG)); @@ -275,13 +275,13 @@ class SignalHandlerTest extends TestCase public function asyncProvider() { - return array( - array(false, false, 0, 1), - array(false, null, 0, 1), - array(false, true, 1, 1), - array(true, false, 0, 1), - array(true, null, 1, 1), - array(true, true, 1, 1), - ); + return [ + [false, false, 0, 1], + [false, null, 0, 1], + [false, true, 1, 1], + [true, false, 0, 1], + [true, null, 1, 1], + [true, true, 1, 1], + ]; } } diff --git a/tests/Monolog/UtilsTest.php b/tests/Monolog/UtilsTest.php index aced3baf..08d127b1 100644 --- a/tests/Monolog/UtilsTest.php +++ b/tests/Monolog/UtilsTest.php @@ -27,8 +27,10 @@ class UtilsTest extends \PHPUnit_Framework_TestCase { return [ ['stdClass', new \stdClass()], - ['class@anonymous', new class {}], - ['stdClass@anonymous', new class extends \stdClass {}], + ['class@anonymous', new class { + }], + ['stdClass@anonymous', new class extends \stdClass { + }], ]; } @@ -44,15 +46,15 @@ class UtilsTest extends \PHPUnit_Framework_TestCase public function providePathsToCanonicalize() { - return array( - array('/foo/bar', '/foo/bar'), - array('file://'.getcwd().'/bla', 'file://bla'), - array(getcwd().'/bla', 'bla'), - array(getcwd().'/./bla', './bla'), - array('file:///foo/bar', 'file:///foo/bar'), - array('any://foo', 'any://foo'), - array('\\\\network\path', '\\\\network\path'), - ); + return [ + ['/foo/bar', '/foo/bar'], + ['file://'.getcwd().'/bla', 'file://bla'], + [getcwd().'/bla', 'bla'], + [getcwd().'/./bla', './bla'], + ['file:///foo/bar', 'file:///foo/bar'], + ['any://foo', 'any://foo'], + ['\\\\network\path', '\\\\network\path'], + ]; } /** @@ -112,13 +114,14 @@ class UtilsTest extends \PHPUnit_Framework_TestCase /** * @dataProvider providesPcreLastErrorMessage - * @param int $code + * @param int $code * @param string $msg */ public function testPcreLastErrorMessage($code, $msg) { if (PHP_VERSION_ID >= 80000) { $this->assertSame('No error', Utils::pcreLastErrorMessage($code)); + return; } @@ -178,7 +181,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase /** * @dataProvider provideIniValuesToConvertToBytes - * @param mixed $input + * @param mixed $input * @param int|false $expected */ public function testExpandIniShorthandBytes($input, $expected)