8000 Merge branch '5.3' into 5.4 · symfony/symfony@4c11c62 · GitHub 10000
[go: up one dir, main page]

Skip to content

Commit 4c11c62

Browse files
Merge branch '5.3' into 5.4
* 5.3: [ErrorHandler][Debug] Do not use the php80 polyfill #42229 update phpdoc to recommend createIndex over ensureIndex
2 parents 43fcd97 + e9d59b3 commit 4c11c62

File tree

12 files changed

+37
-39
lines changed
  • ErrorEnhancer
  • ErrorRenderer
  • Exception
  • HttpFoundation/Session/Storage/Handler
  • Mailer/Bridge/Mailjet
  • 12 files changed

    +37
    -39
    lines changed

    src/Symfony/Component/ErrorHandler/BufferingLogger.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -48,7 +48,7 @@ public function __wakeup()
    4848
    public function __destruct()
    4949
    {
    5050
    foreach ($this->logs as [$level, $message, $context]) {
    51-
    if (str_contains($message, '{')) {
    51+
    if (false !== strpos($message, '{')) {
    5252
    foreach ($context as $key => $val) {
    5353
    if (null === $val || is_scalar($val) || (\is_object($val) && \is_callable([$val, '__toString']))) {
    5454
    $message = str_replace("{{$key}}", $val, $message);

    src/Symfony/Component/ErrorHandler/DebugClassLoader.php

    Lines changed: 18 additions & 18 deletions
    Original file line numberDiff line numberDiff line change
    @@ -205,7 +205,7 @@ public function __construct(callable $classLoader)
    205205
    if (false === $test || false === $i) {
    206206
    // filesystem is case sensitive
    207207
    self::$caseCheck = 0;
    208-
    } elseif (str_ends_with($test, $file)) {
    208+
    } elseif (substr($test, -\strlen($file)) === $file) {
    209209
    // filesystem is case insensitive and realpath() normalizes the case of characters
    210210
    self::$caseCheck = 1;
    211211
    } elseif ('Darwin' === \PHP_OS_FAMILY) {
    @@ -396,7 +396,7 @@ private function checkClass(string $class, string $file = null): void
    396396
    }
    397397

    398398
    if (!$exists) {
    399-
    if (str_contains($class, '/')) {
    399+
    if (false !== strpos($class, '/')) {
    400400
    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));
    401401
    }
    402402

    @@ -418,7 +418,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    418418
    }
    419419
    $deprecations = [];
    420420

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

    423423
    // Don't trigger deprecations for classes in the same vendor
    424424
    if ($class !== $className) {
    @@ -434,17 +434,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    434434
    // Detect annotations on the class
    435435
    if (false !== $doc = $refl->getDocComment()) {
    436436
    foreach (['final', 'deprecated', 'internal'] as $annotation) {
    437-
    if (str_contains($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
    437+
    if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
    438438
    self::${$annotation}[$class] = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
    439439
    }
    440440
    }
    441441

    442-
    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)) {
    442+
    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)) {
    443443
    foreach ($notice as $method) {
    444444
    $static = '' !== $method[1] && !empty($method[2]);
    445445
    $name = $method[3];
    446446
    $description = $method[4] ?? null;
    447-
    if (!str_contains($name, '(')) {
    447+
    if (false === strpos($name, '(')) {
    448448
    $name .= '()';
    449449
    }
    450450
    if (null !== $description) {
    @@ -495,7 +495,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    495495
    }
    496496
    } elseif (!$refl->isInterface()) {
    497497
    if (!strncmp($vendor, str_replace('_', '\\', $use), $vendorLen)
    498-
    && str_starts_with($className, 'Symfony\\')
    498+
    && 0 === strpos($className, 'Symfony\\')
    499499
    && (!class_exists(InstalledVersions::class)
    500500
    || 'symfony/symfony' !== InstalledVersions::getRootPackage()['name'])
    501501
    ) {
    @@ -596,12 +596,12 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    596596

    597597
    $forcePatchTypes = $this->patchTypes['force'];
    598598

    599-
    if ($canAddReturnType = null !== $forcePatchTypes && !str_contains($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
    599+
    if ($canAddReturnType = null !== $forcePatchTypes && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
    600600
    if ('void' !== (self::MAGIC_METHODS[$method->name] ?? 'void')) {
    601601
    $this->patchTypes['force'] = $forcePatchTypes ?: 'docblock';
    602602
    }
    603603

    604-
    $canAddReturnType = str_contains($refl->getFileName(), \DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR)
    604+
    $canAddReturnType = false !== strpos($refl->getFileName(), \DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR)
    605605
    || $refl->isFinal()
    606606
    || $method->isFinal()
    607607
    || $method->isPrivate()
    @@ -622,8 +622,8 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    622622
    $this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
    623623
    }
    624624

    625-
    if (!str_contains($doc, '* @deprecated') && strncmp($ns, $declaringClass, $len)) {
    626-
    if ($canAddReturnType && 'docblock' === $this->patchTypes['force'] && !str_contains($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
    625+
    if (false === strpos($doc, '* @deprecated') && strncmp($ns, $declaringClass, $len)) {
    626+
    if ($canAddReturnType && 'docblock' === $this->patchTypes['force'] && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
    627627
    $this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
    628628
    } elseif ('' !== $declaringClass && $this->patchTypes['deprecations']) {
    629629
    $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);
    @@ -639,7 +639,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    639639

    640640
    $matches = [];
    641641

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

    @@ -661,14 +661,14 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
    661661
    $finalOrInternal = false;
    662662

    663663
    foreach (['final', 'internal'] as $annotation) {
    664-
    if (str_contains($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
    664+
    if (false !== strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s', $doc, $notice)) {
    665665
    $message = isset($notice[1]) ? preg_replace('#\.?\r?\n( \*)? *(?= |\r?\n|$)#', '', $notice[1]) : '';
    666666
    self::${$annotation.'Methods'}[$class][$method->name] = [$class, $message];
    667667
    $finalOrInternal = true;
    668668
    }
    669669
    }
    670670

    671-
    if ($finalOrInternal || $method->isConstructor() || !str_contains($doc, '@param') || StatelessInvocation::class === $class) {
    671+
    if ($finalOrInternal || $method->isConstructor() || false === strpos($doc, '@param') || StatelessInvocation::class === $class) {
    672672
    continue;
    673673
    }
    674674
    if (!preg_match_all('#\n\s+\* @param +((?(?!callable *\().*?|callable *\(.*\).*?))(?<= )\$([a-zA-Z0-9_\x7f-\xff]++)#', $doc, $matches, \PREG_SET_ORDER)) {
    @@ -849,7 +849,7 @@ private function setReturnType(string $types, \ReflectionMethod $method, ?string
    849849
    $iterable = $object = true;
    850850
    foreach ($typesMap as $n => $t) {
    851851
    if ('null' !== $n) {
    852-
    $iterable = $iterable && (\in_array($n, ['array', 'iterable']) || str_contains($n, 'Iterator'));
    852+
    $iterable = $iterable && (\in_array($n, ['array', 'iterable']) || false !== strpos($n, 'Iterator'));
    853853
    $object = $object && (\in_array($n, ['callable', 'object', '$this', 'static']) || !isset(self::SPECIAL_RETURN_TYPES[$n]));
    854854
    }
    855855
    }
    @@ -1033,15 +1033,15 @@ private static function getUseStatements(string $file): array
    10331033
    break;
    10341034
    }
    10351035

    1036-
    if (str_starts_with($file[$i], 'namespace ')) {
    1036+
    if (0 === strpos($file[$i], 'namespace ')) {
    10371037
    $namespace = substr($file[$i], \strlen('namespace '), -2).'\\';
    10381038
    $useOffset = $i + 2;
    10391039
    }
    10401040

    1041-
    if (str_starts_with($file[$i], 'use ')) {
    1041+
    if (0 === strpos($file[$i], 'use ')) {
    10421042
    $useOffset = $i;
    10431043

    1044-
    for (; str_starts_with($file[$i], 'use '); ++$i) {
    1044+
    for (; 0 === strpos($file[$i], 'use '); ++$i) {
    10451045
    $u = explode(' as ', substr($file[$i], 4, -2), 2);
    10461046

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

    src/Symfony/Component/ErrorHandler/ErrorEnhancer/ClassNotFoundErrorEnhancer.php

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

    145145
    if ($prefix) {
    146-
    $candidates = array_filter($candidates, function ($candidate) use ($prefix) { return str_starts_with($candidate, $prefix); });
    146+
    $candidates = array_filter($candidates, function ($candidate) use ($prefix) { return 0 === strpos($candidate, $prefix); });
    147147
    }
    148148

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

    src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedFunctionErrorEnhancer.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -42,7 +42,7 @@ public function enhance(\Throwable $error): ?\Throwable
    4242

    4343
    $prefix = 'Call to undefined function ';
    4444
    $prefixLen = \strlen($prefix);
    45-
    if (!str_starts_with($message, $prefix)) {
    45+
    if (0 !== strpos($message, $prefix)) {
    4646
    return null;
    4747
    }
    4848

    src/Symfony/Component/ErrorHandler/ErrorEnhancer/UndefinedMethodErrorEnhancer.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -47,7 +47,7 @@ public function enhance(\Throwable $error): ?\Throwable
    4747
    $candidates = [];
    4848
    foreach ($methods as $definedMethodName) {
    4949
    $lev = levenshtein($methodName, $definedMethodName);
    50-
    if ($lev <= \strlen($methodName) / 3 || str_contains($definedMethodName, $methodName)) {
    50+
    if ($lev <= \strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) {
    5151
    $candidates[] = $definedMethodName;
    5252
    }
    5353
    }

    src/Symfony/Component/ErrorHandler/ErrorHandler.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -406,7 +406,7 @@ private function reRegister(int $prev): void
    406406
    */
    407407
    public function handleError(int $type, string $message, string $file, int $line): bool
    408408
    {
    409-
    if (\PHP_VERSION_ID >= 70300 && \E_WARNING === $type && '"' === $message[0] && str_contains($message, '" targeting switch is equivalent to "break')) {
    409+
    if (\PHP_VERSION_ID >= 70300 && \E_WARNING === $type && '"' === $message[0] && false !== strpos($message, '" targeting switch is equivalent to "break')) {
    410410
    $type = \E_DEPRECATED;
    411411
    }
    412412

    @@ -457,7 +457,7 @@ public function handleError(int $type, string $message, string $file, int $line)
    457457
    return true;
    458458
    }
    459459
    } else {
    460-
    if (str_contains($message, '@anonymous')) {
    460+
    if (false !== strpos($message, '@anonymous')) {
    461461
    $backtrace = debug_backtrace(false, 5);
    462462

    463463
    for ($i = 1; isset($backtrace[$i]); ++$i) {
    @@ -566,7 +566,7 @@ public function handleException(\Throwable $exception)
    566566
    }
    567567

    568568
    if ($this->loggedErrors & $type) {
    569-
    if (str_contains($message = $exception->getMessage(), "@anonymous\0")) {
    569+
    if (false !== strpos($message = $exception->getMessage(), "@anonymous\0")) {
    570570
    $message = $this->parseAnonymousClass($message);
    571571
    }
    572572

    @@ -680,7 +680,7 @@ public static function handleFatalError(array $error = null): void
    680680
    $handler->throwAt(0, true);
    681681
    $trace = $error['backtrace'] ?? null;
    682682

    683-
    if (str_starts_with($error['message'], 'Allowed memory') || str_starts_with($error['message'], 'Out of memory')) {
    683+
    if (0 === strpos($error['message'], 'Allowed memory') || 0 === strpos($error['message'], 'Out of memory')) {
    684684
    $fatalError = new OutOfMemoryError($handler->levels[$error['type']].': '.$error['message'], 0, $error, 2, false, $trace);
    685685
    } else {
    686686
    $fatalError = new FatalError($handler->levels[$error['type']].': '.$error['message'], 0, $error, 2, true, $trace);

    src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -50,11 +50,11 @@ class HtmlErrorRenderer implements ErrorRendererInterface
    5050
    public function __construct($debug = false, string $charset = null, $fileLinkFormat = null, string $projectDir = null, $outputBuffer = '', LoggerInterface $logger = null)
    5151
    {
    5252
    if (!\is_bool($debug) && !\is_callable($debug)) {
    53-
    throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
    53+
    throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
    5454
    }
    5555

    5656
    if (!\is_string($outputBuffer) && !\is_callable($outputBuffer)) {
    57-
    throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, get_debug_type($outputBuffer)));
    57+
    throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \gettype($outputBuffer)));
    5858
    }
    5959

    6060
    $this->debug = $debug;
    @@ -205,7 +205,7 @@ private function getFileRelative(string $file): ?string
    205205
    {
    206206
    $file = str_replace('\\', '/', $file);
    207207

    208-
    if (null !== $this->projectDir && str_starts_with($file, $this->projectDir)) {
    208+
    if (null !== $this->projectDir && 0 === strpos($file, $this->projectDir)) {
    209209
    return ltrim(substr($file, \strlen($this->projectDir)), '/');
    210210
    }
    211211

    @@ -322,7 +322,7 @@ private function formatFileFromText(string $text)
    322322

    323323
    private function formatLogMessage(string $message, array $context)
    324324
    {
    325-
    if ($context && str_contains($message, '{')) {
    325+
    if ($context && false !== strpos($message, '{')) {
    326326
    $replacements = [];
    327327
    foreach ($context as $key => $val) {
    328328
    if (is_scalar($val)) {

    src/Symfony/Component/ErrorHandler/ErrorRenderer/SerializerErrorRenderer.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -37,11 +37,11 @@ class SerializerErrorRenderer implements ErrorRendererInterface
    3737
    public function __construct(SerializerInterface $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
    3838
    {
    3939
    if (!\is_string($format) && !\is_callable($format)) {
    40-
    throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, get_debug_type($format)));
    40+
    throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \gettype($format)));
    4141
    }
    4242

    4343
    if (!\is_bool($debug) && !\is_callable($debug)) {
    44-
    throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
    44+
    throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, \gettype($debug)));
    4545
    }
    4646

    4747
    $this->serializer = $serializer;

    src/Symfony/Component/ErrorHandler/Exception/FlattenException.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -98,7 +98,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
    9898
    $e->setStatusCode($statusCode);
    9999
    $e->setHeaders($headers);
    100100
    $e->setTraceFromThrowable($exception);
    101-
    $e->setClass(get_debug_type($exception));
    101+
    $e->setClass(\get_class($exception));
    102102
    $e->setFile($exception->getFile());
    103103
    $e->setLine($exception->getLine());
    104104

    @@ -165,7 +165,7 @@ public function getClass(): string
    165165
    */
    166166
    public function setClass(string $class): self
    167167
    {
    168-
    $this->class = str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
    168+
    $this->class = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
    169169

    170170
    return $this;
    171171
    }
    @@ -222,7 +222,7 @@ public function getMessage(): string
    222222
    */
    223223
    public function setMessage(string $message): self
    224224
    {
    225-
    if (str_contains($message, "@anonymous\0")) {
    225+
    if (false !== strpos($message, "@anonymous\0")) {
    226226
    $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) {
    227227
    return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
    228228
    }, $message);

    src/Symfony/Component/ErrorHandler/composer.json

    Lines changed: 0 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,6 @@
    1818
    "require": {
    1919
    "php": ">=7.2.5",
    2020
    "psr/log": "^1|^2|^3",
    21-
    "symfony/polyfill-php80": "^1.16",
    2221
    "symfony/var-dumper": "^4.4|^5.0|^6.0"
    2322
    },
    2423
    "require-dev": {

    0 commit comments

    Comments
     (0)
    0