Skip to content

Commit 3ba77d1

Browse files
authored
Use fully-qualified name for native functions (#1887)
1 parent 4e03d25 commit 3ba77d1

File tree

90 files changed

+246
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+246
-245
lines changed

.php-cs-fixer.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
'header_comment' => ['header' => $header],
3131
'include' => true,
3232
'class_attributes_separation' => array('elements' => array('method' => 'one', 'trait_import' => 'none')),
33+
'native_function_invocation' => true,
3334
'no_blank_lines_after_class_opening' => true,
3435
'no_blank_lines_after_phpdoc' => true,
3536
'no_empty_statement' => true,

src/Monolog/ErrorHandler.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private function handleException(\Throwable $e): never
194194
($this->previousExceptionHandler)($e);
195195
}
196196

197-
if (!headers_sent() && in_array(strtolower((string) ini_get('display_errors')), ['0', '', 'false', 'off', 'none', 'no'], true)) {
197+
if (!headers_sent() && \in_array(strtolower((string) \ini_get('display_errors')), ['0', '', 'false', 'off', 'none', 'no'], true)) {
198198
http_response_code(500);
199199
}
200200

@@ -208,7 +208,7 @@ private function handleError(int $code, string $message, string $file = '', int
208208
}
209209

210210
// fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries
211-
if (!$this->hasFatalErrorHandler || !in_array($code, self::FATAL_ERRORS, true)) {
211+
if (!$this->hasFatalErrorHandler || !\in_array($code, self::FATAL_ERRORS, true)) {
212212
$level = $this->errorLevelMap[$code] ?? LogLevel::CRITICAL;
213213
$this->logger->log($level, self::codeToString($code).': '.$message, ['code' => $code, 'message' => $message, 'file' => $file, 'line' => $line]);
214214
} else {
@@ -234,12 +234,12 @@ public function handleFatalError(): void
234234
{
235235
$this->reservedMemory = '';
236236

237-
if (is_array($this->lastFatalData)) {
237+
if (\is_array($this->lastFatalData)) {
238238
$lastError = $this->lastFatalData;
239239
} else {
240240
$lastError = error_get_last();
241241
}
242-
if (is_array($lastError) && in_array($lastError['type'], self::FATAL_ERRORS, true)) {
242+
if (\is_array($lastError) && \in_array($lastError['type'], self::FATAL_ERRORS, true)) {
243243
$trace = $lastError['trace'] ?? null;
244244
$this->logger->log(
245245
$this->fatalLevel,

src/Monolog/Formatter/ChromePHPFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function format(LogRecord $record)
5959
if (\count($record->extra) > 0) {
6060
$message['extra'] = $record->extra;
6161
}
62-
if (count($message) === 1) {
62+
if (\count($message) === 1) {
6363
$message = reset($message);
6464
}
6565

src/Monolog/Formatter/FlowdockFormatter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getShortMessage(string $message): string
8686
static $hasMbString;
8787

8888
if (null === $hasMbString) {
89-
$hasMbString = function_exists('mb_strlen');
89+
$hasMbString = \function_exists('mb_strlen');
9090
}
9191

9292
$maxLength = 45;
@@ -96,7 +96,7 @@ public function getShortMessage(string $message): string
9696
$message = mb_substr($message, 0, $maxLength - 4, 'UTF-8') . ' ...';
9797
}
9898
} else {
99-
if (strlen($message) > $maxLength) {
99+
if (\strlen($message) > $maxLength) {
100100
$message = substr($message, 0, $maxLength - 4) . ' ...';
101101
}
102102
}

src/Monolog/Formatter/FluentdFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FluentdFormatter implements FormatterInterface
4747
*/
4848
public function __construct(bool $levelTag = false)
4949
{
50-
if (!function_exists('json_encode')) {
50+
if (!\function_exists('json_encode')) {
5151
throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s FluentdUnixFormatter');
5252
}
5353

src/Monolog/Formatter/GelfMessageFormatter.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function format(LogRecord $record): Message
104104
->setLevel($this->getGraylog2Priority($record->level));
105105

106106
// message length + system name length + 200 for padding / metadata
107-
$len = 200 + strlen($record->message) + strlen($this->systemName);
107+
$len = 200 + \strlen($record->message) + \strlen($this->systemName);
108108

109109
if ($len > $this->maxLength) {
110110
$message->setShortMessage(Utils::substr($record->message, 0, $this->maxLength));
@@ -115,8 +115,8 @@ public function format(LogRecord $record): Message
115115
}
116116

117117
foreach ($extra as $key => $val) {
118-
$val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
119-
$len = strlen($this->extraPrefix . $key . $val);
118+
$val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
119+
$len = \strlen($this->extraPrefix . $key . $val);
120120
if ($len > $this->maxLength) {
121121
$message->setAdditional($this->extraPrefix . $key, Utils::substr((string) $val, 0, $this->maxLength));
122122

@@ -126,8 +126,8 @@ public function format(LogRecord $record): Message
126126
}
127127

128128
foreach ($context as $key => $val) {
129-
$val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
130-
$len = strlen($this->contextPrefix . $key . $val);
129+
$val = \is_scalar($val) || null === $val ? $val : $this->toJson($val);
130+
$len = \strlen($this->contextPrefix . $key . $val);
131131
if ($len > $this->maxLength) {
132132
$message->setAdditional($this->contextPrefix . $key, Utils::substr((string) $val, 0, $this->maxLength));
133133

src/Monolog/Formatter/HtmlFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function formatBatch(array $records): string
132132
*/
133133
protected function convertToString($data): string
134134
{
135-
if (null === $data || is_scalar($data)) {
135+
if (null === $data || \is_scalar($data)) {
136136
return (string) $data;
137137
}
138138

src/Monolog/Formatter/JsonFormatter.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ protected function normalize(mixed $data, int $depth = 0): mixed
154154
return 'Over '.$this->maxNormalizeDepth.' levels deep, aborting normalization';
155155
}
156156

157-
if (is_array($data)) {
157+
if (\is_array($data)) {
158158
$normalized = [];
159159

160160
$count = 1;
161161
foreach ($data as $key => $value) {
162162
if ($count++ > $this->maxNormalizeItemCount) {
163-
$normalized['...'] = 'Over '.$this->maxNormalizeItemCount.' items ('.count($data).' total), aborting normalization';
163+
$normalized['...'] = 'Over '.$this->maxNormalizeItemCount.' items ('.\count($data).' total), aborting normalization';
164164
break;
165165
}
166166

@@ -170,7 +170,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed
170170
return $normalized;
171171
}
172172

173-
if (is_object($data)) {
173+
if (\is_object($data)) {
174174
if ($data instanceof \DateTimeInterface) {
175175
return $this->formatDate($data);
176176
}
@@ -195,7 +195,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed
195195
return $data;
196196
}
197197

198-
if (is_resource($data)) {
198+
if (\is_resource($data)) {
199199
return parent::normalize($data);
200200
}
201201

src/Monolog/Formatter/LineFormatter.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ protected function normalizeException(\Throwable $e, int $depth = 0): string
226226
*/
227227
protected function convertToString($data): string
228228
{
229-
if (null === $data || is_bool($data)) {
229+
if (null === $data || \is_bool($data)) {
230230
return var_export($data, true);
231231
}
232232

233-
if (is_scalar($data)) {
233+
if (\is_scalar($data)) {
234234
return (string) $data;
235235
}
236236

@@ -267,9 +267,9 @@ private function formatException(\Throwable $e): string
267267
}
268268

269269
if (isset($e->detail)) {
270-
if (is_string($e->detail)) {
270+
if (\is_string($e->detail)) {
271271
$str .= ' detail: ' . $e->detail;
272-
} elseif (is_object($e->detail) || is_array($e->detail)) {
272+
} elseif (\is_object($e->detail) || \is_array($e->detail)) {
273273
$str .= ' detail: ' . $this->toJson($e->detail, true);
274274
}
275275
}

src/Monolog/Formatter/MongoDBFormatter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(int $maxNestingLevel = 3, bool $exceptionTraceAsStri
3636
$this->maxNestingLevel = max($maxNestingLevel, 0);
3737
$this->exceptionTraceAsString = $exceptionTraceAsString;
3838

39-
$this->isLegacyMongoExt = extension_loaded('mongodb') && version_compare((string) phpversion('mongodb'), '1.1.9', '<=');
39+
$this->isLegacyMongoExt = \extension_loaded('mongodb') && version_compare((string) phpversion('mongodb'), '1.1.9', '<=');
4040
}
4141

4242
/**
@@ -82,9 +82,9 @@ protected function formatArray(array $array, int $nestingLevel = 0)
8282
$array[$name] = $this->formatDate($value, $nestingLevel + 1);
8383
} elseif ($value instanceof \Throwable) {
8484
$array[$name] = $this->formatException($value, $nestingLevel + 1);
85-
} elseif (is_array($value)) {
85+
} elseif (\is_array($value)) {
8686
$array[$name] = $this->formatArray($value, $nestingLevel + 1);
87-
} elseif (is_object($value) && !$value instanceof Type) {
87+
} elseif (\is_object($value) && !$value instanceof Type) {
8888
$array[$name] = $this->formatObject($value, $nestingLevel + 1);
8989
}
9090
}

src/Monolog/Formatter/NormalizerFormatter.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class NormalizerFormatter implements FormatterInterface
4040
public function __construct(?string $dateFormat = null)
4141
{
4242
$this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat;
43-
if (!function_exists('json_encode')) {
43+
if (!\function_exists('json_encode')) {
4444
throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s NormalizerFormatter');
4545
}
4646
}
@@ -182,8 +182,8 @@ protected function normalize(mixed $data, int $depth = 0): mixed
182182
return 'Over ' . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
183183
}
184184

185-
if (null === $data || is_scalar($data)) {
186-
if (is_float($data)) {
185+
if (null === $data || \is_scalar($data)) {
186+
if (\is_float($data)) {
187187
if (is_infinite($data)) {
188188
return ($data > 0 ? '' : '-') . 'INF';
189189
}
@@ -195,13 +195,13 @@ protected function normalize(mixed $data, int $depth = 0): mixed
195195
return $data;
196196
}
197197

198-
if (is_array($data)) {
198+
if (\is_array($data)) {
199199
$normalized = [];
200200

201201
$count = 1;
202202
foreach ($data as $key => $value) {
203203
if ($count++ > $this->maxNormalizeItemCount) {
204-
$normalized['...'] = 'Over ' . $this->maxNormalizeItemCount . ' items ('.count($data).' total), aborting normalization';
204+
$normalized['...'] = 'Over ' . $this->maxNormalizeItemCount . ' items ('.\count($data).' total), aborting normalization';
205205
break;
206206
}
207207

@@ -215,7 +215,7 @@ protected function normalize(mixed $data, int $depth = 0): mixed
215215
return $this->formatDate($data);
216216
}
217217

218-
if (is_object($data)) {
218+
if (\is_object($data)) {
219219
if ($data instanceof Throwable) {
220220
return $this->normalizeException($data, $depth);
221221
}
@@ -244,11 +244,11 @@ protected function normalize(mixed $data, int $depth = 0): mixed
244244
return [Utils::getClass($data) => $value];
245245
}
246246

247-
if (is_resource($data)) {
247+
if (\is_resource($data)) {
248248
return sprintf('[resource(%s)]', get_resource_type($data));
249249
}
250250

251-
return '[unknown('.gettype($data).')]';
251+
return '[unknown('.\gettype($data).')]';
252252
}
253253

254254
/**
@@ -286,9 +286,9 @@ protected function normalizeException(Throwable $e, int $depth = 0)
286286
}
287287

288288
if (isset($e->detail)) {
289-
if (is_string($e->detail)) {
289+
if (\is_string($e->detail)) {
290290
$data['detail'] = $e->detail;
291-
} elseif (is_object($e->detail) || is_array($e->detail)) {
291+
} elseif (\is_object($e->detail) || \is_array($e->detail)) {
292292
$data['detail'] = $this->toJson($e->detail, true);
293293
}
294294
}

src/Monolog/Formatter/ScalarFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function toScalar(mixed $value): string|int|float|bool|null
4040
{
4141
$normalized = $this->normalize($value);
4242

43-
if (is_array($normalized)) {
43+
if (\is_array($normalized)) {
4444
return $this->toJson($normalized, true);
4545
}
4646

src/Monolog/Formatter/WildfireFormatter.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ public function format(LogRecord $record): string
7373

7474
$message = ['message' => $record->message];
7575
$handleError = false;
76-
if (count($record->context) > 0) {
76+
if (\count($record->context) > 0) {
7777
$message['context'] = $this->normalize($record->context);
7878
$handleError = true;
7979
}
80-
if (count($record->extra) > 0) {
80+
if (\count($record->extra) > 0) {
8181
$message['extra'] = $this->normalize($record->extra);
8282
$handleError = true;
8383
}
84-
if (count($message) === 1) {
84+
if (\count($message) === 1) {
8585
$message = reset($message);
8686
}
8787

88-
if (is_array($message) && isset($message['context']['table'])) {
88+
if (\is_array($message) && isset($message['context']['table'])) {
8989
$type = 'TABLE';
9090
$label = $record->channel .': '. $record->message;
9191
$message = $message['context']['table'];
@@ -108,7 +108,7 @@ public function format(LogRecord $record): string
108108
// The message itself is a serialization of the above JSON object + it's length
109109
return sprintf(
110110
'%d|%s|',
111-
strlen($json),
111+
\strlen($json),
112112
$json
113113
);
114114
}
@@ -130,7 +130,7 @@ public function formatBatch(array $records)
130130
*/
131131
protected function normalize(mixed $data, int $depth = 0): mixed
132132
{
133-
if (is_object($data) && !$data instanceof \DateTimeInterface) {
133+
if (\is_object($data) && !$data instanceof \DateTimeInterface) {
134134
return $data;
135135
}
136136

src/Monolog/Handler/AbstractSyslogHandler.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(string|int $facility = \LOG_USER, int|string|Level $
5555
{
5656
parent::__construct($level, $bubble);
5757

58-
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
58+
if (!\defined('PHP_WINDOWS_VERSION_BUILD')) {
5959
$this->facilities['local0'] = \LOG_LOCAL0;
6060
$this->facilities['local1'] = \LOG_LOCAL1;
6161
$this->facilities['local2'] = \LOG_LOCAL2;
@@ -76,9 +76,9 @@ public function __construct(string|int $facility = \LOG_USER, int|string|Level $
7676
}
7777

7878
// convert textual description of facility to syslog constant
79-
if (is_string($facility) && array_key_exists(strtolower($facility), $this->facilities)) {
79+
if (\is_string($facility) && \array_key_exists(strtolower($facility), $this->facilities)) {
8080
$facility = $this->facilities[strtolower($facility)];
81-
} elseif (!in_array($facility, array_values($this->facilities), true)) {
81+
} elseif (!\in_array($facility, array_values($this->facilities), true)) {
8282
throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given');
8383
}
8484

src/Monolog/Handler/BrowserConsoleHandler.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function send(): void
7777
return;
7878
}
7979

80-
if (count(static::$records) > 0) {
80+
if (\count(static::$records) > 0) {
8181
if ($format === self::FORMAT_HTML) {
8282
static::writeOutput('<script>' . self::generateScript() . '</script>');
8383
} else { // js format
@@ -213,7 +213,7 @@ private static function handleStyles(string $formatted): array
213213
$args[] = self::quote(self::handleCustomStyles($match[2][0], $match[1][0]));
214214

215215
$pos = $match[0][1];
216-
$format = Utils::substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . Utils::substr($format, $pos + strlen($match[0][0]));
216+
$format = Utils::substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . Utils::substr($format, $pos + \strlen($match[0][0]));
217217
}
218218

219219
$args[] = self::quote('font-weight: normal');
@@ -231,7 +231,7 @@ private static function handleCustomStyles(string $style, string $string): strin
231231
if (trim($m[1]) === 'autolabel') {
232232
// Format the string as a label with consistent auto assigned background color
233233
if (!isset($labels[$string])) {
234-
$labels[$string] = $colors[count($labels) % count($colors)];
234+
$labels[$string] = $colors[\count($labels) % \count($colors)];
235235
}
236236
$color = $labels[$string];
237237

@@ -284,7 +284,7 @@ private static function quote(string $arg): string
284284
private static function call(...$args): string
285285
{
286286
$method = array_shift($args);
287-
if (!is_string($method)) {
287+
if (!\is_string($method)) {
288288
throw new \UnexpectedValueException('Expected the first arg to be a string, got: '.var_export($method, true));
289289
}
290290

src/Monolog/Handler/BufferHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface
148148
return $this;
149149
}
150150

151-
throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.');
151+
throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.');
152152
}
153153

154154
/**
@@ -160,6 +160,6 @@ public function getFormatter(): FormatterInterface
160160
return $this->handler->getFormatter();
161161
}
162162

163-
throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.');
163+
throw new \UnexpectedValueException('The nested handler of type '.\get_class($this->handler).' does not support formatters.');
164164
}
165165
}

0 commit comments

Comments
 (0)