Skip to content

Commit

Permalink
Use fully-qualified name for native functions (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreis2211 committed Jun 28, 2024
1 parent 4e03d25 commit 3ba77d1
Show file tree
Hide file tree
Showing 90 changed files with 246 additions and 245 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Monolog/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/ChromePHPFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Monolog/Formatter/FlowdockFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) . ' ...';
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/FluentdFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
10 changes: 5 additions & 5 deletions src/Monolog/Formatter/GelfMessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));

Expand All @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/HtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Monolog/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
Expand All @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Monolog/Formatter/MongoDBFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<=');
}

/**
Expand Down Expand Up @@ -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);
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/Monolog/Formatter/NormalizerFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down Expand Up @@ -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';
}
Expand All @@ -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;
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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).')]';
}

/**
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/ScalarFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Monolog/Formatter/WildfireFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {

Check failure on line 88 in src/Monolog/Formatter/WildfireFormatter.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1)

Cannot access offset 'table' on array<array|bool|float|int|string|null>|bool|float|int|object|string.
$type = 'TABLE';
$label = $record->channel .': '. $record->message;
$message = $message['context']['table'];
Expand All @@ -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
);
}
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Monolog/Handler/AbstractSyslogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}

Expand Down
8 changes: 4 additions & 4 deletions src/Monolog/Handler/BrowserConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<script>' . self::generateScript() . '</script>');
} else { // js format
Expand Down Expand Up @@ -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');
Expand All @@ -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];

Expand Down Expand Up @@ -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));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Monolog/Handler/BufferHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

/**
Expand All @@ -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.');
}
}
Loading

0 comments on commit 3ba77d1

Please sign in to comment.