diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 668d14f77860b..48c4f276b34a5 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -38,7 +38,6 @@ 'modernize_strpos' => true, 'get_class_to_class_keyword' => true, 'nullable_type_declaration' => true, - // 'get_class_to_class_keyword' => true, // to be enabled when Bridge/PhpUnit will require PHP 8+ ]) ->setRiskyAllowed(true) ->setFinder( diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index ce13966262b77..f3a78b97f45d0 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -96,7 +96,7 @@ public static function collectDeprecations($outputFile) { $deprecations = []; $previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) { - if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) { + if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) { if ($previousErrorHandler) { return $previousErrorHandler($type, $msg, $file, $line, $context); } @@ -128,7 +128,7 @@ public static function collectDeprecations($outputFile) */ public function handleError($type, $msg, $file, $line, $context = []) { - if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || !str_contains($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) { + if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) { return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php index 64b48c906294d..79cfa0cc9fe85 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php @@ -104,7 +104,7 @@ public function __construct($message, array $trace, $file, $languageDeprecation $this->getOriginalFilesStack(); array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]); - if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "(?:static )?([^:]++))/', $message, $m) || (!str_contains($message, '()" will return') && !str_contains($message, 'native return type declaration') && preg_match('/^(?:The|Method) "([^":]++)/', $message, $m))) { + if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "(?:static )?([^:]++))/', $message, $m) || (false === strpos($message, '()" will return') && false === strpos($message, 'native return type declaration') && preg_match('/^(?:The|Method) "([^":]++)/', $message, $m))) { $this->triggeringFile = (new \ReflectionClass($m[1]))->getFileName(); array_unshift($this->originalFilesStack, $this->triggeringFile); } @@ -142,7 +142,7 @@ public function __construct($message, array $trace, $file, $languageDeprecation return; } - if (!isset($line['class'], $trace[$i - 2]['function']) || !str_starts_with($line['class'], SymfonyTestsListenerFor::class)) { + if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) { $this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class']; $this->originMethod = $line['function']; @@ -169,7 +169,7 @@ private function lineShouldBeSkipped(array $line) } $class = $line['class']; - return 'ReflectionMethod' === $class || str_starts_with($class, 'PHPUnit\\'); + return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\'); } /** @@ -211,7 +211,7 @@ public function originatingClass() $class = $this->originClass; - return str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class; + return false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class; } /** @@ -246,9 +246,9 @@ public function isLegacy() $method = $this->originatingMethod(); $groups = class_exists(Groups::class, false) ? [new Groups(), 'groups'] : [Test::class, 'getGroups']; - return str_starts_with($method, 'testLegacy') - || str_starts_with($method, 'provideLegacy') - || str_starts_with($method, 'getLegacy') + return 0 === strpos($method, 'testLegacy') + || 0 === strpos($method, 'provideLegacy') + || 0 === strpos($method, 'getLegacy') || strpos($this->originClass, '\Legacy') || \in_array('legacy', $groups($this->originClass, $method), true); } @@ -262,10 +262,10 @@ public function isMuted() return false; } if (isset($this->trace[1]['class'])) { - return str_starts_with($this->trace[1]['class'], 'PHPUnit\\'); + return 0 === strpos($this->trace[1]['class'], 'PHPUnit\\'); } - return str_contains($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR); + return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR); } /** @@ -340,7 +340,7 @@ private function getPackage($path) { $path = realpath($path) ?: $path; foreach (self::getVendors() as $vendorRoot) { - if (str_starts_with($path, $vendorRoot)) { + if (0 === strpos($path, $vendorRoot)) { $relativePath = substr($path, \strlen($vendorRoot) + 1); $vendor = strstr($relativePath, \DIRECTORY_SEPARATOR, true); if (false === $vendor) { @@ -366,7 +366,7 @@ private static function getVendors() self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName()); } foreach (get_declared_classes() as $class) { - if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) { + if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { $r = new \ReflectionClass($class); $v = \dirname($r->getFileName(), 2); if (file_exists($v.'/composer/installed.json')) { @@ -381,7 +381,7 @@ private static function getVendors() } foreach ($paths as $path) { foreach (self::$vendors as $vendor) { - if (!str_starts_with($path, $vendor)) { + if (0 !== strpos($path, $vendor)) { self::$internalPaths[] = $path; } } @@ -416,13 +416,13 @@ private function getPathType($path) return self::PATH_TYPE_UNDETERMINED; } foreach (self::getVendors() as $vendor) { - if (str_starts_with($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { + if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { return self::PATH_TYPE_VENDOR; } } foreach (self::$internalPaths as $internalPath) { - if (str_starts_with($realPath, $internalPath)) { + if (0 === strpos($realPath, $internalPath)) { return self::PATH_TYPE_SELF; } } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php b/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php index 769fc1b780f7f..19408df6d2dfe 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php @@ -43,7 +43,7 @@ public function test() exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text --colors=never 2> /dev/null", $output); $output = implode("\n", $output); - if (!str_contains($output, 'FooCov')) { + if (false === strpos($output, 'FooCov')) { $this->addToAssertionCount(1); } else { $this->assertMatchesRegularExpression('/FooCov\n\s*Methods:\s+0.00%[^\n]+Lines:\s+0.00%/', $output); diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php index ed7a9848e01da..f928c87139fe6 100644 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php @@ -57,7 +57,7 @@ break; } // short option - if (str_starts_with($cliArgument, '-c')) { + if (0 === strpos($cliArgument, '-c')) { if ('-c' === $cliArgument && array_key_exists($cliArgumentIndex + 1, $argv)) { $phpunitConfigFilename = $getPhpUnitConfig($argv[$cliArgumentIndex + 1]); } else { diff --git a/src/Symfony/Bridge/PhpUnit/composer.json b/src/Symfony/Bridge/PhpUnit/composer.json index f37bf1e232b14..6c92a3ce5af73 100644 --- a/src/Symfony/Bridge/PhpUnit/composer.json +++ b/src/Symfony/Bridge/PhpUnit/composer.json @@ -23,7 +23,6 @@ "require-dev": { "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/error-handler": "^5.4|^6.0|^7.0", - "symfony/polyfill-php80": "^1.27", "symfony/polyfill-php81": "^1.27" }, "conflict": {