8000 [6.0] Update php8 string function by shuvroroy · Pull Request #42209 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[6.0] Update php8 string function #42209

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

Closed
wants to merge 1 commit into from
Closed
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
Update php8 string function
  • Loading branch information
shuvroroy committed Jul 21, 2021
commit 7daf2018b0532adc94c1d6b96e62ab87a21f5168
48 changes: 24 additions & 24 deletions .github/patch-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@

foreach ($loader->getClassMap() as $class => $file) {
switch (true) {
case false !== strpos($file = realpath($file), '/vendor/'):
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'):
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/ParseError.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/intersectiontype_classes.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/MultipleArgumentsOptionalScalarNotReallyOptional.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/IntersectionConstructor.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ParentNotExists.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Preload/'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php'):
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/'):
case false !== strpos($file, '/src/Symfony/Component/ErrorHandler/Tests/Fixtures/'):
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php'):
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php'):
case false !== strpos($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/TraitUsage/DummyUsingTrait.php'):
case false !== strpos($file, '/src/Symfony/Component/Runtime/Internal/ComposerPlugin.php'):
case false !== strpos($file, '/src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectOuter.php'):
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionIntersectionTypeFixture.php'):
case str_contains($file = realpath($file), '/vendor/'):
case str_contains($file, '/src/Symfony/Bridge/PhpUnit/'):
case str_contains($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
case str_contains($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):
case str_contains($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'):
case str_contains($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'):
case str_contains($file, '/src/Symfony/Component/Config/Tests/Fixtures/ParseError.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/intersectiontype_classes.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/MultipleArgumentsOptionalScalarNotReallyOptional.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/IntersectionConstructor.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ParentNotExists.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Preload/'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/BadClasses/MissingParent.php'):
case str_contains($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/'):
case str_contains($file, '/src/Symfony/Component/ErrorHandler/Tests/Fixtures/'):
case str_contains($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php'):
case str_contains($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/ParentDummy.php'):
case str_contains($file, '/src/Symfony/Component/PropertyInfo/Tests/Fixtures/TraitUsage/DummyUsingTrait.php'):
case str_contains($file, '/src/Symfony/Component/Runtime/Internal/ComposerPlugin.php'):
case str_contains($file, '/src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectOuter.php'):
case str_contains($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
case str_contains($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionIntersectionTypeFixture.php'):
continue 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected function registerMappingDrivers(array $objectManager, ContainerBuilder
]);
}
$mappingDriverDef->setPublic(false);
if (false !== strpos($mappingDriverDef->getClass(), 'yml') || false !== strpos($mappingDriverDef->getClass(), 'xml')) {
if (str_contains($mappingDriverDef->getClass(), 'yml') || str_contains($mappingDriverDef->getClass(), 'xml')) {
$mappingDriverDef->setArguments([array_flip($driverPaths)]);
$mappingDriverDef->addMethodCall('setGlobalBasename', ['mapping']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function getClass(): string
if (null === $this->class) {
$class = $this->classOrAlias;

if (false !== strpos($class, ':')) {
if (str_contains($class, ':')) {
$class = $this->getClassMetadata()->getName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function __construct($message, array $trace, $file)
return;
}

if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) {
if (!isset($line['class'], $trace[$i - 2]['function']) || str_contains($line['class'], SymfonyTestsListenerFor::class)) {
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
$this->originMethod = $line['function'];

Expand Down Expand Up @@ -171,7 +171,7 @@ public function originatingClass()

$class = $this->originClass;

return false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
return str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
}

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ public function isMuted()
return 0 === strpos($this->trace[1]['class'], 'PHPUnit\\');
}

return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR);
return str_contains($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR);
}

/**
Expand Down Expand Up @@ -339,7 +339,7 @@ private static function getVendors()
}
foreach ($paths as $path) {
foreach (self::$vendors as $vendor) {
if (0 !== strpos($path, $vendor)) {
if (str_contains($path, $vendor)) {
self::$internalPaths[] = $path;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function loadClass($className)
public function findFile($class)
{
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
if (0 !== strpos($class, $prefix)) {
if (str_contains($class, $prefix)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getPrefixesPsr4()
public function loadClass($className)
{
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
if (0 !== strpos($className, $prefix)) {
if (str_contains($className, $prefix)) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private function displayGeneralText(SymfonyStyle $io, string $filter = null)
foreach ($types as $index => $type) {
$items = [];
foreach ($this->twig->{'get'.ucfirst($type)}() as $name => $entity) {
if (!$filter || false !== strpos($name, $filter)) {
if (!$filter || str_contains($name, $filter)) {
$items[$name] = $name.$this->getPrettyMetadata($type, $entity, $decorated);
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ private function displayGeneralJson(SymfonyStyle $io, ?string $filter)
$data = [];
foreach ($types as $type) {
foreach ($this->twig->{'get'.ucfirst($type)}() as $name => $entity) {
if (!$filter || false !== strpos($name, $filter)) {
if (!$filter || str_contains($name, $filter)) {
$data[$type][$name] = $this->getMetadata($type, $entity);
}
}
Expand Down Expand Up @@ -526,7 +526,7 @@ private function findAlternatives(string $name, array $collection): array
$alternatives = [];
foreach ($collection as $item) {
$lev = levenshtein($name, $item);
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function abbrClass(string $class): string

public function abbrMethod(string $method): string
{
if (false !== strpos($method, '::')) {
if (str_contains($method, '::')) {
[$class, $method] = explode('::', $method, 2);
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
} elseif ('Closure' === $method) {
Expand Down Expand Up @@ -206,7 +206,7 @@ public function formatFileFromText(string $text): string
*/
public function formatLogMessage(string $message, array $context): string
{
if ($context && false !== strpos($message, '{')) {
if ($context && str_contains($message, '{')) {
$replacements = [];
foreach ($context as $key => $val) {
if (is_scalar($val)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function filterToServiceTypes(string $serviceId): bool
}

// if the id has a \, assume it is a class
if (false !== strpos($serviceId, '\\')) {
if (str_contains($serviceId, '\\')) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($search = $input->getArgument('search')) {
$searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', '', $search);
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) {
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && 0 !== strpos($serviceId, '.');
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && str_contains($serviceId, '.');
});

if (empty($serviceIds)) {
Expand All @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($serviceIds as $serviceId) {
$text = [];
$resolvedServiceId = $serviceId;
if (0 !== strpos($serviceId, $previousId)) {
if (str_contains($serviceId, $previousId)) {
$text[] = '';
if ('' !== $description = Descriptor::getClassDescription($serviceId, $resolvedServiceId)) {
if (isset($hasAlias[$serviceId])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private function getCallableData(mixed $callable): array
$data['name'] = $callable[1];
$data['class'] = \get_class($callable[0]);
} else {
if (0 !== strpos($callable[1], 'parent::')) {
if (str_contains($callable[1], 'parent::')) {
$data['name'] = $callable[1];
$data['class'] = $callable[0];
$data['static'] = true;
Expand Down Expand Up @@ -348,7 +348,7 @@ private function getCallableData(mixed $callable): array
$data['type'] = 'closure';

$r = new \ReflectionFunction($callable);
if (false !== strpos($r->name, '{closure}')) {
if (str_contains($r->name, '{closure}')) {
return $data;
}
$data['name'] = $r->name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ protected function describeCallable(mixed $callable, array $options = [])
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
$string .= "\n".sprintf('- Class: `%s`', \get_class($callable[0]));
} else {
if (0 !== strpos($callable[1], 'parent::')) {
if (str_contains($callable[1], 'parent::')) {
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
$string .= "\n".sprintf('- Class: `%s`', $callable[0]);
$string .= "\n- Static: yes";
Expand Down Expand Up @@ -372,7 +372,7 @@ protected function describeCallable(mixed $callable, array $options = [])
$string .= "\n- Type: `closure`";

$r = new \ReflectionFunction($callable);
if (false !== strpos($r->name, '{closure}')) {
if (str_contains($r->name, '{closure}')) {
return $this->write($string."\n");
}
$string .= "\n".sprintf('- Name: `%s`', $r->name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ private function formatControllerLink(mixed $controller, string $anchorText, cal
$r = new \ReflectionMethod($controller, '__invoke');
} elseif (!\is_string($controller)) {
return $anchorText;
} elseif (false !== strpos($controller, '::')) {
} elseif (str_contains($controller, '::')) {
$r = new \ReflectionMethod($controller);
} else {
$r = new \ReflectionFunction($controller);
Expand Down Expand Up @@ -609,7 +609,7 @@ private function formatCallable(mixed $callable): string

if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
if (false !== strpos($r->name, '{closure}')) {
if (str_contains($r->name, '{closure}')) {
return 'Closure()';
}
if ($class = $r->getClosureScopeClass()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
$callableXML->setAttribute('name', $callable[1]);
$callableXML->setAttribute('class', \get_class($callable[0]));
} else {
if (0 !== strpos($callable[1], 'parent::')) {
if (str_contains($callable[1], 'parent::')) {
$callableXML->setAttribute('name', $callable[1]);
$callableXML->setAttribute('class', $callable[0]);
$callableXML->setAttribute('static', 'true');
Expand Down Expand Up @@ -540,7 +540,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
$callableXML->setAttribute('type', 'closure');

$r = new \ReflectionFunction($callable);
if (false !== strpos($r->name, '{closure}')) {
if (str_contains($r->name, '{closure}')) {
return $dom;
}
$callableXML->setAttribute('name', $r->name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function process(ContainerBuilder $container)
continue;
}

if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= \strlen($tag) / 3) {
if (str_contains($definedTag, $tag) || levenshtein($tag, $definedTag) <= \strlen($tag) / 3) {
$candidates[] = $definedTag;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
],
]);

$kernelClass = false !== strpos(static::class, "@anonymous\0") ? parent::class : static::class;
$kernelClass = str_contains(static::class, "@anonymous\0") ? parent::class : static::class;

if (!$container->hasDefinition('kernel')) {
$container->register('kernel', $kernelClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function load(mixed $resource, string $type = null): mixed
continue;
}

if (false !== strpos($controller, '::')) {
if (str_contains($controller, '::')) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/Secrets/DotenvVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function reveal(string $name): ?string
{
$this->lastMessage = null;
$this->validateName($name);
$v = \is_string($_SERVER[$name] ?? null) && 0 !== strpos($name, 'HTTP_') ? $_SERVER[$name] : ($_ENV[$name] ?? null);
$v = \is_string($_SERVER[$name] ?? null) && str_contains($name, 'HTTP_') ? $_SERVER[$name] : ($_ENV[$name] ?? null);

if (null === $v) {
$this->lastMessage = sprintf('Secret "%s" not found in "%s".', $name, $this->getPrettyPath($this->dotenvFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function testRedisCachePools()
try {
$this->doTestCachePools(['root_config' => 'redis_config.yml', 'environment' => 'redis_cache'], RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
if (str_contains($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (InvalidArgumentException $e) {
if (0 !== strpos($e->getMessage(), 'Redis connection ')) {
if (str_contains($e->getMessage(), 'Redis connection ')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
Expand All @@ -58,7 +58,7 @@ public function testRedisCustomCachePools()
try {
$this->doTestCachePools(['root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'], RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
if (str_contains($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion < 897E /span> src/Symfony/Bundle/SecurityBundle/Command/DebugFirewallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function formatCallable(mixed $callable): string

if ($callable instanceof \Closure) {
$r = new \ReflectionFunction($callable);
if (false !== strpos($r->name, '{closure}')) {
if (str_contains($r->name, '{closure}')) {
return 'Closure()';
}
if ($class = $r->getClosureScopeClass()) {
Expand Down
Loading
0