From 3ba77d1d391e1bba7a77afc600cda5e0e9b77b4e Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Fri, 28 Jun 2024 10:45:25 +0200 Subject: [PATCH] Use fully-qualified name for native functions (#1887) --- .php-cs-fixer.php | 1 + src/Monolog/ErrorHandler.php | 8 +++---- src/Monolog/Formatter/ChromePHPFormatter.php | 2 +- src/Monolog/Formatter/FlowdockFormatter.php | 4 ++-- src/Monolog/Formatter/FluentdFormatter.php | 2 +- .../Formatter/GelfMessageFormatter.php | 10 ++++----- src/Monolog/Formatter/HtmlFormatter.php | 2 +- src/Monolog/Formatter/JsonFormatter.php | 8 +++---- src/Monolog/Formatter/LineFormatter.php | 8 +++---- src/Monolog/Formatter/MongoDBFormatter.php | 6 ++--- src/Monolog/Formatter/NormalizerFormatter.php | 20 ++++++++--------- src/Monolog/Formatter/ScalarFormatter.php | 2 +- src/Monolog/Formatter/WildfireFormatter.php | 12 +++++----- src/Monolog/Handler/AbstractSyslogHandler.php | 6 ++--- src/Monolog/Handler/BrowserConsoleHandler.php | 8 +++---- src/Monolog/Handler/BufferHandler.php | 4 ++-- src/Monolog/Handler/ChromePHPHandler.php | 6 ++--- src/Monolog/Handler/CubeHandler.php | 10 ++++----- src/Monolog/Handler/Curl/Util.php | 2 +- src/Monolog/Handler/DeduplicationHandler.php | 8 +++---- src/Monolog/Handler/ErrorLogHandler.php | 2 +- src/Monolog/Handler/FilterHandler.php | 10 ++++----- src/Monolog/Handler/FingersCrossedHandler.php | 8 +++---- src/Monolog/Handler/FleepHookHandler.php | 4 ++-- src/Monolog/Handler/FlowdockHandler.php | 4 ++-- src/Monolog/Handler/IFTTTHandler.php | 2 +- src/Monolog/Handler/InsightOpsHandler.php | 2 +- src/Monolog/Handler/LogEntriesHandler.php | 2 +- src/Monolog/Handler/LogglyHandler.php | 8 +++---- src/Monolog/Handler/LogmaticHandler.php | 2 +- src/Monolog/Handler/NewRelicHandler.php | 12 +++++----- src/Monolog/Handler/OverflowHandler.php | 4 ++-- src/Monolog/Handler/ProcessHandler.php | 6 ++--- src/Monolog/Handler/PushoverHandler.php | 6 ++--- src/Monolog/Handler/RedisHandler.php | 2 +- src/Monolog/Handler/RotatingFileHandler.php | 4 ++-- src/Monolog/Handler/SamplingHandler.php | 4 ++-- src/Monolog/Handler/SendGridHandler.php | 2 +- src/Monolog/Handler/Slack/SlackRecord.php | 2 +- src/Monolog/Handler/SlackHandler.php | 8 +++---- src/Monolog/Handler/SlackWebhookHandler.php | 2 +- src/Monolog/Handler/SocketHandler.php | 20 ++++++++--------- src/Monolog/Handler/SqsHandler.php | 4 ++-- src/Monolog/Handler/StreamHandler.php | 16 +++++++------- src/Monolog/Handler/SymfonyMailerHandler.php | 2 +- src/Monolog/Handler/SyslogUdp/UdpSocket.php | 4 ++-- src/Monolog/Handler/SyslogUdpHandler.php | 4 ++-- src/Monolog/Handler/TelegramBotHandler.php | 10 ++++----- src/Monolog/Handler/TestHandler.php | 10 ++++----- src/Monolog/Handler/ZendMonitorHandler.php | 2 +- src/Monolog/LogRecord.php | 2 +- src/Monolog/Logger.php | 12 +++++----- src/Monolog/Processor/GitProcessor.php | 2 +- .../Processor/IntrospectionProcessor.php | 4 ++-- .../Processor/LoadAverageProcessor.php | 4 ++-- src/Monolog/Processor/MercurialProcessor.php | 2 +- .../Processor/PsrLogMessageProcessor.php | 8 +++---- src/Monolog/Processor/UidProcessor.php | 2 +- src/Monolog/Processor/WebProcessor.php | 2 +- src/Monolog/SignalHandler.php | 12 +++++----- src/Monolog/Utils.php | 22 +++++++++---------- tests/Monolog/ErrorHandlerTest.php | 6 ++--- .../Formatter/GelfMessageFormatterTest.php | 8 +++---- tests/Monolog/Formatter/JsonFormatterTest.php | 2 +- tests/Monolog/Formatter/LineFormatterTest.php | 2 +- .../Formatter/NormalizerFormatterTest.php | 6 ++--- .../Monolog/Formatter/ScalarFormatterTest.php | 4 ++-- .../Handler/AbstractProcessingHandlerTest.php | 2 +- tests/Monolog/Handler/DynamoDbHandlerTest.php | 2 +- tests/Monolog/Handler/ErrorLogHandlerTest.php | 2 +- .../Monolog/Handler/FleepHookHandlerTest.php | 2 +- tests/Monolog/Handler/FlowdockHandlerTest.php | 2 +- .../Monolog/Handler/InsightOpsHandlerTest.php | 2 +- .../Monolog/Handler/LogEntriesHandlerTest.php | 2 +- tests/Monolog/Handler/LogmaticHandlerTest.php | 2 +- .../Handler/NativeMailerHandlerTest.php | 2 +- .../Monolog/Handler/PHPConsoleHandlerTest.php | 4 ++-- tests/Monolog/Handler/ProcessHandlerTest.php | 4 ++-- .../Handler/RotatingFileHandlerTest.php | 4 ++-- tests/Monolog/Handler/SamplingHandlerTest.php | 2 +- tests/Monolog/Handler/SlackHandlerTest.php | 2 +- tests/Monolog/Handler/SocketHandlerTest.php | 16 +++++++------- tests/Monolog/Handler/StreamHandlerTest.php | 16 +++++++------- .../Handler/SymfonyMailerHandlerTest.php | 2 +- .../Handler/ZendMonitorHandlerTest.php | 2 +- tests/Monolog/LoggerTest.php | 2 +- tests/Monolog/Processor/GitProcessorTest.php | 2 +- .../Processor/MercurialProcessorTest.php | 6 ++--- tests/Monolog/Processor/UidProcessorTest.php | 2 +- tests/Monolog/SignalHandlerTest.php | 12 +++++----- 90 files changed, 246 insertions(+), 245 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 839368490..d96f93029 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -30,6 +30,7 @@ 'header_comment' => ['header' => $header], 'include' => true, 'class_attributes_separation' => array('elements' => array('method' => 'one', 'trait_import' => 'none')), + 'native_function_invocation' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_statement' => true, diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index 08d414b34..d2ef247ea 100644 --- a/src/Monolog/ErrorHandler.php +++ b/src/Monolog/ErrorHandler.php @@ -194,7 +194,7 @@ private function handleException(\Throwable $e): never ($this->previousExceptionHandler)($e); } - if (!headers_sent() && in_array(strtolower((string) ini_get('display_errors')), ['0', '', 'false', 'off', 'none', 'no'], true)) { + if (!headers_sent() && \in_array(strtolower((string) \ini_get('display_errors')), ['0', '', 'false', 'off', 'none', 'no'], true)) { http_response_code(500); } @@ -208,7 +208,7 @@ private function handleError(int $code, string $message, string $file = '', int } // fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries - if (!$this->hasFatalErrorHandler || !in_array($code, self::FATAL_ERRORS, true)) { + if (!$this->hasFatalErrorHandler || !\in_array($code, self::FATAL_ERRORS, true)) { $level = $this->errorLevelMap[$code] ?? LogLevel::CRITICAL; $this->logger->log($level, self::codeToString($code).': '.$message, ['code' => $code, 'message' => $message, 'file' => $file, 'line' => $line]); } else { @@ -234,12 +234,12 @@ public function handleFatalError(): void { $this->reservedMemory = ''; - if (is_array($this->lastFatalData)) { + if (\is_array($this->lastFatalData)) { $lastError = $this->lastFatalData; } else { $lastError = error_get_last(); } - if (is_array($lastError) && in_array($lastError['type'], self::FATAL_ERRORS, true)) { + if (\is_array($lastError) && \in_array($lastError['type'], self::FATAL_ERRORS, true)) { $trace = $lastError['trace'] ?? null; $this->logger->log( $this->fatalLevel, diff --git a/src/Monolog/Formatter/ChromePHPFormatter.php b/src/Monolog/Formatter/ChromePHPFormatter.php index 3f1d45829..beb5106af 100644 --- a/src/Monolog/Formatter/ChromePHPFormatter.php +++ b/src/Monolog/Formatter/ChromePHPFormatter.php @@ -59,7 +59,7 @@ public function format(LogRecord $record) if (\count($record->extra) > 0) { $message['extra'] = $record->extra; } - if (count($message) === 1) { + if (\count($message) === 1) { $message = reset($message); } diff --git a/src/Monolog/Formatter/FlowdockFormatter.php b/src/Monolog/Formatter/FlowdockFormatter.php index c64da7c06..cc805c892 100644 --- a/src/Monolog/Formatter/FlowdockFormatter.php +++ b/src/Monolog/Formatter/FlowdockFormatter.php @@ -86,7 +86,7 @@ public function getShortMessage(string $message): string static $hasMbString; if (null === $hasMbString) { - $hasMbString = function_exists('mb_strlen'); + $hasMbString = \function_exists('mb_strlen'); } $maxLength = 45; @@ -96,7 +96,7 @@ public function getShortMessage(string $message): string $message = mb_substr($message, 0, $maxLength - 4, 'UTF-8') . ' ...'; } } else { - if (strlen($message) > $maxLength) { + if (\strlen($message) > $maxLength) { $message = substr($message, 0, $maxLength - 4) . ' ...'; } } diff --git a/src/Monolog/Formatter/FluentdFormatter.php b/src/Monolog/Formatter/FluentdFormatter.php index 04495a614..0c9f3e162 100644 --- a/src/Monolog/Formatter/FluentdFormatter.php +++ b/src/Monolog/Formatter/FluentdFormatter.php @@ -47,7 +47,7 @@ class FluentdFormatter implements FormatterInterface */ public function __construct(bool $levelTag = false) { - if (!function_exists('json_encode')) { + if (!\function_exists('json_encode')) { throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s FluentdUnixFormatter'); } diff --git a/src/Monolog/Formatter/GelfMessageFormatter.php b/src/Monolog/Formatter/GelfMessageFormatter.php index 96cb60ffe..dd6fefbcb 100644 --- a/src/Monolog/Formatter/GelfMessageFormatter.php +++ b/src/Monolog/Formatter/GelfMessageFormatter.php @@ -104,7 +104,7 @@ public function format(LogRecord $record): Message ->setLevel($this->getGraylog2Priority($record->level)); // message length + system name length + 200 for padding / metadata - $len = 200 + strlen($record->message) + strlen($this->systemName); + $len = 200 + \strlen($record->message) + \strlen($this->systemName); if ($len > $this->maxLength) { $message->setShortMessage(Utils::substr($record->message, 0, $this->maxLength)); @@ -115,8 +115,8 @@ public function format(LogRecord $record): Message } foreach ($extra as $key => $val) { - $val = is_scalar($val) || null === $val ? $val : $this->toJson($val); - $len = strlen($this->extraPrefix . $key . $val); + $val = \is_scalar($val) || null === $val ? $val : $this->toJson($val); + $len = \strlen($this->extraPrefix . $key . $val); if ($len > $this->maxLength) { $message->setAdditional($this->extraPrefix . $key, Utils::substr((string) $val, 0, $this->maxLength)); @@ -126,8 +126,8 @@ public function format(LogRecord $record): Message } foreach ($context as $key => $val) { - $val = is_scalar($val) || null === $val ? $val : $this->toJson($val); - $len = strlen($this->contextPrefix . $key . $val); + $val = \is_scalar($val) || null === $val ? $val : $this->toJson($val); + $len = \strlen($this->contextPrefix . $key . $val); if ($len > $this->maxLength) { $message->setAdditional($this->contextPrefix . $key, Utils::substr((string) $val, 0, $this->maxLength)); diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index c316b65ee..a2314ab55 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -132,7 +132,7 @@ public function formatBatch(array $records): string */ protected function convertToString($data): string { - if (null === $data || is_scalar($data)) { + if (null === $data || \is_scalar($data)) { return (string) $data; } diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index c1cf48dcd..640043a7e 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -154,13 +154,13 @@ protected function normalize(mixed $data, int $depth = 0): mixed return 'Over '.$this->maxNormalizeDepth.' levels deep, aborting normalization'; } - if (is_array($data)) { + if (\is_array($data)) { $normalized = []; $count = 1; foreach ($data as $key => $value) { if ($count++ > $this->maxNormalizeItemCount) { - $normalized['...'] = 'Over '.$this->maxNormalizeItemCount.' items ('.count($data).' total), aborting normalization'; + $normalized['...'] = 'Over '.$this->maxNormalizeItemCount.' items ('.\count($data).' total), aborting normalization'; break; } @@ -170,7 +170,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed return $normalized; } - if (is_object($data)) { + if (\is_object($data)) { if ($data instanceof \DateTimeInterface) { return $this->formatDate($data); } @@ -195,7 +195,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed return $data; } - if (is_resource($data)) { + if (\is_resource($data)) { return parent::normalize($data); } diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 7d35960cc..3ff840b7c 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -226,11 +226,11 @@ protected function normalizeException(\Throwable $e, int $depth = 0): string */ protected function convertToString($data): string { - if (null === $data || is_bool($data)) { + if (null === $data || \is_bool($data)) { return var_export($data, true); } - if (is_scalar($data)) { + if (\is_scalar($data)) { return (string) $data; } @@ -267,9 +267,9 @@ private function formatException(\Throwable $e): string } if (isset($e->detail)) { - if (is_string($e->detail)) { + if (\is_string($e->detail)) { $str .= ' detail: ' . $e->detail; - } elseif (is_object($e->detail) || is_array($e->detail)) { + } elseif (\is_object($e->detail) || \is_array($e->detail)) { $str .= ' detail: ' . $this->toJson($e->detail, true); } } diff --git a/src/Monolog/Formatter/MongoDBFormatter.php b/src/Monolog/Formatter/MongoDBFormatter.php index 9b7da8a9c..2da3e0bec 100644 --- a/src/Monolog/Formatter/MongoDBFormatter.php +++ b/src/Monolog/Formatter/MongoDBFormatter.php @@ -36,7 +36,7 @@ public function __construct(int $maxNestingLevel = 3, bool $exceptionTraceAsStri $this->maxNestingLevel = max($maxNestingLevel, 0); $this->exceptionTraceAsString = $exceptionTraceAsString; - $this->isLegacyMongoExt = extension_loaded('mongodb') && version_compare((string) phpversion('mongodb'), '1.1.9', '<='); + $this->isLegacyMongoExt = \extension_loaded('mongodb') && version_compare((string) phpversion('mongodb'), '1.1.9', '<='); } /** @@ -82,9 +82,9 @@ protected function formatArray(array $array, int $nestingLevel = 0) $array[$name] = $this->formatDate($value, $nestingLevel + 1); } elseif ($value instanceof \Throwable) { $array[$name] = $this->formatException($value, $nestingLevel + 1); - } elseif (is_array($value)) { + } elseif (\is_array($value)) { $array[$name] = $this->formatArray($value, $nestingLevel + 1); - } elseif (is_object($value) && !$value instanceof Type) { + } elseif (\is_object($value) && !$value instanceof Type) { $array[$name] = $this->formatObject($value, $nestingLevel + 1); } } diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index 358b39383..0304b9f75 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -40,7 +40,7 @@ class NormalizerFormatter implements FormatterInterface public function __construct(?string $dateFormat = null) { $this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat; - if (!function_exists('json_encode')) { + if (!\function_exists('json_encode')) { throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s NormalizerFormatter'); } } @@ -182,8 +182,8 @@ protected function normalize(mixed $data, int $depth = 0): mixed return 'Over ' . $this->maxNormalizeDepth . ' levels deep, aborting normalization'; } - if (null === $data || is_scalar($data)) { - if (is_float($data)) { + if (null === $data || \is_scalar($data)) { + if (\is_float($data)) { if (is_infinite($data)) { return ($data > 0 ? '' : '-') . 'INF'; } @@ -195,13 +195,13 @@ protected function normalize(mixed $data, int $depth = 0): mixed return $data; } - if (is_array($data)) { + if (\is_array($data)) { $normalized = []; $count = 1; foreach ($data as $key => $value) { if ($count++ > $this->maxNormalizeItemCount) { - $normalized['...'] = 'Over ' . $this->maxNormalizeItemCount . ' items ('.count($data).' total), aborting normalization'; + $normalized['...'] = 'Over ' . $this->maxNormalizeItemCount . ' items ('.\count($data).' total), aborting normalization'; break; } @@ -215,7 +215,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed return $this->formatDate($data); } - if (is_object($data)) { + if (\is_object($data)) { if ($data instanceof Throwable) { return $this->normalizeException($data, $depth); } @@ -244,11 +244,11 @@ protected function normalize(mixed $data, int $depth = 0): mixed return [Utils::getClass($data) => $value]; } - if (is_resource($data)) { + if (\is_resource($data)) { return sprintf('[resource(%s)]', get_resource_type($data)); } - return '[unknown('.gettype($data).')]'; + return '[unknown('.\gettype($data).')]'; } /** @@ -286,9 +286,9 @@ protected function normalizeException(Throwable $e, int $depth = 0) } if (isset($e->detail)) { - if (is_string($e->detail)) { + if (\is_string($e->detail)) { $data['detail'] = $e->detail; - } elseif (is_object($e->detail) || is_array($e->detail)) { + } elseif (\is_object($e->detail) || \is_array($e->detail)) { $data['detail'] = $this->toJson($e->detail, true); } } diff --git a/src/Monolog/Formatter/ScalarFormatter.php b/src/Monolog/Formatter/ScalarFormatter.php index 4bc20a08c..ec73a0ec4 100644 --- a/src/Monolog/Formatter/ScalarFormatter.php +++ b/src/Monolog/Formatter/ScalarFormatter.php @@ -40,7 +40,7 @@ protected function toScalar(mixed $value): string|int|float|bool|null { $normalized = $this->normalize($value); - if (is_array($normalized)) { + if (\is_array($normalized)) { return $this->toJson($normalized, true); } diff --git a/src/Monolog/Formatter/WildfireFormatter.php b/src/Monolog/Formatter/WildfireFormatter.php index 2e28b3ab4..28a1deecf 100644 --- a/src/Monolog/Formatter/WildfireFormatter.php +++ b/src/Monolog/Formatter/WildfireFormatter.php @@ -73,19 +73,19 @@ public function format(LogRecord $record): string $message = ['message' => $record->message]; $handleError = false; - if (count($record->context) > 0) { + if (\count($record->context) > 0) { $message['context'] = $this->normalize($record->context); $handleError = true; } - if (count($record->extra) > 0) { + if (\count($record->extra) > 0) { $message['extra'] = $this->normalize($record->extra); $handleError = true; } - if (count($message) === 1) { + if (\count($message) === 1) { $message = reset($message); } - if (is_array($message) && isset($message['context']['table'])) { + if (\is_array($message) && isset($message['context']['table'])) { $type = 'TABLE'; $label = $record->channel .': '. $record->message; $message = $message['context']['table']; @@ -108,7 +108,7 @@ public function format(LogRecord $record): string // The message itself is a serialization of the above JSON object + it's length return sprintf( '%d|%s|', - strlen($json), + \strlen($json), $json ); } @@ -130,7 +130,7 @@ public function formatBatch(array $records) */ protected function normalize(mixed $data, int $depth = 0): mixed { - if (is_object($data) && !$data instanceof \DateTimeInterface) { + if (\is_object($data) && !$data instanceof \DateTimeInterface) { return $data; } diff --git a/src/Monolog/Handler/AbstractSyslogHandler.php b/src/Monolog/Handler/AbstractSyslogHandler.php index 695a1c07f..4a7031706 100644 --- a/src/Monolog/Handler/AbstractSyslogHandler.php +++ b/src/Monolog/Handler/AbstractSyslogHandler.php @@ -55,7 +55,7 @@ public function __construct(string|int $facility = \LOG_USER, int|string|Level $ { parent::__construct($level, $bubble); - if (!defined('PHP_WINDOWS_VERSION_BUILD')) { + if (!\defined('PHP_WINDOWS_VERSION_BUILD')) { $this->facilities['local0'] = \LOG_LOCAL0; $this->facilities['local1'] = \LOG_LOCAL1; $this->facilities['local2'] = \LOG_LOCAL2; @@ -76,9 +76,9 @@ public function __construct(string|int $facility = \LOG_USER, int|string|Level $ } // convert textual description of facility to syslog constant - if (is_string($facility) && array_key_exists(strtolower($facility), $this->facilities)) { + if (\is_string($facility) && \array_key_exists(strtolower($facility), $this->facilities)) { $facility = $this->facilities[strtolower($facility)]; - } elseif (!in_array($facility, array_values($this->facilities), true)) { + } elseif (!\in_array($facility, array_values($this->facilities), true)) { throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given'); } diff --git a/src/Monolog/Handler/BrowserConsoleHandler.php b/src/Monolog/Handler/BrowserConsoleHandler.php index 5930ca488..cbd158eaa 100644 --- a/src/Monolog/Handler/BrowserConsoleHandler.php +++ b/src/Monolog/Handler/BrowserConsoleHandler.php @@ -77,7 +77,7 @@ public static function send(): void return; } - if (count(static::$records) > 0) { + if (\count(static::$records) > 0) { if ($format === self::FORMAT_HTML) { static::writeOutput(''); } else { // js format @@ -213,7 +213,7 @@ private static function handleStyles(string $formatted): array $args[] = self::quote(self::handleCustomStyles($match[2][0], $match[1][0])); $pos = $match[0][1]; - $format = Utils::substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . Utils::substr($format, $pos + strlen($match[0][0])); + $format = Utils::substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . Utils::substr($format, $pos + \strlen($match[0][0])); } $args[] = self::quote('font-weight: normal'); @@ -231,7 +231,7 @@ private static function handleCustomStyles(string $style, string $string): strin if (trim($m[1]) === 'autolabel') { // Format the string as a label with consistent auto assigned background color if (!isset($labels[$string])) { - $labels[$string] = $colors[count($labels) % count($colors)]; + $labels[$string] = $colors[\count($labels) % \count($colors)]; } $color = $labels[$string]; @@ -284,7 +284,7 @@ private static function quote(string $arg): string private static function call(...$args): string { $method = array_shift($args); - if (!is_string($method)) { + if (!\is_string($method)) { throw new \UnexpectedValueException('Expected the first arg to be a string, got: '.var_export($method, true)); } diff --git a/src/Monolog/Handler/BufferHandler.php b/src/Monolog/Handler/BufferHandler.php index ff89faa8a..c241c32f2 100644 --- a/src/Monolog/Handler/BufferHandler.php +++ b/src/Monolog/Handler/BufferHandler.php @@ -148,7 +148,7 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface return $this; } - throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.'); } /** @@ -160,6 +160,6 @@ public function getFormatter(): FormatterInterface return $this->handler->getFormatter(); } - throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.'); } } diff --git a/src/Monolog/Handler/ChromePHPHandler.php b/src/Monolog/Handler/ChromePHPHandler.php index 2f7f21d5f..8b1cd5a3e 100644 --- a/src/Monolog/Handler/ChromePHPHandler.php +++ b/src/Monolog/Handler/ChromePHPHandler.php @@ -68,7 +68,7 @@ class ChromePHPHandler extends AbstractProcessingHandler public function __construct(int|string|Level $level = Level::Debug, bool $bubble = true) { parent::__construct($level, $bubble); - if (!function_exists('json_encode')) { + if (!\function_exists('json_encode')) { throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s ChromePHPHandler'); } } @@ -149,7 +149,7 @@ protected function send(): void $json = Utils::jsonEncode(self::$json, Utils::DEFAULT_JSON_FLAGS & ~JSON_UNESCAPED_UNICODE, true); $data = base64_encode($json); - if (strlen($data) > 3 * 1024) { + if (\strlen($data) > 3 * 1024) { self::$overflowed = true; $record = new LogRecord( @@ -158,7 +158,7 @@ protected function send(): void channel: 'monolog', datetime: new DateTimeImmutable(true), ); - self::$json['rows'][count(self::$json['rows']) - 1] = $this->getFormatter()->format($record); + self::$json['rows'][\count(self::$json['rows']) - 1] = $this->getFormatter()->format($record); $json = Utils::jsonEncode(self::$json, Utils::DEFAULT_JSON_FLAGS & ~JSON_UNESCAPED_UNICODE, true); $data = base64_encode($json); } diff --git a/src/Monolog/Handler/CubeHandler.php b/src/Monolog/Handler/CubeHandler.php index 8388f5ade..a76bf4089 100644 --- a/src/Monolog/Handler/CubeHandler.php +++ b/src/Monolog/Handler/CubeHandler.php @@ -47,7 +47,7 @@ public function __construct(string $url, int|string|Level $level = Level::Debug, throw new \UnexpectedValueException('URL "'.$url.'" is not valid'); } - if (!in_array($urlInfo['scheme'], $this->acceptedSchemes, true)) { + if (!\in_array($urlInfo['scheme'], $this->acceptedSchemes, true)) { throw new \UnexpectedValueException( 'Invalid protocol (' . $urlInfo['scheme'] . ').' . ' Valid options are ' . implode(', ', $this->acceptedSchemes) @@ -69,7 +69,7 @@ public function __construct(string $url, int|string|Level $level = Level::Debug, */ protected function connectUdp(): void { - if (!extension_loaded('sockets')) { + if (!\extension_loaded('sockets')) { throw new MissingExtensionException('The sockets extension is required to use udp URLs with the CubeHandler'); } @@ -92,7 +92,7 @@ protected function connectUdp(): void */ protected function connectHttp(): void { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is required to use http URLs with the CubeHandler'); } @@ -143,7 +143,7 @@ private function writeUdp(string $data): void throw new \LogicException('No UDP socket could be opened'); } - socket_send($this->udpConnection, $data, strlen($data), 0); + socket_send($this->udpConnection, $data, \strlen($data), 0); } private function writeHttp(string $data): void @@ -159,7 +159,7 @@ private function writeHttp(string $data): void curl_setopt($this->httpConnection, CURLOPT_POSTFIELDS, '['.$data.']'); curl_setopt($this->httpConnection, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', - 'Content-Length: ' . strlen('['.$data.']'), + 'Content-Length: ' . \strlen('['.$data.']'), ]); Curl\Util::execute($this->httpConnection, 5, false); diff --git a/src/Monolog/Handler/Curl/Util.php b/src/Monolog/Handler/Curl/Util.php index 4decf0e62..f10281144 100644 --- a/src/Monolog/Handler/Curl/Util.php +++ b/src/Monolog/Handler/Curl/Util.php @@ -44,7 +44,7 @@ public static function execute(CurlHandle $ch, int $retries = 5, bool $closeAfte if ($curlResponse === false) { $curlErrno = curl_errno($ch); - if (false === in_array($curlErrno, self::$retriableErrorCodes, true) || $retries === 0) { + if (false === \in_array($curlErrno, self::$retriableErrorCodes, true) || $retries === 0) { $curlError = curl_error($ch); if ($closeAfterDone) { diff --git a/src/Monolog/Handler/DeduplicationHandler.php b/src/Monolog/Handler/DeduplicationHandler.php index 0ef2734f4..c6e615c75 100644 --- a/src/Monolog/Handler/DeduplicationHandler.php +++ b/src/Monolog/Handler/DeduplicationHandler.php @@ -79,11 +79,11 @@ public function flush(): void foreach ($this->buffer as $record) { if ($record->level->value >= $this->deduplicationLevel->value) { - $passthru = $passthru === true || !is_array($store) || !$this->isDuplicate($store, $record); + $passthru = $passthru === true || !\is_array($store) || !$this->isDuplicate($store, $record); if ($passthru) { $line = $this->buildDeduplicationStoreEntry($record); file_put_contents($this->deduplicationStore, $line . "\n", FILE_APPEND); - if (!is_array($store)) { + if (!\is_array($store)) { $store = []; } $store[] = $line; @@ -113,7 +113,7 @@ protected function isDuplicate(array $store, LogRecord $record): bool $expectedMessage = preg_replace('{[\r\n].*}', '', $record->message); $yesterday = time() - 86400; - for ($i = count($store) - 1; $i >= 0; $i--) { + for ($i = \count($store) - 1; $i >= 0; $i--) { list($timestamp, $level, $message) = explode(':', $store[$i], 3); if ($level === $record->level->getName() && $message === $expectedMessage && $timestamp > $timestampValidity) { @@ -155,7 +155,7 @@ private function collectLogs(): void while (!feof($handle)) { $log = fgets($handle); - if (is_string($log) && '' !== $log && substr($log, 0, 10) >= $timestampValidity) { + if (\is_string($log) && '' !== $log && substr($log, 0, 10) >= $timestampValidity) { $validLogs[] = $log; } } diff --git a/src/Monolog/Handler/ErrorLogHandler.php b/src/Monolog/Handler/ErrorLogHandler.php index 571c439e1..aaad9d48c 100644 --- a/src/Monolog/Handler/ErrorLogHandler.php +++ b/src/Monolog/Handler/ErrorLogHandler.php @@ -40,7 +40,7 @@ public function __construct(int $messageType = self::OPERATING_SYSTEM, int|strin { parent::__construct($level, $bubble); - if (false === in_array($messageType, self::getAvailableTypes(), true)) { + if (false === \in_array($messageType, self::getAvailableTypes(), true)) { $message = sprintf('The given message type "%s" is not supported', print_r($messageType, true)); throw new \InvalidArgumentException($message); diff --git a/src/Monolog/Handler/FilterHandler.php b/src/Monolog/Handler/FilterHandler.php index 66f65477a..81dde3a16 100644 --- a/src/Monolog/Handler/FilterHandler.php +++ b/src/Monolog/Handler/FilterHandler.php @@ -87,7 +87,7 @@ public function getAcceptedLevels(): array */ public function setAcceptedLevels(int|string|Level|array $minLevelOrList = Level::Debug, int|string|Level $maxLevel = Level::Emergency): self { - if (is_array($minLevelOrList)) { + if (\is_array($minLevelOrList)) { $acceptedLevels = array_map(Logger::toMonologLevel(...), $minLevelOrList); } else { $minLevelOrList = Logger::toMonologLevel($minLevelOrList); @@ -140,8 +140,8 @@ public function handleBatch(array $records): void } } - if (count($filtered) > 0) { - $this->getHandler($filtered[count($filtered) - 1])->handleBatch($filtered); + if (\count($filtered) > 0) { + $this->getHandler($filtered[\count($filtered) - 1])->handleBatch($filtered); } } @@ -175,7 +175,7 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface return $this; } - throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($handler).' does not support formatters.'); } /** @@ -188,7 +188,7 @@ public function getFormatter(): FormatterInterface return $handler->getFormatter(); } - throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($handler).' does not support formatters.'); } public function reset(): void diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index d4551fb9c..5c99d6ac3 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -130,7 +130,7 @@ public function handle(LogRecord $record): bool if ($this->buffering) { $this->buffer[] = $record; - if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) { + if ($this->bufferSize > 0 && \count($this->buffer) > $this->bufferSize) { array_shift($this->buffer); } if ($this->activationStrategy->isHandlerActivated($record)) { @@ -185,7 +185,7 @@ private function flushBuffer(): void $this->buffer = array_filter($this->buffer, static function ($record) use ($passthruLevel) { return $passthruLevel->includes($record->level); }); - if (count($this->buffer) > 0) { + if (\count($this->buffer) > 0) { $this->getHandler(end($this->buffer))->handleBatch($this->buffer); } } @@ -224,7 +224,7 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface return $this; } - throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($handler).' does not support formatters.'); } /** @@ -237,6 +237,6 @@ public function getFormatter(): FormatterInterface return $handler->getFormatter(); } - throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($handler).' does not support formatters.'); } } diff --git a/src/Monolog/Handler/FleepHookHandler.php b/src/Monolog/Handler/FleepHookHandler.php index 220648223..46ebfc0b7 100644 --- a/src/Monolog/Handler/FleepHookHandler.php +++ b/src/Monolog/Handler/FleepHookHandler.php @@ -54,7 +54,7 @@ public function __construct( ?float $connectionTimeout = null, ?int $chunkSize = null ) { - if (!extension_loaded('openssl')) { + if (!\extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP extension is required to use the FleepHookHandler'); } @@ -112,7 +112,7 @@ private function buildHeader(string $content): string $header = "POST " . static::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n"; $header .= "Host: " . static::FLEEP_HOST . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; - $header .= "Content-Length: " . strlen($content) . "\r\n"; + $header .= "Content-Length: " . \strlen($content) . "\r\n"; $header .= "\r\n"; return $header; diff --git a/src/Monolog/Handler/FlowdockHandler.php b/src/Monolog/Handler/FlowdockHandler.php index d24bec40b..27c6c1533 100644 --- a/src/Monolog/Handler/FlowdockHandler.php +++ b/src/Monolog/Handler/FlowdockHandler.php @@ -46,7 +46,7 @@ public function __construct( ?float $connectionTimeout = null, ?int $chunkSize = null ) { - if (!extension_loaded('openssl')) { + if (!\extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP extension is required to use the FlowdockHandler'); } @@ -119,7 +119,7 @@ private function buildHeader(string $content): string $header = "POST /v1/messages/team_inbox/" . $this->apiToken . " HTTP/1.1\r\n"; $header .= "Host: api.flowdock.com\r\n"; $header .= "Content-Type: application/json\r\n"; - $header .= "Content-Length: " . strlen($content) . "\r\n"; + $header .= "Content-Length: " . \strlen($content) . "\r\n"; $header .= "\r\n"; return $header; diff --git a/src/Monolog/Handler/IFTTTHandler.php b/src/Monolog/Handler/IFTTTHandler.php index 418f2ba03..b9c7ba84b 100644 --- a/src/Monolog/Handler/IFTTTHandler.php +++ b/src/Monolog/Handler/IFTTTHandler.php @@ -39,7 +39,7 @@ class IFTTTHandler extends AbstractProcessingHandler */ public function __construct(string $eventName, string $secretKey, int|string|Level $level = Level::Error, bool $bubble = true) { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the IFTTTHandler'); } diff --git a/src/Monolog/Handler/InsightOpsHandler.php b/src/Monolog/Handler/InsightOpsHandler.php index abb2f88f7..4b558bd65 100644 --- a/src/Monolog/Handler/InsightOpsHandler.php +++ b/src/Monolog/Handler/InsightOpsHandler.php @@ -43,7 +43,7 @@ public function __construct( ?float $connectionTimeout = null, ?int $chunkSize = null ) { - if ($useSSL && !extension_loaded('openssl')) { + if ($useSSL && !\extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for InsightOpsHandler'); } diff --git a/src/Monolog/Handler/LogEntriesHandler.php b/src/Monolog/Handler/LogEntriesHandler.php index 00259834e..8c12898e2 100644 --- a/src/Monolog/Handler/LogEntriesHandler.php +++ b/src/Monolog/Handler/LogEntriesHandler.php @@ -40,7 +40,7 @@ public function __construct( ?float $connectionTimeout = null, ?int $chunkSize = null ) { - if ($useSSL && !extension_loaded('openssl')) { + if ($useSSL && !\extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for LogEntriesHandler'); } diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index 6a9a20e01..597e01179 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -50,7 +50,7 @@ class LogglyHandler extends AbstractProcessingHandler */ public function __construct(string $token, int|string|Level $level = Level::Debug, bool $bubble = true) { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the LogglyHandler'); } @@ -64,7 +64,7 @@ public function __construct(string $token, int|string|Level $level = Level::Debu */ protected function getCurlHandler(string $endpoint): CurlHandle { - if (!array_key_exists($endpoint, $this->curlHandlers)) { + if (!\array_key_exists($endpoint, $this->curlHandlers)) { $this->curlHandlers[$endpoint] = $this->loadCurlHandle($endpoint); } @@ -96,7 +96,7 @@ public function setTag(string|array $tag): self if ('' === $tag || [] === $tag) { $this->tag = []; } else { - $this->tag = is_array($tag) ? $tag : [$tag]; + $this->tag = \is_array($tag) ? $tag : [$tag]; } return $this; @@ -109,7 +109,7 @@ public function setTag(string|array $tag): self public function addTag(string|array $tag): self { if ('' !== $tag) { - $tag = is_array($tag) ? $tag : [$tag]; + $tag = \is_array($tag) ? $tag : [$tag]; $this->tag = array_unique(array_merge($this->tag, $tag)); } diff --git a/src/Monolog/Handler/LogmaticHandler.php b/src/Monolog/Handler/LogmaticHandler.php index 876b1a953..6aa1b31bf 100644 --- a/src/Monolog/Handler/LogmaticHandler.php +++ b/src/Monolog/Handler/LogmaticHandler.php @@ -48,7 +48,7 @@ public function __construct( ?float $connectionTimeout = null, ?int $chunkSize = null ) { - if ($useSSL && !extension_loaded('openssl')) { + if ($useSSL && !\extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP extension is required to use SSL encrypted connection for LogmaticHandler'); } diff --git a/src/Monolog/Handler/NewRelicHandler.php b/src/Monolog/Handler/NewRelicHandler.php index b8cb3785b..4f28dd4a5 100644 --- a/src/Monolog/Handler/NewRelicHandler.php +++ b/src/Monolog/Handler/NewRelicHandler.php @@ -79,9 +79,9 @@ protected function write(LogRecord $record): void newrelic_notice_error($record->message); } - if (isset($record->formatted['context']) && is_array($record->formatted['context'])) { + if (isset($record->formatted['context']) && \is_array($record->formatted['context'])) { foreach ($record->formatted['context'] as $key => $parameter) { - if (is_array($parameter) && $this->explodeArrays) { + if (\is_array($parameter) && $this->explodeArrays) { foreach ($parameter as $paramKey => $paramValue) { $this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue); } @@ -91,9 +91,9 @@ protected function write(LogRecord $record): void } } - if (isset($record->formatted['extra']) && is_array($record->formatted['extra'])) { + if (isset($record->formatted['extra']) && \is_array($record->formatted['extra'])) { foreach ($record->formatted['extra'] as $key => $parameter) { - if (is_array($parameter) && $this->explodeArrays) { + if (\is_array($parameter) && $this->explodeArrays) { foreach ($parameter as $paramKey => $paramValue) { $this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue); } @@ -109,7 +109,7 @@ protected function write(LogRecord $record): void */ protected function isNewRelicEnabled(): bool { - return extension_loaded('newrelic'); + return \extension_loaded('newrelic'); } /** @@ -163,7 +163,7 @@ protected function setNewRelicTransactionName(string $transactionName): void */ protected function setNewRelicParameter(string $key, $value): void { - if (null === $value || is_scalar($value)) { + if (null === $value || \is_scalar($value)) { newrelic_add_custom_parameter($key, $value); } else { newrelic_add_custom_parameter($key, Utils::jsonEncode($value, null, true)); diff --git a/src/Monolog/Handler/OverflowHandler.php b/src/Monolog/Handler/OverflowHandler.php index a72b7a11d..b213a98dc 100644 --- a/src/Monolog/Handler/OverflowHandler.php +++ b/src/Monolog/Handler/OverflowHandler.php @@ -122,7 +122,7 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface return $this; } - throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.'); } /** @@ -134,6 +134,6 @@ public function getFormatter(): FormatterInterface return $this->handler->getFormatter(); } - throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.'); } } diff --git a/src/Monolog/Handler/ProcessHandler.php b/src/Monolog/Handler/ProcessHandler.php index 9edc9ac54..8b68e6463 100644 --- a/src/Monolog/Handler/ProcessHandler.php +++ b/src/Monolog/Handler/ProcessHandler.php @@ -96,7 +96,7 @@ protected function write(LogRecord $record): void */ private function ensureProcessIsStarted(): void { - if (is_resource($this->process) === false) { + if (\is_resource($this->process) === false) { $this->startProcess(); $this->handleStartupErrors(); @@ -129,7 +129,7 @@ private function handleStartupErrors(): void $errors = $this->readProcessErrors(); - if (is_resource($this->process) === false || $errors !== '') { + if (\is_resource($this->process) === false || $errors !== '') { throw new \UnexpectedValueException( sprintf('The process "%s" could not be opened: ' . $errors, $this->command) ); @@ -175,7 +175,7 @@ protected function writeProcessInput(string $string): void */ public function close(): void { - if (is_resource($this->process)) { + if (\is_resource($this->process)) { foreach ($this->pipes as $pipe) { fclose($pipe); } diff --git a/src/Monolog/Handler/PushoverHandler.php b/src/Monolog/Handler/PushoverHandler.php index 615f12194..f7389d1b9 100644 --- a/src/Monolog/Handler/PushoverHandler.php +++ b/src/Monolog/Handler/PushoverHandler.php @@ -145,7 +145,7 @@ protected function generateDataStream(LogRecord $record): string private function buildContent(LogRecord $record): string { // Pushover has a limit of 512 characters on title and message combined. - $maxMessageLength = 512 - strlen($this->title); + $maxMessageLength = 512 - \strlen($this->title); $message = ($this->useFormattedMessage) ? $record->formatted : $record->message; $message = Utils::substr($message, 0, $maxMessageLength); @@ -176,7 +176,7 @@ private function buildContent(LogRecord $record): string $dataArray = array_merge($extra, $context, $dataArray); // Only pass sounds that are supported by the API - if (isset($dataArray['sound']) && !in_array($dataArray['sound'], $this->sounds, true)) { + if (isset($dataArray['sound']) && !\in_array($dataArray['sound'], $this->sounds, true)) { unset($dataArray['sound']); } @@ -188,7 +188,7 @@ private function buildHeader(string $content): string $header = "POST /1/messages.json HTTP/1.1\r\n"; $header .= "Host: api.pushover.net\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; - $header .= "Content-Length: " . strlen($content) . "\r\n"; + $header .= "Content-Length: " . \strlen($content) . "\r\n"; $header .= "\r\n"; return $header; diff --git a/src/Monolog/Handler/RedisHandler.php b/src/Monolog/Handler/RedisHandler.php index 977f32c75..3ff4a916b 100644 --- a/src/Monolog/Handler/RedisHandler.php +++ b/src/Monolog/Handler/RedisHandler.php @@ -69,7 +69,7 @@ protected function write(LogRecord $record): void protected function writeCapped(LogRecord $record): void { if ($this->redisClient instanceof Redis) { - $mode = defined('Redis::MULTI') ? Redis::MULTI : 1; + $mode = \defined('Redis::MULTI') ? Redis::MULTI : 1; $this->redisClient->multi($mode) ->rPush($this->redisKey, $record->formatted) ->lTrim($this->redisKey, -$this->capSize, -1) diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index 86240b44f..da5521268 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -133,7 +133,7 @@ protected function rotate(): void return; } - if ($this->maxFiles >= count($logFiles)) { + if ($this->maxFiles >= \count($logFiles)) { // no files to remove return; } @@ -143,7 +143,7 @@ protected function rotate(): void return strcmp($b, $a); }); - foreach (array_slice($logFiles, $this->maxFiles) as $file) { + foreach (\array_slice($logFiles, $this->maxFiles) as $file) { if (is_writable($file)) { // suppress errors here as unlink() might fail if two processes // are cleaning up/rotating at the same time diff --git a/src/Monolog/Handler/SamplingHandler.php b/src/Monolog/Handler/SamplingHandler.php index db43d5a85..1b10580f2 100644 --- a/src/Monolog/Handler/SamplingHandler.php +++ b/src/Monolog/Handler/SamplingHandler.php @@ -103,7 +103,7 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface return $this; } - throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($handler).' does not support formatters.'); } /** @@ -116,6 +116,6 @@ public function getFormatter(): FormatterInterface return $handler->getFormatter(); } - throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.'); + throw new \UnexpectedValueException('The nested handler of type '.\get_class($handler).' does not support formatters.'); } } diff --git a/src/Monolog/Handler/SendGridHandler.php b/src/Monolog/Handler/SendGridHandler.php index b8f574bb4..0a6fe406b 100644 --- a/src/Monolog/Handler/SendGridHandler.php +++ b/src/Monolog/Handler/SendGridHandler.php @@ -57,7 +57,7 @@ class SendGridHandler extends MailHandler */ public function __construct(string $apiUser, string $apiKey, string $from, string|array $to, string $subject, int|string|Level $level = Level::Error, bool $bubble = true) { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the SendGridHandler'); } diff --git a/src/Monolog/Handler/Slack/SlackRecord.php b/src/Monolog/Handler/Slack/SlackRecord.php index 0cb8b9b4a..99a7fe2a5 100644 --- a/src/Monolog/Handler/Slack/SlackRecord.php +++ b/src/Monolog/Handler/Slack/SlackRecord.php @@ -321,7 +321,7 @@ public function setFormatter(?FormatterInterface $formatter = null): self */ private function generateAttachmentField(string $title, $value): array { - $value = is_array($value) + $value = \is_array($value) ? sprintf('```%s```', substr($this->stringify($value), 0, 1990)) : $value; diff --git a/src/Monolog/Handler/SlackHandler.php b/src/Monolog/Handler/SlackHandler.php index 1d9a17712..c72d36208 100644 --- a/src/Monolog/Handler/SlackHandler.php +++ b/src/Monolog/Handler/SlackHandler.php @@ -63,7 +63,7 @@ public function __construct( ?float $connectionTimeout = null, ?int $chunkSize = null ) { - if (!extension_loaded('openssl')) { + if (!\extension_loaded('openssl')) { throw new MissingExtensionException('The OpenSSL PHP extension is required to use the SlackHandler'); } @@ -129,7 +129,7 @@ protected function prepareContentData(LogRecord $record): array $dataArray = $this->slackRecord->getSlackData($record); $dataArray['token'] = $this->token; - if (isset($dataArray['attachments']) && is_array($dataArray['attachments']) && \count($dataArray['attachments']) > 0) { + if (isset($dataArray['attachments']) && \is_array($dataArray['attachments']) && \count($dataArray['attachments']) > 0) { $dataArray['attachments'] = Utils::jsonEncode($dataArray['attachments']); } @@ -144,7 +144,7 @@ private function buildHeader(string $content): string $header = "POST /api/chat.postMessage HTTP/1.1\r\n"; $header .= "Host: slack.com\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; - $header .= "Content-Length: " . strlen($content) . "\r\n"; + $header .= "Content-Length: " . \strlen($content) . "\r\n"; $header .= "\r\n"; return $header; @@ -168,7 +168,7 @@ protected function write(LogRecord $record): void protected function finalizeWrite(): void { $res = $this->getResource(); - if (is_resource($res)) { + if (\is_resource($res)) { @fread($res, 2048); } $this->closeSocket(); diff --git a/src/Monolog/Handler/SlackWebhookHandler.php b/src/Monolog/Handler/SlackWebhookHandler.php index c69237aeb..eac51ccbe 100644 --- a/src/Monolog/Handler/SlackWebhookHandler.php +++ b/src/Monolog/Handler/SlackWebhookHandler.php @@ -59,7 +59,7 @@ public function __construct( bool $bubble = true, array $excludeFields = [] ) { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the SlackWebhookHandler'); } diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index 63f437f3f..94e055f22 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -63,7 +63,7 @@ public function __construct( $this->validateTimeout($connectionTimeout); } - $this->connectionTimeout = $connectionTimeout ?? (float) ini_get('default_socket_timeout'); + $this->connectionTimeout = $connectionTimeout ?? (float) \ini_get('default_socket_timeout'); $this->persistent = $persistent; $this->validateTimeout($timeout); $this->timeout = $timeout; @@ -102,7 +102,7 @@ public function close(): void */ public function closeSocket(): void { - if (is_resource($this->resource)) { + if (\is_resource($this->resource)) { fclose($this->resource); $this->resource = null; } @@ -229,7 +229,7 @@ public function getChunkSize(): ?int */ public function isConnected(): bool { - return is_resource($this->resource) + return \is_resource($this->resource) && !feof($this->resource); // on TCP - other party can close connection. } @@ -263,7 +263,7 @@ protected function streamSetTimeout(): bool $seconds = floor($this->timeout); $microseconds = round(($this->timeout - $seconds) * 1e6); - if (!is_resource($this->resource)) { + if (!\is_resource($this->resource)) { throw new \LogicException('streamSetTimeout called but $this->resource is not a resource'); } @@ -279,7 +279,7 @@ protected function streamSetTimeout(): bool */ protected function streamSetChunkSize(): int|bool { - if (!is_resource($this->resource)) { + if (!\is_resource($this->resource)) { throw new \LogicException('streamSetChunkSize called but $this->resource is not a resource'); } @@ -297,7 +297,7 @@ protected function streamSetChunkSize(): int|bool */ protected function fwrite(string $data): int|bool { - if (!is_resource($this->resource)) { + if (!\is_resource($this->resource)) { throw new \LogicException('fwrite called but $this->resource is not a resource'); } @@ -311,7 +311,7 @@ protected function fwrite(string $data): int|bool */ protected function streamGetMetadata(): array|bool { - if (!is_resource($this->resource)) { + if (!\is_resource($this->resource)) { throw new \LogicException('streamGetMetadata called but $this->resource is not a resource'); } @@ -360,7 +360,7 @@ private function createSocketResource(): void } else { $resource = $this->fsockopen(); } - if (is_bool($resource)) { + if (\is_bool($resource)) { throw new \UnexpectedValueException("Failed connecting to $this->connectionString ($this->errno: $this->errstr)"); } $this->resource = $resource; @@ -382,7 +382,7 @@ private function setStreamChunkSize(): void private function writeToSocket(string $data): void { - $length = strlen($data); + $length = \strlen($data); $sent = 0; $this->lastSentBytes = $sent; while ($this->isConnected() && $sent < $length) { @@ -396,7 +396,7 @@ private function writeToSocket(string $data): void } $sent += $chunk; $socketInfo = $this->streamGetMetadata(); - if (is_array($socketInfo) && (bool) $socketInfo['timed_out']) { + if (\is_array($socketInfo) && (bool) $socketInfo['timed_out']) { throw new \RuntimeException("Write timed-out"); } diff --git a/src/Monolog/Handler/SqsHandler.php b/src/Monolog/Handler/SqsHandler.php index b4512a601..1d28b65d4 100644 --- a/src/Monolog/Handler/SqsHandler.php +++ b/src/Monolog/Handler/SqsHandler.php @@ -44,12 +44,12 @@ public function __construct(SqsClient $sqsClient, string $queueUrl, int|string|L */ protected function write(LogRecord $record): void { - if (!isset($record->formatted) || 'string' !== gettype($record->formatted)) { + if (!isset($record->formatted) || 'string' !== \gettype($record->formatted)) { throw new \InvalidArgumentException('SqsHandler accepts only formatted records as a string' . Utils::getRecordMessageForException($record)); } $messageBody = $record->formatted; - if (strlen($messageBody) >= static::MAX_MESSAGE_SIZE) { + if (\strlen($messageBody) >= static::MAX_MESSAGE_SIZE) { $messageBody = Utils::substr($messageBody, 0, static::HEAD_MESSAGE_SIZE); } diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index f3e11c8c5..08cf85543 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -48,7 +48,7 @@ public function __construct($stream, int|string|Level $level = Level::Debug, boo { parent::__construct($level, $bubble); - if (($phpMemoryLimit = Utils::expandIniShorthandBytes(ini_get('memory_limit'))) !== false) { + if (($phpMemoryLimit = Utils::expandIniShorthandBytes(\ini_get('memory_limit'))) !== false) { if ($phpMemoryLimit > 0) { // use max 10% of allowed memory for the chunk size, and at least 100KB $this->streamChunkSize = min(static::MAX_CHUNK_SIZE, max((int) ($phpMemoryLimit / 10), 100 * 1024)); @@ -61,11 +61,11 @@ public function __construct($stream, int|string|Level $level = Level::Debug, boo $this->streamChunkSize = static::DEFAULT_CHUNK_SIZE; } - if (is_resource($stream)) { + if (\is_resource($stream)) { $this->stream = $stream; stream_set_chunk_size($this->stream, $this->streamChunkSize); - } elseif (is_string($stream)) { + } elseif (\is_string($stream)) { $this->url = Utils::canonicalizePath($stream); } else { throw new \InvalidArgumentException('A stream must either be a resource or a string.'); @@ -80,7 +80,7 @@ public function __construct($stream, int|string|Level $level = Level::Debug, boo */ public function close(): void { - if (null !== $this->url && is_resource($this->stream)) { + if (null !== $this->url && \is_resource($this->stream)) { fclose($this->stream); } $this->stream = null; @@ -115,7 +115,7 @@ public function getStreamChunkSize(): int */ protected function write(LogRecord $record): void { - if (!is_resource($this->stream)) { + if (!\is_resource($this->stream)) { $url = $this->url; if (null === $url || '' === $url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().' . Utils::getRecordMessageForException($record)); @@ -133,7 +133,7 @@ protected function write(LogRecord $record): void } finally { restore_error_handler(); } - if (!is_resource($stream)) { + if (!\is_resource($stream)) { $this->stream = null; throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened in append mode: '.$this->errorMessage, $url) . Utils::getRecordMessageForException($record)); @@ -175,11 +175,11 @@ private function getDirFromStream(string $stream): ?string { $pos = strpos($stream, '://'); if ($pos === false) { - return dirname($stream); + return \dirname($stream); } if ('file://' === substr($stream, 0, 7)) { - return dirname(substr($stream, 7)); + return \dirname(substr($stream, 7)); } return null; diff --git a/src/Monolog/Handler/SymfonyMailerHandler.php b/src/Monolog/Handler/SymfonyMailerHandler.php index 842b6577f..6e0fba341 100644 --- a/src/Monolog/Handler/SymfonyMailerHandler.php +++ b/src/Monolog/Handler/SymfonyMailerHandler.php @@ -76,7 +76,7 @@ protected function buildMessage(string $content, array $records): Email $message = null; if ($this->emailTemplate instanceof Email) { $message = clone $this->emailTemplate; - } elseif (is_callable($this->emailTemplate)) { + } elseif (\is_callable($this->emailTemplate)) { $message = ($this->emailTemplate)($content, $records); } diff --git a/src/Monolog/Handler/SyslogUdp/UdpSocket.php b/src/Monolog/Handler/SyslogUdp/UdpSocket.php index 6a4833450..3ff0bce5f 100644 --- a/src/Monolog/Handler/SyslogUdp/UdpSocket.php +++ b/src/Monolog/Handler/SyslogUdp/UdpSocket.php @@ -65,12 +65,12 @@ protected function getSocket(): Socket protected function send(string $chunk): void { - socket_sendto($this->getSocket(), $chunk, strlen($chunk), $flags = 0, $this->ip, $this->port); + socket_sendto($this->getSocket(), $chunk, \strlen($chunk), $flags = 0, $this->ip, $this->port); } protected function assembleMessage(string $line, string $header): string { - $chunkSize = static::DATAGRAM_MAX_LENGTH - strlen($header); + $chunkSize = static::DATAGRAM_MAX_LENGTH - \strlen($header); return $header . Utils::substr($line, 0, $chunkSize); } diff --git a/src/Monolog/Handler/SyslogUdpHandler.php b/src/Monolog/Handler/SyslogUdpHandler.php index 607409353..e8db4cdeb 100644 --- a/src/Monolog/Handler/SyslogUdpHandler.php +++ b/src/Monolog/Handler/SyslogUdpHandler.php @@ -54,7 +54,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler */ public function __construct(string $host, int $port = 514, string|int $facility = LOG_USER, int|string|Level $level = Level::Debug, bool $bubble = true, string $ident = 'php', int $rfc = self::RFC5424) { - if (!extension_loaded('sockets')) { + if (!\extension_loaded('sockets')) { throw new MissingExtensionException('The sockets extension is required to use the SyslogUdpHandler'); } @@ -88,7 +88,7 @@ public function close(): void */ private function splitMessageIntoLines($message): array { - if (is_array($message)) { + if (\is_array($message)) { $message = implode("\n", $message); } diff --git a/src/Monolog/Handler/TelegramBotHandler.php b/src/Monolog/Handler/TelegramBotHandler.php index 8fda76977..e4f69a9ff 100644 --- a/src/Monolog/Handler/TelegramBotHandler.php +++ b/src/Monolog/Handler/TelegramBotHandler.php @@ -118,7 +118,7 @@ public function __construct( bool $delayBetweenMessages = false, int $topic = null ) { - if (!extension_loaded('curl')) { + if (!\extension_loaded('curl')) { throw new MissingExtensionException('The curl extension is needed to use the TelegramBotHandler'); } @@ -139,7 +139,7 @@ public function __construct( */ public function setParseMode(string|null $parseMode = null): self { - if ($parseMode !== null && !in_array($parseMode, self::AVAILABLE_PARSE_MODES, true)) { + if ($parseMode !== null && !\in_array($parseMode, self::AVAILABLE_PARSE_MODES, true)) { throw new \InvalidArgumentException('Unknown parseMode, use one of these: ' . implode(', ', self::AVAILABLE_PARSE_MODES) . '.'); } @@ -271,7 +271,7 @@ protected function sendCurl(string $message): void curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); $result = Curl\Util::execute($ch); - if (!is_string($result)) { + if (!\is_string($result)) { throw new RuntimeException('Telegram API error. Description: No response'); } $result = json_decode($result, true); @@ -288,8 +288,8 @@ protected function sendCurl(string $message): void private function handleMessageLength(string $message): array { $truncatedMarker = ' (...truncated)'; - if (!$this->splitLongMessages && strlen($message) > self::MAX_MESSAGE_LENGTH) { - return [Utils::substr($message, 0, self::MAX_MESSAGE_LENGTH - strlen($truncatedMarker)) . $truncatedMarker]; + if (!$this->splitLongMessages && \strlen($message) > self::MAX_MESSAGE_LENGTH) { + return [Utils::substr($message, 0, self::MAX_MESSAGE_LENGTH - \strlen($truncatedMarker)) . $truncatedMarker]; } return str_split($message, self::MAX_MESSAGE_LENGTH); diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index 8e356ef31..a98389b95 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/src/Monolog/Handler/TestHandler.php @@ -119,7 +119,7 @@ public function hasRecords(int|string|Level $level): bool */ public function hasRecord(string|array $recordAssertions, Level $level): bool { - if (is_string($recordAssertions)) { + if (\is_string($recordAssertions)) { $recordAssertions = ['message' => $recordAssertions]; } @@ -181,15 +181,15 @@ public function __call(string $method, array $args): bool { if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) { $genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3]; - $level = constant(Level::class.'::' . $matches[2]); + $level = \constant(Level::class.'::' . $matches[2]); $callback = [$this, $genericMethod]; - if (is_callable($callback)) { + if (\is_callable($callback)) { $args[] = $level; - return call_user_func_array($callback, $args); + return \call_user_func_array($callback, $args); } } - throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()'); + throw new \BadMethodCallException('Call to undefined method ' . \get_class($this) . '::' . $method . '()'); } } diff --git a/src/Monolog/Handler/ZendMonitorHandler.php b/src/Monolog/Handler/ZendMonitorHandler.php index 1e71194bc..8841f2f14 100644 --- a/src/Monolog/Handler/ZendMonitorHandler.php +++ b/src/Monolog/Handler/ZendMonitorHandler.php @@ -29,7 +29,7 @@ class ZendMonitorHandler extends AbstractProcessingHandler */ public function __construct(int|string|Level $level = Level::Debug, bool $bubble = true) { - if (!function_exists('zend_monitor_custom_event')) { + if (!\function_exists('zend_monitor_custom_event')) { throw new MissingExtensionException( 'You must have Zend Server installed with Zend Monitor enabled in order to use this handler' ); diff --git a/src/Monolog/LogRecord.php b/src/Monolog/LogRecord.php index df758c58b..94b2a2500 100644 --- a/src/Monolog/LogRecord.php +++ b/src/Monolog/LogRecord.php @@ -42,7 +42,7 @@ public function __construct( public function offsetSet(mixed $offset, mixed $value): void { if ($offset === 'extra') { - if (!is_array($value)) { + if (!\is_array($value)) { throw new \InvalidArgumentException('extra must be an array'); } diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index f33c08f88..0e3233816 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -330,7 +330,7 @@ public function useLoggingLoopDetection(bool $detectCycles): self */ public function addRecord(int|Level $level, string $message, array $context = [], DateTimeImmutable|null $datetime = null): bool { - if (is_int($level) && isset(self::RFC_5424_LEVELS[$level])) { + if (\is_int($level) && isset(self::RFC_5424_LEVELS[$level])) { $level = self::RFC_5424_LEVELS[$level]; } @@ -352,7 +352,7 @@ public function addRecord(int|Level $level, string $message, array $context = [] } try { - $recordInitialized = count($this->processors) === 0; + $recordInitialized = \count($this->processors) === 0; $record = new LogRecord( datetime: $datetime ?? new DateTimeImmutable($this->microsecondTimestamps, $this->timezone), @@ -482,7 +482,7 @@ public static function toMonologLevel(string|int|Level $level): Level } if (\is_string($level)) { - if (\is_numeric($level)) { + if (is_numeric($level)) { $levelEnum = Level::tryFrom((int) $level); if ($levelEnum === null) { throw new InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', ', Level::NAMES + Level::VALUES)); @@ -494,8 +494,8 @@ public static function toMonologLevel(string|int|Level $level): Level // Contains first char of all log levels and avoids using strtoupper() which may have // strange results depending on locale (for example, "i" will become "İ" in Turkish locale) $upper = strtr(substr($level, 0, 1), 'dinweca', 'DINWECA') . strtolower(substr($level, 1)); - if (defined(Level::class.'::'.$upper)) { - return constant(Level::class . '::' . $upper); + if (\defined(Level::class.'::'.$upper)) { + return \constant(Level::class . '::' . $upper); } throw new InvalidArgumentException('Level "'.$level.'" is not defined, use one of: '.implode(', ', Level::NAMES + Level::VALUES)); @@ -565,7 +565,7 @@ public function getExceptionHandler(): Closure|null public function log($level, string|\Stringable $message, array $context = []): void { if (!$level instanceof Level) { - if (!is_string($level) && !is_int($level)) { + if (!\is_string($level) && !\is_int($level)) { throw new \InvalidArgumentException('$level is expected to be a string, int or '.Level::class.' instance'); } diff --git a/src/Monolog/Processor/GitProcessor.php b/src/Monolog/Processor/GitProcessor.php index 5a70ac2e2..6b25505de 100644 --- a/src/Monolog/Processor/GitProcessor.php +++ b/src/Monolog/Processor/GitProcessor.php @@ -63,7 +63,7 @@ private static function getGitInfo(): array } $branches = shell_exec('git branch -v --no-abbrev'); - if (is_string($branches) && 1 === preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) { + if (\is_string($branches) && 1 === preg_match('{^\* (.+?)\s+([a-f0-9]{40})(?:\s|$)}m', $branches, $matches)) { return self::$cache = [ 'branch' => $matches[1], 'commit' => $matches[2], diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index 3a6fbfbef..433f4d28b 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -82,7 +82,7 @@ public function __invoke(LogRecord $record): LogRecord continue 2; } } - } elseif (in_array($trace[$i]['function'], self::SKIP_FUNCTIONS, true)) { + } elseif (\in_array($trace[$i]['function'], self::SKIP_FUNCTIONS, true)) { $i++; continue; @@ -117,6 +117,6 @@ private function isTraceClassOrSkippedFunction(array $trace, int $index): bool return false; } - return isset($trace[$index]['class']) || in_array($trace[$index]['function'], self::SKIP_FUNCTIONS, true); + return isset($trace[$index]['class']) || \in_array($trace[$index]['function'], self::SKIP_FUNCTIONS, true); } } diff --git a/src/Monolog/Processor/LoadAverageProcessor.php b/src/Monolog/Processor/LoadAverageProcessor.php index 64e3c4747..762ed9142 100644 --- a/src/Monolog/Processor/LoadAverageProcessor.php +++ b/src/Monolog/Processor/LoadAverageProcessor.php @@ -40,7 +40,7 @@ class LoadAverageProcessor implements ProcessorInterface */ public function __construct(int $avgSystemLoad = self::LOAD_1_MINUTE) { - if (!in_array($avgSystemLoad, self::AVAILABLE_LOAD, true)) { + if (!\in_array($avgSystemLoad, self::AVAILABLE_LOAD, true)) { throw new \InvalidArgumentException(sprintf('Invalid average system load: `%s`', $avgSystemLoad)); } $this->avgSystemLoad = $avgSystemLoad; @@ -51,7 +51,7 @@ public function __construct(int $avgSystemLoad = self::LOAD_1_MINUTE) */ public function __invoke(LogRecord $record): LogRecord { - if (!function_exists('sys_getloadavg')) { + if (!\function_exists('sys_getloadavg')) { return $record; } $usage = sys_getloadavg(); diff --git a/src/Monolog/Processor/MercurialProcessor.php b/src/Monolog/Processor/MercurialProcessor.php index 47b1e64ff..a48a78544 100644 --- a/src/Monolog/Processor/MercurialProcessor.php +++ b/src/Monolog/Processor/MercurialProcessor.php @@ -63,7 +63,7 @@ private static function getMercurialInfo(): array $result = explode(' ', trim((string) shell_exec('hg id -nb'))); - if (count($result) >= 3) { + if (\count($result) >= 3) { return self::$cache = [ 'branch' => $result[1], 'revision' => $result[2], diff --git a/src/Monolog/Processor/PsrLogMessageProcessor.php b/src/Monolog/Processor/PsrLogMessageProcessor.php index aad2aad2f..76adf258f 100644 --- a/src/Monolog/Processor/PsrLogMessageProcessor.php +++ b/src/Monolog/Processor/PsrLogMessageProcessor.php @@ -57,7 +57,7 @@ public function __invoke(LogRecord $record): LogRecord continue; } - if (null === $val || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) { + if (null === $val || \is_scalar($val) || (\is_object($val) && method_exists($val, "__toString"))) { $replacements[$placeholder] = $val; } elseif ($val instanceof \DateTimeInterface) { if (null === $this->dateFormat && $val instanceof \Monolog\DateTimeImmutable) { @@ -69,12 +69,12 @@ public function __invoke(LogRecord $record): LogRecord } } elseif ($val instanceof \UnitEnum) { $replacements[$placeholder] = $val instanceof \BackedEnum ? $val->value : $val->name; - } elseif (is_object($val)) { + } elseif (\is_object($val)) { $replacements[$placeholder] = '[object '.Utils::getClass($val).']'; - } elseif (is_array($val)) { + } elseif (\is_array($val)) { $replacements[$placeholder] = 'array'.Utils::jsonEncode($val, null, true); } else { - $replacements[$placeholder] = '['.gettype($val).']'; + $replacements[$placeholder] = '['.\gettype($val).']'; } if ($this->removeUsedContextFields) { diff --git a/src/Monolog/Processor/UidProcessor.php b/src/Monolog/Processor/UidProcessor.php index 3a0c128c2..261e65389 100644 --- a/src/Monolog/Processor/UidProcessor.php +++ b/src/Monolog/Processor/UidProcessor.php @@ -53,7 +53,7 @@ public function getUid(): string public function reset(): void { - $this->uid = $this->generateUid(strlen($this->uid)); + $this->uid = $this->generateUid(\strlen($this->uid)); } /** diff --git a/src/Monolog/Processor/WebProcessor.php b/src/Monolog/Processor/WebProcessor.php index 1abb8400c..b78385e0c 100644 --- a/src/Monolog/Processor/WebProcessor.php +++ b/src/Monolog/Processor/WebProcessor.php @@ -65,7 +65,7 @@ public function __construct(array|ArrayAccess|null $serverData = null, array|nul } if (isset($extraFields[0])) { foreach (array_keys($this->extraFields) as $fieldName) { - if (!in_array($fieldName, $extraFields, true)) { + if (!\in_array($fieldName, $extraFields, true)) { unset($this->extraFields[$fieldName]); } } diff --git a/src/Monolog/SignalHandler.php b/src/Monolog/SignalHandler.php index b930ca439..b6a69fca0 100644 --- a/src/Monolog/SignalHandler.php +++ b/src/Monolog/SignalHandler.php @@ -44,7 +44,7 @@ public function __construct(LoggerInterface $logger) */ public function registerSignalHandler(int $signo, int|string|Level $level = LogLevel::CRITICAL, bool $callPrevious = true, bool $restartSyscalls = true, ?bool $async = true): self { - if (!extension_loaded('pcntl') || !function_exists('pcntl_signal')) { + if (!\extension_loaded('pcntl') || !\function_exists('pcntl_signal')) { return $this; } @@ -76,10 +76,10 @@ public function handleSignal(int $signo, $siginfo = null): void /** @var array $signals */ static $signals = []; - if (\count($signals) === 0 && extension_loaded('pcntl')) { + if (\count($signals) === 0 && \extension_loaded('pcntl')) { $pcntl = new ReflectionExtension('pcntl'); foreach ($pcntl->getConstants() as $name => $value) { - if (substr($name, 0, 3) === 'SIG' && $name[3] !== '_' && is_int($value)) { + if (substr($name, 0, 3) === 'SIG' && $name[3] !== '_' && \is_int($value)) { $signals[$value] = $name; } } @@ -95,8 +95,8 @@ public function handleSignal(int $signo, $siginfo = null): void } if ($this->previousSignalHandler[$signo] === SIG_DFL) { - if (extension_loaded('pcntl') && function_exists('pcntl_signal') && function_exists('pcntl_sigprocmask') && function_exists('pcntl_signal_dispatch') - && extension_loaded('posix') && function_exists('posix_getpid') && function_exists('posix_kill') + if (\extension_loaded('pcntl') && \function_exists('pcntl_signal') && \function_exists('pcntl_sigprocmask') && \function_exists('pcntl_signal_dispatch') + && \extension_loaded('posix') && \function_exists('posix_getpid') && \function_exists('posix_kill') ) { $restartSyscalls = $this->signalRestartSyscalls[$signo] ?? true; pcntl_signal($signo, SIG_DFL, $restartSyscalls); @@ -106,7 +106,7 @@ public function handleSignal(int $signo, $siginfo = null): void pcntl_sigprocmask(SIG_SETMASK, $oldset); pcntl_signal($signo, [$this, 'handleSignal'], $restartSyscalls); } - } elseif (is_callable($this->previousSignalHandler[$signo])) { + } elseif (\is_callable($this->previousSignalHandler[$signo])) { $this->previousSignalHandler[$signo]($signo, $siginfo); } } diff --git a/src/Monolog/Utils.php b/src/Monolog/Utils.php index 7848f0ecd..79ea96ca3 100644 --- a/src/Monolog/Utils.php +++ b/src/Monolog/Utils.php @@ -19,12 +19,12 @@ public static function getClass(object $object): string { $class = \get_class($object); - if (false === ($pos = \strpos($class, "@anonymous\0"))) { + if (false === ($pos = strpos($class, "@anonymous\0"))) { return $class; } - if (false === ($parent = \get_parent_class($class))) { - return \substr($class, 0, $pos + 10); + if (false === ($parent = get_parent_class($class))) { + return substr($class, 0, $pos + 10); } return $parent . '@anonymous'; @@ -32,11 +32,11 @@ public static function getClass(object $object): string public static function substr(string $string, int $start, ?int $length = null): string { - if (extension_loaded('mbstring')) { + if (\extension_loaded('mbstring')) { return mb_strcut($string, $start, $length); } - return substr($string, $start, (null === $length) ? strlen($string) : $length); + return substr($string, $start, (null === $length) ? \strlen($string) : $length); } /** @@ -119,9 +119,9 @@ public static function handleJsonError(int $code, $data, ?int $encodeFlags = nul self::throwEncodeError($code, $data); } - if (is_string($data)) { + if (\is_string($data)) { self::detectAndCleanUtf8($data); - } elseif (is_array($data)) { + } elseif (\is_array($data)) { array_walk_recursive($data, ['Monolog\Utils', 'detectAndCleanUtf8']); } else { self::throwEncodeError($code, $data); @@ -196,15 +196,15 @@ private static function throwEncodeError(int $code, $data): never */ private static function detectAndCleanUtf8(&$data): void { - if (is_string($data) && preg_match('//u', $data) !== 1) { + if (\is_string($data) && preg_match('//u', $data) !== 1) { $data = preg_replace_callback( '/[\x80-\xFF]+/', function (array $m): string { - return function_exists('mb_convert_encoding') ? mb_convert_encoding($m[0], 'UTF-8', 'ISO-8859-1') : utf8_encode($m[0]); + return \function_exists('mb_convert_encoding') ? mb_convert_encoding($m[0], 'UTF-8', 'ISO-8859-1') : utf8_encode($m[0]); }, $data ); - if (!is_string($data)) { + if (!\is_string($data)) { $pcreErrorCode = preg_last_error(); throw new \RuntimeException('Failed to preg_replace_callback: ' . $pcreErrorCode . ' / ' . self::pcreLastErrorMessage($pcreErrorCode)); @@ -225,7 +225,7 @@ function (array $m): string { */ public static function expandIniShorthandBytes($val) { - if (!is_string($val)) { + if (!\is_string($val)) { return false; } diff --git a/tests/Monolog/ErrorHandlerTest.php b/tests/Monolog/ErrorHandlerTest.php index 98c0e9960..55025479b 100644 --- a/tests/Monolog/ErrorHandlerTest.php +++ b/tests/Monolog/ErrorHandlerTest.php @@ -37,7 +37,7 @@ public function testHandleError() try { $errHandler->registerErrorHandler([], true); $prop = $this->getPrivatePropertyValue($errHandler, 'previousErrorHandler'); - $this->assertTrue(is_callable($prop)); + $this->assertTrue(\is_callable($prop)); $this->assertSame($prevHandler, $prop); $resHandler = $errHandler->registerErrorHandler([E_USER_NOTICE => LogLevel::EMERGENCY], false); @@ -66,7 +66,7 @@ public static function fatalHandlerProvider() protected function getPrivatePropertyValue($instance, $property) { - $ref = new \ReflectionClass(get_class($instance)); + $ref = new \ReflectionClass(\get_class($instance)); $prop = $ref->getProperty($property); $prop->setAccessible(true); @@ -105,7 +105,7 @@ public function testHandleException() $errHandler->registerExceptionHandler([], true); $prop = $this->getPrivatePropertyValue($errHandler, 'previousExceptionHandler'); - $this->assertTrue(is_callable($prop)); + $this->assertTrue(\is_callable($prop)); } public function testCodeToString() diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index eab7022ce..cda67e515 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -193,8 +193,8 @@ public function testFormatWithLargeData() $length = 200; foreach ($messageArray as $key => $value) { - if (!in_array($key, ['level', 'timestamp']) && is_string($value)) { - $length += strlen($value); + if (!\in_array($key, ['level', 'timestamp']) && \is_string($value)) { + $length += \strlen($value); } } @@ -219,8 +219,8 @@ public function testFormatWithUnlimitedLength() $length = 200; foreach ($messageArray as $key => $value) { - if (!in_array($key, ['level', 'timestamp'])) { - $length += strlen($value); + if (!\in_array($key, ['level', 'timestamp'])) { + $length += \strlen($value); } } diff --git a/tests/Monolog/Formatter/JsonFormatterTest.php b/tests/Monolog/Formatter/JsonFormatterTest.php index a3ab36dd3..76170018f 100644 --- a/tests/Monolog/Formatter/JsonFormatterTest.php +++ b/tests/Monolog/Formatter/JsonFormatterTest.php @@ -244,7 +244,7 @@ private function formatExceptionFilePathWithLine($exception): string private function formatException($exception, ?string $previous = null): string { $formattedException = - '{"class":"' . get_class($exception) . + '{"class":"' . \get_class($exception) . '","message":"' . $exception->getMessage() . '","code":' . $exception->getCode() . ',"file":"' . $this->formatExceptionFilePathWithLine($exception) . diff --git a/tests/Monolog/Formatter/LineFormatterTest.php b/tests/Monolog/Formatter/LineFormatterTest.php index ab31c64f4..8408a77b5 100644 --- a/tests/Monolog/Formatter/LineFormatterTest.php +++ b/tests/Monolog/Formatter/LineFormatterTest.php @@ -296,7 +296,7 @@ public function testBasePath(): void { $formatter = new LineFormatter(); $formatter->includeStacktraces(); - $formatter->setBasePath(dirname(dirname(dirname(__DIR__)))); + $formatter->setBasePath(\dirname(\dirname(\dirname(__DIR__)))); $formatter->indentStackTraces(' '); $message = $formatter->format($this->getRecord(message: "foo", context: ['exception' => new RuntimeException('lala')])); diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index 9744052f6..97aecefcd 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -67,13 +67,13 @@ public function testFormatExceptions() 'exception' => $e2, ]); - $this->assertGreaterThan(5, count($formatted['exception']['trace'])); + $this->assertGreaterThan(5, \count($formatted['exception']['trace'])); $this->assertTrue(isset($formatted['exception']['previous'])); unset($formatted['exception']['trace'], $formatted['exception']['previous']); $this->assertEquals([ 'exception' => [ - 'class' => get_class($e2), + 'class' => \get_class($e2), 'message' => $e2->getMessage(), 'code' => $e2->getCode(), 'file' => $e2->getFile().':'.$e2->getLine(), @@ -416,7 +416,7 @@ public function testExceptionTraceDoesNotLeakCallUserFuncArgs() { try { $arg = new TestInfoLeak; - call_user_func([$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 5f36fca7a..2cdf68308 100644 --- a/tests/Monolog/Formatter/ScalarFormatterTest.php +++ b/tests/Monolog/Formatter/ScalarFormatterTest.php @@ -69,7 +69,7 @@ public function testFormat() 'bat' => ['foo' => 'bar'], 'bap' => (string) $dt, 'ban' => [ - 'class' => get_class($exception), + 'class' => \get_class($exception), 'message' => $exception->getMessage(), 'code' => $exception->getCode(), 'file' => $exception->getFile() . ':' . $exception->getLine(), @@ -97,7 +97,7 @@ public function testFormatWithExceptionContext() $this->assertSame($this->encodeJson([ 'exception' => [ - 'class' => get_class($exception), + 'class' => \get_class($exception), 'message' => $exception->getMessage(), 'code' => $exception->getCode(), 'file' => $exception->getFile() . ':' . $exception->getLine(), diff --git a/tests/Monolog/Handler/AbstractProcessingHandlerTest.php b/tests/Monolog/Handler/AbstractProcessingHandlerTest.php index d9479c018..f44fc431d 100644 --- a/tests/Monolog/Handler/AbstractProcessingHandlerTest.php +++ b/tests/Monolog/Handler/AbstractProcessingHandlerTest.php @@ -87,7 +87,7 @@ public function testProcessRecord() }) ; $handler->handle($this->getRecord()); - $this->assertEquals(6, count($handledRecord['extra'])); + $this->assertEquals(6, \count($handledRecord['extra'])); } /** diff --git a/tests/Monolog/Handler/DynamoDbHandlerTest.php b/tests/Monolog/Handler/DynamoDbHandlerTest.php index 53c3a9cd5..d6a0babb8 100644 --- a/tests/Monolog/Handler/DynamoDbHandlerTest.php +++ b/tests/Monolog/Handler/DynamoDbHandlerTest.php @@ -27,7 +27,7 @@ public function setUp(): void $this->markTestSkipped('aws/aws-sdk-php not installed'); } - $this->isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>='); + $this->isV3 = \defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>='); $implementedMethods = ['__call']; diff --git a/tests/Monolog/Handler/ErrorLogHandlerTest.php b/tests/Monolog/Handler/ErrorLogHandlerTest.php index 37bf58c56..f51d22a6b 100644 --- a/tests/Monolog/Handler/ErrorLogHandlerTest.php +++ b/tests/Monolog/Handler/ErrorLogHandlerTest.php @@ -17,7 +17,7 @@ function error_log() { - $GLOBALS['error_log'][] = func_get_args(); + $GLOBALS['error_log'][] = \func_get_args(); } class ErrorLogHandlerTest extends TestCase diff --git a/tests/Monolog/Handler/FleepHookHandlerTest.php b/tests/Monolog/Handler/FleepHookHandlerTest.php index 75cd32be6..828282994 100644 --- a/tests/Monolog/Handler/FleepHookHandlerTest.php +++ b/tests/Monolog/Handler/FleepHookHandlerTest.php @@ -31,7 +31,7 @@ public function setUp(): void { parent::setUp(); - if (!extension_loaded('openssl')) { + if (!\extension_loaded('openssl')) { $this->markTestSkipped('This test requires openssl extension to run'); } diff --git a/tests/Monolog/Handler/FlowdockHandlerTest.php b/tests/Monolog/Handler/FlowdockHandlerTest.php index d7d28189c..3e03f1da5 100644 --- a/tests/Monolog/Handler/FlowdockHandlerTest.php +++ b/tests/Monolog/Handler/FlowdockHandlerTest.php @@ -30,7 +30,7 @@ class FlowdockHandlerTest extends TestCase public function setUp(): void { - if (!extension_loaded('openssl')) { + if (!\extension_loaded('openssl')) { $this->markTestSkipped('This test requires openssl to run'); } } diff --git a/tests/Monolog/Handler/InsightOpsHandlerTest.php b/tests/Monolog/Handler/InsightOpsHandlerTest.php index 99a53536d..144181ef9 100644 --- a/tests/Monolog/Handler/InsightOpsHandlerTest.php +++ b/tests/Monolog/Handler/InsightOpsHandlerTest.php @@ -59,7 +59,7 @@ public function testWriteBatchContent() private function createHandler() { - $useSSL = extension_loaded('openssl'); + $useSSL = \extension_loaded('openssl'); $args = ['testToken', 'us', $useSSL, Level::Debug, true]; $this->resource = fopen('php://memory', 'a'); $this->handler = $this->getMockBuilder(InsightOpsHandler::class) diff --git a/tests/Monolog/Handler/LogEntriesHandlerTest.php b/tests/Monolog/Handler/LogEntriesHandlerTest.php index 629b2349a..c078da3e1 100644 --- a/tests/Monolog/Handler/LogEntriesHandlerTest.php +++ b/tests/Monolog/Handler/LogEntriesHandlerTest.php @@ -63,7 +63,7 @@ public function testWriteBatchContent() private function createHandler() { - $useSSL = extension_loaded('openssl'); + $useSSL = \extension_loaded('openssl'); $args = ['testToken', $useSSL, Level::Debug, true]; $this->res = fopen('php://memory', 'a'); $this->handler = $this->getMockBuilder('Monolog\Handler\LogEntriesHandler') diff --git a/tests/Monolog/Handler/LogmaticHandlerTest.php b/tests/Monolog/Handler/LogmaticHandlerTest.php index a65b52521..4ac0c96d1 100644 --- a/tests/Monolog/Handler/LogmaticHandlerTest.php +++ b/tests/Monolog/Handler/LogmaticHandlerTest.php @@ -63,7 +63,7 @@ public function testWriteBatchContent() private function createHandler() { - $useSSL = extension_loaded('openssl'); + $useSSL = \extension_loaded('openssl'); $args = ['testToken', 'testHostname', 'testAppname', $useSSL, Level::Debug, true]; $this->res = fopen('php://memory', 'a'); $this->handler = $this->getMockBuilder('Monolog\Handler\LogmaticHandler') diff --git a/tests/Monolog/Handler/NativeMailerHandlerTest.php b/tests/Monolog/Handler/NativeMailerHandlerTest.php index 25564e9f1..81c1c04b1 100644 --- a/tests/Monolog/Handler/NativeMailerHandlerTest.php +++ b/tests/Monolog/Handler/NativeMailerHandlerTest.php @@ -16,7 +16,7 @@ function mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null) { - $GLOBALS['mail'][] = func_get_args(); + $GLOBALS['mail'][] = \func_get_args(); } class NativeMailerHandlerTest extends TestCase diff --git a/tests/Monolog/Handler/PHPConsoleHandlerTest.php b/tests/Monolog/Handler/PHPConsoleHandlerTest.php index e1ceb829a..f6b554636 100644 --- a/tests/Monolog/Handler/PHPConsoleHandlerTest.php +++ b/tests/Monolog/Handler/PHPConsoleHandlerTest.php @@ -143,7 +143,7 @@ public function testDebugContextInMessage() $message = 'test'; $tag = 'tag'; $context = [$tag, 'custom' => mt_rand()]; - $expectedMessage = $message . ' ' . json_encode(array_slice($context, 1)); + $expectedMessage = $message . ' ' . json_encode(\array_slice($context, 1)); $this->debugDispatcher->expects($this->once())->method('dispatchDebug')->with( $this->equalTo($expectedMessage), $this->equalTo($tag) @@ -197,7 +197,7 @@ public function testException() $handler = $this->initLogger(); $handler->log( \Psr\Log\LogLevel::ERROR, - sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), + sprintf('Uncaught Exception %s: "%s" at %s line %s', \get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e] ); } diff --git a/tests/Monolog/Handler/ProcessHandlerTest.php b/tests/Monolog/Handler/ProcessHandlerTest.php index 2d7003a6b..f0dfaa2c0 100644 --- a/tests/Monolog/Handler/ProcessHandlerTest.php +++ b/tests/Monolog/Handler/ProcessHandlerTest.php @@ -190,11 +190,11 @@ public function testCloseClosesProcess() $handler->handle($this->getRecord(Level::Warning, '21 is only the half truth')); $process = $property->getValue($handler); - $this->assertTrue(is_resource($process), 'Process is not running although it should.'); + $this->assertTrue(\is_resource($process), 'Process is not running although it should.'); $handler->close(); $process = $property->getValue($handler); - $this->assertFalse(is_resource($process), 'Process is still running although it should not.'); + $this->assertFalse(\is_resource($process), 'Process is still running although it should not.'); } } diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index f7f35533f..8de357d96 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -64,7 +64,7 @@ private function rrmdir($directory) { throw new InvalidArgumentException("$directory must be a directory"); } - if (substr($directory, strlen($directory) - 1, 1) !== '/') { + if (substr($directory, \strlen($directory) - 1, 1) !== '/') { $directory .= '/'; } @@ -169,7 +169,7 @@ public static function rotationTests() private function createDeep($file) { - mkdir(dirname($file), 0777, true); + mkdir(\dirname($file), 0777, true); touch($file); return $file; diff --git a/tests/Monolog/Handler/SamplingHandlerTest.php b/tests/Monolog/Handler/SamplingHandlerTest.php index 90f5c9b34..a2d93d9c6 100644 --- a/tests/Monolog/Handler/SamplingHandlerTest.php +++ b/tests/Monolog/Handler/SamplingHandlerTest.php @@ -25,7 +25,7 @@ public function testHandle() for ($i = 0; $i < 10000; $i++) { $handler->handle($this->getRecord()); } - $count = count($testHandler->getRecords()); + $count = \count($testHandler->getRecords()); // $count should be half of 10k, so between 4k and 6k $this->assertLessThan(6000, $count); $this->assertGreaterThan(4000, $count); diff --git a/tests/Monolog/Handler/SlackHandlerTest.php b/tests/Monolog/Handler/SlackHandlerTest.php index 6e5be8396..8ef83beae 100644 --- a/tests/Monolog/Handler/SlackHandlerTest.php +++ b/tests/Monolog/Handler/SlackHandlerTest.php @@ -32,7 +32,7 @@ class SlackHandlerTest extends TestCase public function setUp(): void { - if (!extension_loaded('openssl')) { + if (!\extension_loaded('openssl')) { $this->markTestSkipped('This test requires openssl to run'); } } diff --git a/tests/Monolog/Handler/SocketHandlerTest.php b/tests/Monolog/Handler/SocketHandlerTest.php index c8a2c7735..ca6c358e4 100644 --- a/tests/Monolog/Handler/SocketHandlerTest.php +++ b/tests/Monolog/Handler/SocketHandlerTest.php @@ -198,7 +198,7 @@ public function testWriteFailsOnIncompleteWrite() $callback = function ($string) use ($res) { fclose($res); - return strlen('Hello'); + return \strlen('Hello'); }; $this->handler->expects($this->exactly(1)) @@ -249,7 +249,7 @@ public function testClose() $this->writeRecord('Hello world'); $this->assertIsResource($this->res); $this->handler->close(); - $this->assertFalse(is_resource($this->res), "Expected resource to be closed after closing handler"); + $this->assertFalse(\is_resource($this->res), "Expected resource to be closed after closing handler"); } public function testCloseDoesNotClosePersistentSocket() @@ -257,9 +257,9 @@ public function testCloseDoesNotClosePersistentSocket() $this->setMockHandler(); $this->handler->setPersistent(true); $this->writeRecord('Hello world'); - $this->assertTrue(is_resource($this->res)); + $this->assertTrue(\is_resource($this->res)); $this->handler->close(); - $this->assertTrue(is_resource($this->res)); + $this->assertTrue(\is_resource($this->res)); } public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds() @@ -308,25 +308,25 @@ private function setMockHandler(array $methods = []) ->setConstructorArgs(['localhost:1234']) ->getMock(); - if (!in_array('fsockopen', $methods)) { + if (!\in_array('fsockopen', $methods)) { $this->handler->expects($this->any()) ->method('fsockopen') ->willReturn($this->res); } - if (!in_array('pfsockopen', $methods)) { + if (!\in_array('pfsockopen', $methods)) { $this->handler->expects($this->any()) ->method('pfsockopen') ->willReturn($this->res); } - if (!in_array('streamSetTimeout', $methods)) { + if (!\in_array('streamSetTimeout', $methods)) { $this->handler->expects($this->any()) ->method('streamSetTimeout') ->willReturn(true); } - if (!in_array('streamSetChunkSize', $methods)) { + if (!\in_array('streamSetChunkSize', $methods)) { $this->handler->expects($this->any()) ->method('streamSetChunkSize') ->willReturn(8192); diff --git a/tests/Monolog/Handler/StreamHandlerTest.php b/tests/Monolog/Handler/StreamHandlerTest.php index 882f8d843..378ed8c09 100644 --- a/tests/Monolog/Handler/StreamHandlerTest.php +++ b/tests/Monolog/Handler/StreamHandlerTest.php @@ -40,9 +40,9 @@ public function testCloseKeepsExternalHandlersOpen() { $handle = fopen('php://memory', 'a+'); $handler = new StreamHandler($handle); - $this->assertTrue(is_resource($handle)); + $this->assertTrue(\is_resource($handle)); $handler->close(); - $this->assertTrue(is_resource($handle)); + $this->assertTrue(\is_resource($handle)); } /** @@ -54,9 +54,9 @@ public function testClose() $handler->handle($this->getRecord(Level::Warning, 'test')); $stream = $handler->getStream(); - $this->assertTrue(is_resource($stream)); + $this->assertTrue(\is_resource($stream)); $handler->close(); - $this->assertFalse(is_resource($stream)); + $this->assertFalse(\is_resource($stream)); } /** @@ -69,17 +69,17 @@ public function testSerialization() $handler->handle($this->getRecord(Level::Warning, 'testfoo')); $stream = $handler->getStream(); - $this->assertTrue(is_resource($stream)); + $this->assertTrue(\is_resource($stream)); fseek($stream, 0); $this->assertStringContainsString('testfoo', stream_get_contents($stream)); $serialized = serialize($handler); - $this->assertFalse(is_resource($stream)); + $this->assertFalse(\is_resource($stream)); $handler = unserialize($serialized); $handler->handle($this->getRecord(Level::Warning, 'testbar')); $stream = $handler->getStream(); - $this->assertTrue(is_resource($stream)); + $this->assertTrue(\is_resource($stream)); fseek($stream, 0); $contents = stream_get_contents($stream); $this->assertStringNotContainsString('testfoo', $contents); @@ -212,7 +212,7 @@ public function testWriteNonExistingFileResource() #[DataProvider('provideNonExistingAndNotCreatablePath')] public function testWriteNonExistingAndNotCreatablePath($nonExistingAndNotCreatablePath) { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('Permissions checks can not run on windows'); } diff --git a/tests/Monolog/Handler/SymfonyMailerHandlerTest.php b/tests/Monolog/Handler/SymfonyMailerHandlerTest.php index ea4b9e26f..c9cf8835f 100644 --- a/tests/Monolog/Handler/SymfonyMailerHandlerTest.php +++ b/tests/Monolog/Handler/SymfonyMailerHandlerTest.php @@ -68,7 +68,7 @@ public function testMessageCanBeCustomizedGivenLoggedData() // Callback dynamically changes subject based on number of logged records $callback = function ($content, array $records) use ($expectedMessage) { - $subject = count($records) > 0 ? 'Emergency' : 'Normal'; + $subject = \count($records) > 0 ? 'Emergency' : 'Normal'; return $expectedMessage->subject($subject); }; $handler = new SymfonyMailerHandler($this->mailer, $callback); diff --git a/tests/Monolog/Handler/ZendMonitorHandlerTest.php b/tests/Monolog/Handler/ZendMonitorHandlerTest.php index 6c73eb6c8..a1064c3b9 100644 --- a/tests/Monolog/Handler/ZendMonitorHandlerTest.php +++ b/tests/Monolog/Handler/ZendMonitorHandlerTest.php @@ -17,7 +17,7 @@ class ZendMonitorHandlerTest extends TestCase { public function setUp(): void { - if (!function_exists('zend_monitor_custom_event')) { + if (!\function_exists('zend_monitor_custom_event')) { $this->markTestSkipped('ZendServer is not installed'); } } diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index ffae65587..89d010ed4 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -746,7 +746,7 @@ public function testReset() $logger->pushProcessor($processorUid2); $getProperty = function ($object, $property) { - $reflectionProperty = new \ReflectionProperty(get_class($object), $property); + $reflectionProperty = new \ReflectionProperty(\get_class($object), $property); $reflectionProperty->setAccessible(true); return $reflectionProperty->getValue($object); diff --git a/tests/Monolog/Processor/GitProcessorTest.php b/tests/Monolog/Processor/GitProcessorTest.php index a8fc3d007..175dec105 100644 --- a/tests/Monolog/Processor/GitProcessorTest.php +++ b/tests/Monolog/Processor/GitProcessorTest.php @@ -25,7 +25,7 @@ public function testProcessor() $record = $processor($this->getRecord()); $this->assertArrayHasKey('git', $record->extra); - $this->assertTrue(!is_array($record->extra['git']['branch'])); + $this->assertTrue(!\is_array($record->extra['git']['branch'])); } /** diff --git a/tests/Monolog/Processor/MercurialProcessorTest.php b/tests/Monolog/Processor/MercurialProcessorTest.php index 2e20bae15..25d91848b 100644 --- a/tests/Monolog/Processor/MercurialProcessorTest.php +++ b/tests/Monolog/Processor/MercurialProcessorTest.php @@ -20,7 +20,7 @@ class MercurialProcessorTest extends TestCase */ public function testProcessor() { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if (\defined('PHP_WINDOWS_VERSION_BUILD')) { exec("where hg 2>NUL", $output, $result); } else { exec("which hg 2>/dev/null >/dev/null", $output, $result); @@ -36,7 +36,7 @@ public function testProcessor() $record = $processor($this->getRecord()); $this->assertArrayHasKey('hg', $record->extra); - $this->assertTrue(!is_array($record->extra['hg']['branch'])); - $this->assertTrue(!is_array($record->extra['hg']['revision'])); + $this->assertTrue(!\is_array($record->extra['hg']['branch'])); + $this->assertTrue(!\is_array($record->extra['hg']['revision'])); } } diff --git a/tests/Monolog/Processor/UidProcessorTest.php b/tests/Monolog/Processor/UidProcessorTest.php index d9288acd5..14a791f5f 100644 --- a/tests/Monolog/Processor/UidProcessorTest.php +++ b/tests/Monolog/Processor/UidProcessorTest.php @@ -28,6 +28,6 @@ public function testProcessor() public function testGetUid() { $processor = new UidProcessor(10); - $this->assertEquals(10, strlen($processor->getUid())); + $this->assertEquals(10, \strlen($processor->getUid())); } } diff --git a/tests/Monolog/SignalHandlerTest.php b/tests/Monolog/SignalHandlerTest.php index 9d833a599..e08930acf 100644 --- a/tests/Monolog/SignalHandlerTest.php +++ b/tests/Monolog/SignalHandlerTest.php @@ -30,11 +30,11 @@ class SignalHandlerTest extends TestCase protected function setUp(): void { $this->signalHandlers = []; - if (extension_loaded('pcntl')) { - if (function_exists('pcntl_async_signals')) { + if (\extension_loaded('pcntl')) { + if (\function_exists('pcntl_async_signals')) { $this->asyncSignalHandling = pcntl_async_signals(); } - if (function_exists('pcntl_sigprocmask')) { + if (\function_exists('pcntl_sigprocmask')) { pcntl_sigprocmask(SIG_SETMASK, [], $this->blockedSignals); } } @@ -62,7 +62,7 @@ public function tearDown(): void private function setSignalHandler($signo, $handler = SIG_DFL) { - if (function_exists('pcntl_signal_get_handler')) { + if (\function_exists('pcntl_signal_get_handler')) { $this->signalHandlers[$signo] = pcntl_signal_get_handler($signo); } else { $this->signalHandlers[$signo] = SIG_DFL; @@ -95,7 +95,7 @@ public function testHandleSignal() public function testRegisterSignalHandler() { // SIGCONT and SIGURG should be ignored by default. - if (!defined('SIGCONT') || !defined('SIGURG')) { + if (!\defined('SIGCONT') || !\defined('SIGURG')) { $this->markTestSkipped('This test requires the SIGCONT and SIGURG pcntl constants.'); } @@ -162,7 +162,7 @@ public function testRegisterDefaultPreviousSignalHandler($signo, $callPrevious, public static function defaultPreviousProvider() { - if (!defined('SIGCONT') || !defined('SIGINT') || !defined('SIGURG')) { + if (!\defined('SIGCONT') || !\defined('SIGINT') || !\defined('SIGURG')) { return []; }