8000 Partially revert "DX: PHP CS Fixer - update excluded paths and apply some minor CS" by nicolas-grekas · Pull Request #52202 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Partially revert "DX: PHP CS Fixer - update excluded paths and apply some minor CS" #52202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
28 changes: 14 additions & 14 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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'];

Expand All @@ -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\\');
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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')) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bridge/PhpUnit/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
0