Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0071bcd

Browse filesBrowse files
[ErrorHandler] Do not use the php80 polyfill in DebugClassLoader
1 parent 855232f commit 0071bcd
Copy full SHA for 0071bcd

File tree

1 file changed

+18
-17
lines changed
Filter options

1 file changed

+18
-17
lines changed

‎src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorHandler/DebugClassLoader.php
+18-17Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ private function checkClass(string $class, string $file = null): void
396396
}
397397

398398
if (!$exists) {
399-
if (str_contains($class, '/')) {
399+
// Because this file is loading classes, it cannot use any polyfill
400+
if (false !== strpos($class, '/')) {
400401
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));
401402
}
402403

@@ -419,7 +420,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
419420
}
420421
$deprecations = [];
421422

422-
$className = str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
423+
$className = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
423424

424425
// Don't trigger deprecations for classes in the same vendor
425426
if ($class !== $className) {
@@ -435,17 +436,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
435436
// Detect annotations on the class
436437
if (false !== $doc = $refl->getDocComment()) {
437438
foreach (['final', 'deprecated', 'internal'] as $annotation) {
438-
if (str_contains($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
439+
if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
439440
self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
440441
}
441442
}
442443

443-
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)) {
444+
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)) {
444445
foreach ($notice as $method) {
445446
$static = '' !== $method[1] && !empty($method[2]);
446447
$name = $method[3];
447448
$description = $method[4] ?? null;
448-
if (!str_contains($name, '(')) {
449+
if (false === strpos($name, '(')) {
449450
$name .= '()';
450451
}
451452
if (null !== $description) {
@@ -496,7 +497,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
496497
}
497498
} elseif (!$refl->isInterface()) {
498499
if (!strncmp($vendor, str_replace('_', '\\', $use), $vendorLen)
499-
&& str_starts_with($className, 'Symfony\\')
500+
&& 0 === strpos($className, 'Symfony\\')
500501
&& (!class_exists(InstalledVersions::class)
501502
|| 'symfony/symfony' !== InstalledVersions::getRootPackage()['name'])
502503
) {
@@ -597,12 +598,12 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
597598

598599
$forcePatchTypes = $this->patchTypes['force'];
599600

600-
if ($canAddReturnType = null !== $forcePatchTypes && !str_contains($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
601+
if ($canAddReturnType = null !== $forcePatchTypes && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
601602
if ('void' !== (self::MAGIC_METHODS[$method->name] ?? 'void')) {
602603
$this->patchTypes['force'] = $forcePatchTypes ?: 'docblock';
603604
}
604605

605-
$canAddReturnType = str_contains($refl->getFileName(), \DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR)
606+
$canAddReturnType = false !== strpos($refl->getFileName(), \DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR)
606607
|| $refl->isFinal()
607608
|| $method->isFinal()
608609
|| $method->isPrivate()
@@ -623,8 +624,8 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
623624
$this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
624625
}
625626

626-
if (!str_contains($doc, '* @deprecated') && strncmp($ns, $declaringClass, $len)) {
627-
if ($canAddReturnType && 'docblock' === $this->patchTypes['force'] && !str_contains($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
627+
if (false === strpos($doc, '* @deprecated') && strncmp($ns, $declaringClass, $len)) {
628+
if ($canAddReturnType && 'docblock' === $this->patchTypes['force'] && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
628629
$this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
629630
} elseif ('' !== $declaringClass && $this->patchTypes['deprecations']) {
630631
$deprecations[] = sprintf('Method "%s::%s()" will return "%s" as of its next major version. Doing the same in %s "%s" will be required when upgrading.', $declaringClass, $method->name, $normalizedType, interface_exists($declaringClass) ? 'implementation' : 'child class', $className);
@@ -640,7 +641,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
640641

641642
$matches = [];
642643

643-
if (!$method->hasReturnType() && ((str_contains($doc, '@return') && preg_match('/\n\s+\* @return +([^\s<(]+)/', $doc, $matches)) || 'void' !== (self::MAGIC_METHODS[$method->name] ?? 'void'))) {
644+
if (!$method->hasReturnType() && ((false !== strpos($doc, '@return') && preg_match('/\n\s+\* @return +([^\s<(]+)/', $doc, $matches)) || 'void' !== (self::MAGIC_METHODS[$method->name] ?? 'void'))) {
644645
$matches = $matches ?: [1 => self::MAGIC_METHODS[$method->name]];
645646
$this->setReturnType($matches[1], $method, $parent);
646647

@@ -662,14 +663,14 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
662663
$finalOrInternal = false;
663664

664665
foreach (['final', 'internal'] as $annotation) {
665-
if (str_contains($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
666+
if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
666667
$message = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
667668
self::${$annotation.'Methods'}[$class][$method->name] = [$class, $message];
668669
$finalOrInternal = true;
669670
}
670671
}
671672

672-
if ($finalOrInternal || $method->isConstructor() || !str_contains($doc, '@param') || StatelessInvocation::class === $class) {
673+
if ($finalOrInternal || $method->isConstructor() || false === strpos($doc, '@param') || StatelessInvocation::class === $class) {
673674
continue;
674675
}
675676
if (!preg_match_all('#\n\s+\* @param +((?(?!callable *\().*?|callable *\(.*\).*?))(?<= )\$([a-zA-Z0-9_\x7f-\xff]++)#', $doc, $matches, \PREG_SET_ORDER)) {
@@ -850,7 +851,7 @@ private function setReturnType(string $types, \ReflectionMethod $method, ?string
850851
$iterable = $object = true;
851852
foreach ($typesMap as $n => $t) {
852853
if ('null' !== $n) {
853-
$iterable = $iterable && (\in_array($n, ['array', 'iterable']) || str_contains($n, 'Iterator'));
854+
$iterable = $iterable && (\in_array($n, ['array', 'iterable']) || false !== strpos($n, 'Iterator'));
854855
$object = $object && (\in_array($n, ['callable', 'object', '$this', 'static']) || !isset(self::SPECIAL_RETURN_TYPES[$n]));
855856
}
856857
}
@@ -1034,15 +1035,15 @@ private static function getUseStatements(string $file): array
10341035
break;
10351036
}
10361037

1037-
if (str_starts_with($file[$i], 'namespace ')) {
1038+
if (0 === strpos($file[$i], 'namespace ')) {
10381039
$namespace = substr($file[$i], \strlen('namespace '), -2).'\\';
10391040
$useOffset = $i + 2;
10401041
}
10411042

1042-
if (str_starts_with($file[$i], 'use ')) {
1043+
if (0 === strpos($file[$i], 'use ')) {
10431044
$useOffset = $i;
10441045

1045-
for (; str_starts_with($file[$i], 'use '); ++$i) {
1046+
for (; 0 === strpos($file[$i], 'use '); ++$i) {
10461047
$u = explode(' as ', substr($file[$i], 4, -2), 2);
10471048

10481049
if (1 === \count($u)) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.