Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 2f9160e

Browse files
[ErrorHandler][Debug] Do not use the php80 polyfill
1 parent 0239626 commit 2f9160e

9 files changed

+20
-21
lines changed

DebugClassLoader.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(callable $classLoader)
6161
if (false === $test || false === $i) {
6262
// filesystem is case sensitive
6363
self::$caseCheck = 0;
64-
} elseif (str_ends_with($test, $file)) {
64+
} elseif (substr($test, -\strlen($file)) === $file) {
6565
// filesystem is case insensitive and realpath() normalizes the case of characters
6666
self::$caseCheck = 1;
6767
} elseif (false !== stripos(\PHP_OS, 'darwin')) {
@@ -210,7 +210,7 @@ private function checkClass(string $class, string $file = null)
210210
}
211211

212212
if (!$exists) {
213-
if (str_contains($class, '/')) {
213+
if (false !== strpos($class, '/')) {
214214
throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class));
215215
}
216216

@@ -237,17 +237,17 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
237237
// Detect annotations on the class
238238
if (false !== $doc = $refl->getDocComment()) {
239239
foreach (['final', 'deprecated', 'internal'] as $annotation) {
240-
if (str_contains($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
240+
if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
241241
self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
242242
}
243243
}
244244

245-
if ($refl->isInterface() && str_contains($doc, 'method') && preg_match_all('#\n \* @method\s+(static\s+)?+(?:[\w\|&\[\]\\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))#', $doc, $notice, \PREG_SET_ORDER)) {
245+
if ($refl->isInterface() && false !== strpos($doc, 'method') && preg_match_all('#\n \* @method\s+(static\s+)?+(?:[\w\|&\[\]\\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))#', $doc, $notice, \PREG_SET_ORDER)) {
246246
foreach ($notice as $method) {
247247
$static = '' !== $method[1];
248248
$name = $method[2];
249249
$description = $method[3] ?? null;
250-
if (!str_contains($name, '(')) {
250+
if (false === strpos($name, '(')) {
251251
$name .= '()';
252252
}
253253
if (null !== $description) {
@@ -369,14 +369,14 @@ public function checkAnnotations(\ReflectionClass $refl, $class)
369369
$finalOrInternal = false;
370370

371371
foreach (['final', 'internal'] as $annotation) {
372-
if (str_contains($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
372+
if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
373373
$message = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
374374
self::${$annotation.'Methods'}[$class][$method->name] = [$class, $message];
375375
$finalOrInternal = true;
376376
}
377377
}
378378

379-
if ($finalOrInternal || $method->isConstructor() || !str_contains($doc, '@param') || StatelessInvocation::class === $class) {
379+
if ($finalOrInternal || $method->isConstructor() || false === strpos($doc, '@param') || StatelessInvocation::class === $class) {
380380
continue;
381381
}
382382
if (!preg_match_all('#\n\s+\* @param +((?(?!callable *\().*?|callable *\(.*\).*?))(?<= )\$([a-zA-Z0-9_\x7f-\xff]++)#', $doc, $matches, \PREG_SET_ORDER)) {

ErrorHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private function reRegister(int $prev)
385385
*/
386386
public function handleError($type, $message, $file, $line)
387387
{
388-
if (\PHP_VERSION_ID >= 70300 && \E_WARNING === $type && '"' === $message[0] && str_contains($message, '" targeting switch is equivalent to "break')) {
388+
if (\PHP_VERSION_ID >= 70300 && \E_WARNING === $type && '"' === $message[0] && false !== strpos($message, '" targeting switch is equivalent to "break')) {
389389
$type = \E_DEPRECATED;
390390
}
391391

@@ -403,7 +403,7 @@ public function handleError($type, $message, $file, $line)
403403
}
404404
$scope = $this->scopedErrors & $type;
405405

406-
if (str_contains($message, "@anonymous\0")) {
406+
if (false !== strpos($message, "@anonymous\0")) {
407407
$logMessage = $this->levels[$type].': '.(new FlattenException())->setMessage($message)->getMessage();
408408
} else {
409409
$logMessage = $this->levels[$type].': '.$message;
@@ -530,7 +530,7 @@ public function handleException($exception, array $error = null)
530530
$handlerException = null;
531531

532532
if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
533-
if (str_contains($message = $exception->getMessage(), "@anonymous\0")) {
533+
if (false !== strpos($message = $exception->getMessage(), "@anonymous\0")) {
534534
$message = (new FlattenException())->setMessage($message)->getMessage();
535535
}
536536
if ($exception instanceof FatalErrorException) {
@@ -638,7 +638,7 @@ public static function handleFatalError(array $error = null)
638638
$handler->throwAt(0, true);
639639
$trace = $error['backtrace'] ?? null;
640640

641-
if (str_starts_with($error['message'], 'Allowed memory') || str_starts_with($error['message'], 'Out of memory')) {
641+
if (0 === strpos($error['message'], 'Allowed memory') || 0 === strpos($error['message'], 'Out of memory')) {
642642
$exception = new OutOfMemoryException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, false, $trace);
643643
} else {
644644
$exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);

Exception/FatalThrowableError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FatalThrowableError extends FatalErrorException
2626

2727
public function __construct(\Throwable $e)
2828
{
29-
$this->originalClassName = get_debug_type($e);
29+
$this->originalClassName = \get_class($e);
3030

3131
if ($e instanceof \ParseError) {
3232
$severity = \E_PARSE;

Exception/FlattenException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
6767
$e->setStatusCode($statusCode);
6868
$e->setHeaders($headers);
6969
$e->setTraceFromThrowable($exception);
70-
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : get_debug_type($exception));
70+
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
7171
$e->setFile($exception->getFile());
7272
$e->setLine($exception->getLine());
7373

@@ -134,7 +134,7 @@ public function getClass()
134134
*/
135135
public function setClass($class)
136136
{
137-
$this->class = str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
137+
$this->class = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
138138

139139
return $this;
140140
}
@@ -179,7 +179,7 @@ public function getMessage()
179179
*/
180180
public function setMessage($message)
181181
{
182-
if (str_contains($message, "@anonymous\0")) {
182+
if (false !== strpos($message, "@anonymous\0")) {
183183
$message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
184184
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
185185
}, $message);

ExceptionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private function formatPath(string $path, int $line): string
401401
$fmt = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
402402

403403
for ($i = 1; isset($fmt[$i]); ++$i) {
404-
if (str_starts_with($path, $k = $fmt[$i++])) {
404+
if (0 === strpos($path, $k = $fmt[$i++])) {
405405
$path = substr_replace($path, $fmt[$i], 0, \strlen($k));
406406
break;
407407
}

FatalErrorHandler/ClassNotFoundFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private function convertFileToClass(string $path, string $file, string $prefix):
149149
];
150150

151151
if ($prefix) {
152-
$candidates = array_filter($candidates, function ($candidate) use ($prefix) { return str_starts_with($candidate, $prefix); });
152+
$candidates = array_filter($candidates, function ($candidate) use ($prefix) { return 0 === strpos($candidate, $prefix); });
153153
}
154154

155155
// We cannot use the autoloader here as most of them use require; but if the class

FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function handleError(array $error, FatalErrorException $exception)
4343

4444
$prefix = 'Call to undefined function ';
4545
$prefixLen = \strlen($prefix);
46-
if (!str_starts_with($error['message'], $prefix)) {
46+
if (0 !== strpos($error['message'], $prefix)) {
4747
return null;
4848
}
4949

FatalErrorHandler/UndefinedMethodFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function handleError(array $error, FatalErrorException $exception)
4848
$candidates = [];
4949
foreach ($methods as $definedMethodName) {
5050
$lev = levenshtein($methodName, $definedMethodName);
51-
if ($lev <= \strlen($methodName) / 3 || str_contains($definedMethodName, $methodName)) {
51+
if ($lev <= \strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) {
5252
$candidates[] = $definedMethodName;
5353
}
5454
}

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20-
"psr/log": "^1|^2|^3",
21-
"symfony/polyfill-php80": "^1.16"
20+
"psr/log": "^1|^2|^3"
2221
},
2322
"conflict": {
2423
"symfony/http-kernel": "<3.4"

0 commit comments

Comments
 (0)