Merge branch '4.4' into 5.2

* 4.4:
  Leverage str_contains/str_starts_with
  Leverage str_ends_with
This commit is contained in:
Nicolas Grekas 2021-07-21 14:38:00 +02:00
commit 6d1f8c8c2b
294 changed files with 550 additions and 533 deletions

View File

@ -51,7 +51,7 @@
"symfony/polyfill-intl-normalizer": "~1.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.11",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/polyfill-php81": "^1.22",
"symfony/polyfill-uuid": "^1.15"
},

View File

@ -221,7 +221,7 @@ abstract class AbstractDoctrineExtension extends Extension
]);
}
$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']);
}

View File

@ -50,7 +50,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
if ($metadata instanceof ClassMetadataInfo && class_exists(\Doctrine\ORM\Mapping\Embedded::class) && $metadata->embeddedClasses) {
$properties = array_filter($properties, function ($property) {
return false === strpos($property, '.');
return !str_contains($property, '.');
});
$properties = array_merge($properties, array_keys($metadata->embeddedClasses));

View File

@ -144,7 +144,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
if (null === $this->class) {
$class = $this->classOrAlias;
if (false !== strpos($class, ':')) {
if (str_contains($class, ':')) {
$class = $this->getClassMetadata()->getName();
}

View File

@ -104,7 +104,7 @@ final class DoctrineLoader implements LoaderInterface
}
if (null === $lengthConstraint) {
if (isset($mapping['originalClass']) && false === strpos($mapping['declaredField'], '.')) {
if (isset($mapping['originalClass']) && !str_contains($mapping['declaredField'], '.')) {
$metadata->addPropertyConstraint($mapping['declaredField'], new Valid());
$loaded = true;
} elseif (property_exists($className, $mapping['fieldName'])) {

View File

@ -22,7 +22,7 @@
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.1|^2"
},
"require-dev": {

View File

@ -96,7 +96,7 @@ EOF
'multiline' => OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity(),
]));
if (false === strpos($host = $input->getOption('host'), '://')) {
if (!str_contains($host = $input->getOption('host'), '://')) {
$host = 'tcp://'.$host;
}

View File

@ -163,7 +163,7 @@ class ConsoleFormatter implements FormatterInterface
{
$message = $record['message'];
if (false === strpos($message, '{')) {
if (!str_contains($message, '{')) {
return $record;
}

View File

@ -61,7 +61,7 @@ trait ServerLogHandlerTrait
{
parent::__construct($level, $bubble);
if (false === strpos($host, '://')) {
if (!str_contains($host, '://')) {
$host = 'tcp://'.$host;
}

View File

@ -20,7 +20,8 @@
"monolog/monolog": "^1.25.1|^2",
"symfony/service-contracts": "^1.1|^2",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/deprecation-contracts": "^2.1"
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"symfony/console": "^4.4|^5.0",

View File

@ -28,12 +28,12 @@ class LazyLoadingValueHolderGenerator extends BaseGenerator
parent::generate($originalClass, $classGenerator, $proxyOptions);
foreach ($classGenerator->getMethods() as $method) {
if (0 === strpos($originalClass->getFilename(), __FILE__)) {
if (str_starts_with($originalClass->getFilename(), __FILE__)) {
$method->setBody(str_replace(var_export($originalClass->name, true), '__CLASS__', $method->getBody()));
}
}
if (0 === strpos($originalClass->getFilename(), __FILE__)) {
if (str_starts_with($originalClass->getFilename(), __FILE__)) {
$interfaces = $classGenerator->getImplementedInterfaces();
array_pop($interfaces);
$classGenerator->setImplementedInterfaces(array_merge($interfaces, $originalClass->getInterfaceNames()));

View File

@ -19,7 +19,8 @@
"php": ">=7.2.5",
"composer/package-versions-deprecated": "^1.8",
"friendsofphp/proxy-manager-lts": "^1.0.2",
"symfony/dependency-injection": "^5.0"
"symfony/dependency-injection": "^5.0",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"symfony/config": "^4.4|^5.0"

View File

@ -211,7 +211,7 @@ EOF
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);
}
}
@ -245,7 +245,7 @@ EOF
$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);
}
}
@ -395,7 +395,7 @@ EOF
$folders = glob($this->twigDefaultPath.'/bundles/*', \GLOB_ONLYDIR);
$relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
$bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) {
if (0 === strpos($absolutePath, $this->projectDir)) {
if (str_starts_with($absolutePath, $this->projectDir)) {
$name = basename($absolutePath);
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
$carry[$name] = $path;
@ -525,7 +525,7 @@ EOF
$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;
}
}
@ -539,7 +539,7 @@ EOF
private function getRelativePath(string $path): string
{
if (null !== $this->projectDir && 0 === strpos($path, $this->projectDir)) {
if (null !== $this->projectDir && str_starts_with($path, $this->projectDir)) {
return ltrim(substr($path, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
}

View File

@ -65,7 +65,7 @@ final class CodeExtension extends AbstractExtension
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) {
@ -190,7 +190,7 @@ final class CodeExtension extends AbstractExtension
{
$file = str_replace('\\', '/', $file);
if (null !== $this->projectDir && 0 === strpos($file, $this->projectDir)) {
if (null !== $this->projectDir && str_starts_with($file, $this->projectDir)) {
return ltrim(substr($file, \strlen($this->projectDir)), '/');
}
@ -209,7 +209,7 @@ final class CodeExtension extends AbstractExtension
*/
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)) {

View File

@ -17,7 +17,7 @@
],
"require": {
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/translation-contracts": "^1.1|^2",
"twig/twig": "^2.13|^3.0.4"
},

View File

@ -59,7 +59,7 @@ class DebugExtension extends Extension
$container->getDefinition('var_dumper.command.server_dump')
->setClass(ServerDumpPlaceholderCommand::class)
;
} elseif (0 === strpos($config['dump_destination'], 'tcp://')) {
} elseif (str_starts_with($config['dump_destination'], 'tcp://')) {
$container->getDefinition('debug.dump_listener')
->replaceArgument(2, new Reference('var_dumper.server_connection'))
;

View File

@ -19,6 +19,7 @@
"php": ">=7.2.5",
"ext-xml": "*",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/polyfill-php80": "^1.16",
"symfony/twig-bridge": "^4.4|^5.0",
"symfony/var-dumper": "^4.4|^5.0"
},

View File

@ -113,7 +113,7 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
}
}
if ('Bundle' !== substr($name, -6)) {
if (!str_ends_with($name, 'Bundle')) {
$message = sprintf('No extensions with configuration available for "%s".', $name);
} else {
$message = sprintf('No extension with alias "%s" is enabled.', $name);

View File

@ -83,7 +83,7 @@ EOF
$realBuildDir = $kernel->getContainer()->hasParameter('kernel.build_dir') ? $kernel->getContainer()->getParameter('kernel.build_dir') : $realCacheDir;
// the old cache dir name must not be longer than the real one to avoid exceeding
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
$oldCacheDir = substr($realCacheDir, 0, -1).(str_ends_with($realCacheDir, '~') ? '+' : '~');
$fs->remove($oldCacheDir);
if (!is_writable($realCacheDir)) {

View File

@ -237,7 +237,7 @@ EOF
$serviceIds = $builder->getServiceIds();
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
foreach ($serviceIds as $serviceId) {
if (!$showHidden && 0 === strpos($serviceId, '.')) {
if (!$showHidden && str_starts_with($serviceId, '.')) {
continue;
}
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
@ -262,7 +262,7 @@ EOF
}
// if the id has a \, assume it is a class
if (false !== strpos($serviceId, '\\')) {
if (str_contains($serviceId, '\\')) {
return true;
}

View File

@ -113,7 +113,7 @@ final class ContainerLintCommand extends Command
$skippedIds = [];
foreach ($container->getServiceIds() as $serviceId) {
if (0 === strpos($serviceId, '.errored.')) {
if (str_starts_with($serviceId, '.errored.')) {
$skippedIds[$serviceId] = true;
}
}

View File

@ -80,7 +80,7 @@ EOF
if ($search = $input->getArgument('search')) {
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($search) {
return false !== stripos(str_replace('\\', '', $serviceId), $search) && 0 !== strpos($serviceId, '.');
return false !== stripos(str_replace('\\', '', $serviceId), $search) && !str_starts_with($serviceId, '.');
});
if (empty($serviceIds)) {
@ -104,7 +104,7 @@ EOF
foreach ($serviceIds as $serviceId) {
$text = [];
$resolvedServiceId = $serviceId;
if (0 !== strpos($serviceId, $previousId)) {
if (!str_starts_with($serviceId, $previousId)) {
$text[] = '';
if ('' !== $description = Descriptor::getClassDescription($serviceId, $resolvedServiceId)) {
if (isset($hasAlias[$serviceId])) {

View File

@ -37,7 +37,7 @@ class XliffLintCommand extends BaseLintCommand
};
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
};
parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);

View File

@ -36,7 +36,7 @@ class YamlLintCommand extends BaseLintCommand
};
$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
};
parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);

View File

@ -312,7 +312,7 @@ class JsonDescriptor extends Descriptor
$data['name'] = $callable[1];
$data['class'] = \get_class($callable[0]);
} else {
if (0 !== strpos($callable[1], 'parent::')) {
if (!str_starts_with($callable[1], 'parent::')) {
$data['name'] = $callable[1];
$data['class'] = $callable[0];
$data['static'] = true;
@ -330,7 +330,7 @@ class JsonDescriptor extends Descriptor
if (\is_string($callable)) {
$data['type'] = 'function';
if (false === strpos($callable, '::')) {
if (!str_contains($callable, '::')) {
$data['name'] = $callable;
} else {
$callableParts = explode('::', $callable);
@ -347,7 +347,7 @@ class JsonDescriptor extends Descriptor
$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;

View File

@ -328,7 +328,7 @@ class MarkdownDescriptor extends Descriptor
$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_starts_with($callable[1], 'parent::')) {
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
$string .= "\n".sprintf('- Class: `%s`', $callable[0]);
$string .= "\n- Static: yes";
@ -346,7 +346,7 @@ class MarkdownDescriptor extends Descriptor
if (\is_string($callable)) {
$string .= "\n- Type: `function`";
if (false === strpos($callable, '::')) {
if (!str_contains($callable, '::')) {
$string .= "\n".sprintf('- Name: `%s`', $callable);
} else {
$callableParts = explode('::', $callable);
@ -363,7 +363,7 @@ class MarkdownDescriptor extends Descriptor
$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);

View File

@ -548,7 +548,7 @@ class TextDescriptor extends Descriptor
$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);
@ -601,7 +601,7 @@ class TextDescriptor extends Descriptor
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()) {

View File

@ -502,7 +502,7 @@ class XmlDescriptor extends Descriptor
$callableXML->setAttribute('name', $callable[1]);
$callableXML->setAttribute('class', \get_class($callable[0]));
} else {
if (0 !== strpos($callable[1], 'parent::')) {
if (!str_starts_with($callable[1], 'parent::')) {
$callableXML->setAttribute('name', $callable[1]);
$callableXML->setAttribute('class', $callable[0]);
$callableXML->setAttribute('static', 'true');
@ -520,7 +520,7 @@ class XmlDescriptor extends Descriptor
if (\is_string($callable)) {
$callableXML->setAttribute('type', 'function');
if (false === strpos($callable, '::')) {
if (!str_contains($callable, '::')) {
$callableXML->setAttribute('name', $callable);
} else {
$callableParts = explode('::', $callable);
@ -537,7 +537,7 @@ class XmlDescriptor extends Descriptor
$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);

View File

@ -129,7 +129,7 @@ class RedirectController
}
if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
if (false === strpos($path, '?')) {
if (!str_contains($path, '?')) {
$qs = '?'.$qs;
} else {
$qs = '&'.$qs;

View File

@ -107,7 +107,7 @@ class UnusedTagsPass implements CompilerPassInterface
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;
}
}

View File

@ -1253,7 +1253,7 @@ class FrameworkExtension extends Extension
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
'cache_vary' => [
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
return str_starts_with($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
}, $scannedDirectories),
],
]

View File

@ -82,7 +82,7 @@ class DelegatingLoader extends BaseDelegatingLoader
continue;
}
if (false !== strpos($controller, '::')) {
if (str_contains($controller, '::')) {
continue;
}

View File

@ -54,7 +54,7 @@ class DotenvVault extends AbstractVault
{
$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_starts_with($name, 'HTTP_') ? $_SERVER[$name] : ($_ENV[$name] ?? null);
if (null === $v) {
$this->lastMessage = sprintf('Secret "%s" not found in "%s".', $name, $this->getPrettyPath($this->dotenvFile));

View File

@ -35,12 +35,12 @@ class CachePoolsTest extends AbstractWebTestCase
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_starts_with($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (InvalidArgumentException $e) {
if (0 !== strpos($e->getMessage(), 'Redis connection ')) {
if (!str_starts_with($e->getMessage(), 'Redis connection ')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
@ -58,7 +58,7 @@ class CachePoolsTest extends AbstractWebTestCase
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_starts_with($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());

View File

@ -27,7 +27,7 @@
"symfony/http-foundation": "^5.2.1",
"symfony/http-kernel": "^5.2.1",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/filesystem": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0",
"symfony/routing": "^5.2"

View File

@ -279,7 +279,7 @@ class MainConfiguration implements ConfigurationInterface
continue;
}
if (false !== strpos($firewall[$k]['check_path'], '/') && !preg_match('#'.$firewall['pattern'].'#', $firewall[$k]['check_path'])) {
if (str_contains($firewall[$k]['check_path'], '/') && !preg_match('#'.$firewall['pattern'].'#', $firewall[$k]['check_path'])) {
throw new \LogicException(sprintf('The check_path "%s" for login method "%s" is not matched by the firewall pattern "%s".', $firewall[$k]['check_path'], $k, $firewall['pattern']));
}
}

View File

@ -75,7 +75,7 @@ abstract class CompleteConfigurationTest extends TestCase
{
$container = $this->getContainer('container1');
$providers = array_values(array_filter($container->getServiceIds(), function ($key) { return 0 === strpos($key, 'security.user.provider.concrete'); }));
$providers = array_values(array_filter($container->getServiceIds(), function ($key) { return str_starts_with($key, 'security.user.provider.concrete'); }));
$expectedProviders = [
'security.user.provider.concrete.default',

View File

@ -23,7 +23,7 @@
"symfony/deprecation-contracts": "^2.1",
"symfony/event-dispatcher": "^5.1",
"symfony/http-kernel": "^5.0",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/security-core": "^5.2",
"symfony/security-csrf": "^4.4|^5.0",
"symfony/security-guard": "^5.2",

View File

@ -44,7 +44,7 @@ EOF
protected function findFiles(string $filename): iterable
{
if (0 === strpos($filename, '@')) {
if (str_starts_with($filename, '@')) {
$dir = $this->getApplication()->getKernel()->locateResource($filename);
return Finder::create()->files()->in($dir)->name('*.twig');

View File

@ -43,7 +43,7 @@ class TwigEnvironmentPass implements CompilerPassInterface
$methodCall = ['addExtension', [$extension]];
$extensionClass = $container->getDefinition((string) $extension)->getClass();
if (\is_string($extensionClass) && 0 === strpos($extensionClass, 'Symfony\Bridge\Twig\Extension')) {
if (\is_string($extensionClass) && str_starts_with($extensionClass, 'Symfony\Bridge\Twig\Extension')) {
$twigBridgeExtensionsMethodCalls[] = $methodCall;
} else {
$othersExtensionsMethodCalls[] = $methodCall;

View File

@ -86,9 +86,9 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->normalizeKeys(false)
->beforeNormalization()
->ifTrue(function ($v) { return \is_string($v) && 0 === strpos($v, '@'); })
->ifTrue(function ($v) { return \is_string($v) && str_starts_with($v, '@'); })
->then(function ($v) {
if (0 === strpos($v, '@@')) {
if (str_starts_with($v, '@@')) {
return substr($v, 1);
}

View File

@ -172,7 +172,7 @@ class TwigExtension extends Extension
private function normalizeBundleName(string $name): string
{
if ('Bundle' === substr($name, -6)) {
if (str_ends_with($name, 'Bundle')) {
$name = substr($name, 0, -6);
}

View File

@ -49,7 +49,7 @@ class TemplateIterator implements \IteratorAggregate
foreach ($this->kernel->getBundles() as $bundle) {
$name = $bundle->getName();
if ('Bundle' === substr($name, -6)) {
if (str_ends_with($name, 'Bundle')) {
$name = substr($name, 0, -6);
}

View File

@ -181,7 +181,7 @@ class TwigExtensionTest extends TestCase
$def = $container->getDefinition('twig.loader.native_filesystem');
$paths = [];
foreach ($def->getMethodCalls() as $call) {
if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) {
if ('addPath' === $call[0] && !str_contains($call[1][0], 'Form')) {
$paths[] = $call[1];
}
}

View File

@ -22,6 +22,7 @@
"symfony/http-foundation": "^4.4|^5.0",
"symfony/http-kernel": "^5.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-php80": "^1.16",
"twig/twig": "^2.13|^3.0.4"
},
"require-dev": {

View File

@ -221,7 +221,7 @@ class ContentSecurityPolicyHandler
private function hasHashOrNonce(array $directives): bool
{
foreach ($directives as $directive) {
if ('\'' !== substr($directive, -1)) {
if (!str_ends_with($directive, '\'')) {
continue;
}
if ('\'nonce-' === substr($directive, 0, 7)) {

View File

@ -101,7 +101,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
if (self::DISABLED === $this->mode
|| !$response->headers->has('X-Debug-Token')
|| $response->isRedirection()
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
|| 'html' !== $request->getRequestFormat()
|| false !== stripos($response->headers->get('Content-Disposition', ''), 'attachment;')
) {

View File

@ -78,7 +78,7 @@ class TemplateManager
continue;
}
if ('.html.twig' === substr($template, -10)) {
if (str_ends_with($template, '.html.twig')) {
$template = substr($template, 0, -10);
}

View File

@ -90,7 +90,7 @@ class WebProfilerExtension extends ProfilerExtension
$message = twig_escape_filter($env, $message);
$message = preg_replace('/&quot;(.*?)&quot;/', '&quot;<b>$1</b>&quot;', $message);
if (null === $context || false === strpos($message, '{')) {
if (null === $context || !str_contains($message, '{')) {
return '<span class="dump-inline">'.$message.'</span>';
}

View File

@ -20,6 +20,7 @@
"symfony/config": "^4.4|^5.0",
"symfony/framework-bundle": "^5.1",
"symfony/http-kernel": "^5.2",
"symfony/polyfill-php80": "^1.16",
"symfony/routing": "^4.4|^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"twig/twig": "^2.13|^3.0.4"

View File

@ -73,6 +73,6 @@ class Package implements PackageInterface
*/
protected function isAbsoluteUrl(string $url)
{
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
return str_contains($url, '://') || '//' === substr($url, 0, 2);
}
}

View File

@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=7.2.5"
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
},
"suggest": {
"symfony/http-foundation": ""

View File

@ -129,7 +129,7 @@ class Cookie
{
$parts = explode(';', $cookie);
if (false === strpos($parts[0], '=')) {
if (!str_contains($parts[0], '=')) {
throw new \InvalidArgumentException(sprintf('The cookie string "%s" is not valid.', $parts[0]));
}

View File

@ -42,13 +42,13 @@ class CookieJar
foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
if ($cookieDomain && $domain) {
$cookieDomain = '.'.ltrim($cookieDomain, '.');
if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) {
if (!str_ends_with('.'.$domain, $cookieDomain)) {
continue;
}
}
foreach ($pathCookies as $cookiePath => $namedCookies) {
if (0 !== strpos($path, $cookiePath)) {
if (!str_starts_with($path, $cookiePath)) {
continue;
}
if (isset($namedCookies[$name])) {

View File

@ -100,7 +100,7 @@ class HttpBrowser extends AbstractBrowser
foreach ($request->getServer() as $key => $value) {
$key = strtolower(str_replace('_', '-', $key));
$contentHeaders = ['content-length' => true, 'content-md5' => true, 'content-type' => true];
if (0 === strpos($key, 'http-')) {
if (str_starts_with($key, 'http-')) {
$headers[substr($key, 5)] = $value;
} elseif (isset($contentHeaders[$key])) {
// CONTENT_* are not prefixed with HTTP_

View File

@ -17,7 +17,8 @@
],
"require": {
"php": ">=7.2.5",
"symfony/dom-crawler": "^4.4|^5.0"
"symfony/dom-crawler": "^4.4|^5.0",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"symfony/css-selector": "^4.4|^5.0",

View File

@ -126,10 +126,10 @@ abstract class AbstractAdapter implements AdapterInterface, CacheInterface, Logg
public static function createConnection(string $dsn, array $options = [])
{
if (0 === strpos($dsn, 'redis:') || 0 === strpos($dsn, 'rediss:')) {
if (str_starts_with($dsn, 'redis:') || str_starts_with($dsn, 'rediss:')) {
return RedisAdapter::createConnection($dsn, $options);
}
if (0 === strpos($dsn, 'memcached:')) {
if (str_starts_with($dsn, 'memcached:')) {
return MemcachedAdapter::createConnection($dsn, $options);
}
if (0 === strpos($dsn, 'couchbase:')) {

View File

@ -88,7 +88,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
protected function doSave(array $values, int $lifetime, array $addTagData = [], array $delTagData = []): array
{
$eviction = $this->getRedisEvictionPolicy();
if ('noeviction' !== $eviction && 0 !== strpos($eviction, 'volatile-')) {
if ('noeviction' !== $eviction && !str_starts_with($eviction, 'volatile-')) {
throw new LogicException(sprintf('Redis maxmemory-policy setting "%s" is *not* supported by RedisTagAwareAdapter, use "noeviction" or "volatile-*" eviction policies.', $eviction));
}

View File

@ -233,7 +233,7 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
{
if ('' !== $prefix) {
foreach ($this->deferred as $key => $item) {
if (0 === strpos($key, $prefix)) {
if (str_starts_with($key, $prefix)) {
unset($this->deferred[$key]);
}
}

View File

@ -58,7 +58,7 @@ trait FilesystemCommonTrait
$ok = true;
foreach ($this->scanHashDir($this->directory) as $file) {
if ('' !== $namespace && 0 !== strpos($this->getFileKey($file), $namespace)) {
if ('' !== $namespace && !str_starts_with($this->getFileKey($file), $namespace)) {
continue;
}
@ -98,7 +98,7 @@ trait FilesystemCommonTrait
try {
$h = fopen($this->tmp, 'x');
} catch (\ErrorException $e) {
if (false === strpos($e->getMessage(), 'File exists')) {
if (!str_contains($e->getMessage(), 'File exists')) {
throw $e;
}

View File

@ -90,9 +90,9 @@ trait RedisTrait
*/
public static function createConnection(string $dsn, array $options = [])
{
if (0 === strpos($dsn, 'redis:')) {
if (str_starts_with($dsn, 'redis:')) {
$scheme = 'redis';
} elseif (0 === strpos($dsn, 'rediss:')) {
} elseif (str_starts_with($dsn, 'rediss:')) {
$scheme = 'rediss';
} else {
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: "%s" does not start with "redis:" or "rediss".', $dsn));

View File

@ -25,7 +25,7 @@
"psr/cache": "^1.0|^2.0",
"psr/log": "^1.1|^2|^3",
"symfony/cache-contracts": "^1.1.7|^2",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.1|^2",
"symfony/var-exporter": "^4.4|^5.0"
},

View File

@ -55,7 +55,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
$normalized = [];
foreach ($value as $k => $v) {
if (false !== strpos($k, '-') && false === strpos($k, '_') && !\array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
if (str_contains($k, '-') && !str_contains($k, '_') && !\array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
$normalized[$normalizedKey] = $v;
} else {
$normalized[$k] = $v;

View File

@ -47,7 +47,7 @@ abstract class BaseNode implements NodeInterface
*/
public function __construct(?string $name, NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
{
if (false !== strpos($name = (string) $name, $pathSeparator)) {
if (str_contains($name = (string) $name, $pathSeparator)) {
throw new \InvalidArgumentException('The name must not contain ".'.$pathSeparator.'".');
}
@ -542,7 +542,7 @@ abstract class BaseNode implements NodeInterface
}
foreach (self::$placeholderUniquePrefixes as $placeholderUniquePrefix) {
if (0 === strpos($value, $placeholderUniquePrefix)) {
if (str_starts_with($value, $placeholderUniquePrefix)) {
return [];
}
}

View File

@ -71,7 +71,7 @@ abstract class FileLoader extends Loader
*/
public function import($resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null, $exclude = null)
{
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && false === strpos($resource, "\n")) {
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && !str_contains($resource, "\n")) {
$excluded = [];
foreach ((array) $exclude as $pattern) {
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {
@ -81,7 +81,7 @@ abstract class FileLoader extends Loader
}
$ret = [];
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
$isSubpath = 0 !== $i && str_contains(substr($resource, 0, $i), '/');
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath, false, $excluded) as $path => $info) {
if (null !== $res = $this->doImport($path, 'glob' === $type ? null : $type, $ignoreErrors, $sourceResource)) {
$ret[] = $res;
@ -105,7 +105,7 @@ abstract class FileLoader extends Loader
if (\strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
$prefix = $pattern;
$pattern = '';
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
} elseif (0 === $i || !str_contains(substr($pattern, 0, $i), '/')) {
$prefix = '.';
$pattern = '/'.$pattern;
} else {

View File

@ -55,7 +55,7 @@ class ComposerResource implements SelfCheckingResourceInterface
self::$runtimeVendors = [];
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname($r->getFileName(), 2);
if (is_file($v.'/composer/installed.json')) {

View File

@ -81,7 +81,7 @@ class DirectoryResource implements SelfCheckingResourceInterface
// always monitor directories for changes, except the .. entries
// (otherwise deleted files wouldn't get detected)
if ($file->isDir() && '/..' === substr($file, -3)) {
if ($file->isDir() && str_ends_with($file, '/..')) {
continue;
}

View File

@ -107,10 +107,10 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
$prefix = str_replace('\\', '/', $this->prefix);
$paths = null;
if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/')) {
if ($this->globBrace || false === strpos($this->pattern, '{')) {
if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
if ($this->globBrace || !str_contains($this->pattern, '{')) {
$paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace);
} elseif (false === strpos($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
} elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
foreach ($this->expandGlob($this->pattern) as $p) {
$paths[] = glob($this->prefix.$p, \GLOB_NOSORT);
}
@ -223,7 +223,7 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
$j = 0;
foreach ($patterns as $i => $p) {
if (false !== strpos($p, '{')) {
if (str_contains($p, '{')) {
$p = $this->expandGlob($p);
array_splice($paths, $i + $j, 1, $p);
$j += \count($p) - 1;

View File

@ -85,7 +85,7 @@ class ReflectionClassResource implements SelfCheckingResourceInterface
$file = $class->getFileName();
if (false !== $file && is_file($file)) {
foreach ($this->excludedVendors as $vendor) {
if (0 === strpos($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
if (str_starts_with($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
$file = false;
break;
}

View File

@ -25,7 +25,7 @@ class ComposerResourceTest extends TestCase
$found = false;
foreach ($res->getVendors() as $vendor) {
if ($vendor && 0 === strpos($r->getFileName(), $vendor)) {
if ($vendor && str_starts_with($r->getFileName(), $vendor)) {
$found = true;
break;
}

View File

@ -20,7 +20,7 @@
"symfony/deprecation-contracts": "^2.1",
"symfony/filesystem": "^4.4|^5.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/polyfill-php81": "^1.22"
},
"require-dev": {

View File

@ -812,7 +812,7 @@ class Application implements ResetInterface
$len = 0;
}
if (false !== strpos($message, "@anonymous\0")) {
if (str_contains($message, "@anonymous\0")) {
$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) {
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
}, $message);
@ -1113,7 +1113,7 @@ class Application implements ResetInterface
}
$lev = levenshtein($subname, $parts[$i]);
if ($lev <= \strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
if ($lev <= \strlen($subname) / 3 || '' !== $subname && str_contains($parts[$i], $subname)) {
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
} elseif ($exists) {
$alternatives[$collectionName] += $threshold;
@ -1123,7 +1123,7 @@ class Application implements ResetInterface
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;
}
}

View File

@ -604,7 +604,7 @@ class Command
*/
public function addUsage(string $usage)
{
if (0 !== strpos($usage, $this->name)) {
if (!str_starts_with($usage, $this->name)) {
$usage = sprintf('%s %s', $this->name, $usage);
}

View File

@ -52,7 +52,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
*/
public static function escapeTrailingBackslash(string $text): string
{
if ('\\' === substr($text, -1)) {
if (str_ends_with($text, '\\')) {
$len = \strlen($text);
$text = rtrim($text, '\\');
$text = str_replace("\0", '', $text);
@ -178,7 +178,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
$output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength);
if (false !== strpos($output, "\0")) {
if (str_contains($output, "\0")) {
return strtr($output, ["\0" => '\\', '\\<' => '<']);
}

View File

@ -311,7 +311,7 @@ class QuestionHelper extends Helper
$matches = array_filter(
$autocomplete($ret),
function ($match) use ($ret) {
return '' === $ret || 0 === strpos($match, $ret);
return '' === $ret || str_starts_with($match, $ret);
}
);
$numMatches = \count($matches);
@ -348,7 +348,7 @@ class QuestionHelper extends Helper
foreach ($autocomplete($ret) as $value) {
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
if (0 === strpos($value, $tempRet)) {
if (str_starts_with($value, $tempRet)) {
$matches[$numMatches++] = $value;
}
}
@ -374,7 +374,7 @@ class QuestionHelper extends Helper
private function mostRecentlyEnteredValue(string $entered): string
{
// Determine the most recent value that the user entered
if (false === strpos($entered, ',')) {
if (!str_contains($entered, ',')) {
return $entered;
}

View File

@ -72,7 +72,7 @@ class ArgvInput extends Input
$this->parseArgument($token);
} elseif ($parseOptions && '--' == $token) {
$parseOptions = false;
} elseif ($parseOptions && 0 === strpos($token, '--')) {
} elseif ($parseOptions && str_starts_with($token, '--')) {
$this->parseLongOption($token);
} elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
$this->parseShortOption($token);
@ -254,7 +254,7 @@ class ArgvInput extends Input
$isOption = false;
foreach ($this->tokens as $i => $token) {
if ($token && '-' === $token[0]) {
if (false !== strpos($token, '=') || !isset($this->tokens[$i + 1])) {
if (str_contains($token, '=') || !isset($this->tokens[$i + 1])) {
continue;
}
@ -296,8 +296,8 @@ class ArgvInput extends Input
// Options with values:
// For long options, test for '--option=' at beginning
// For short options, test for '-o' at beginning
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
if ($token === $value || '' !== $leading && str_starts_with($token, $leading)) {
return true;
}
}
@ -327,8 +327,8 @@ class ArgvInput extends Input
// Options with values:
// For long options, test for '--option=' at beginning
// For short options, test for '-o' at beginning
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
if ('' !== $leading && 0 === strpos($token, $leading)) {
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
if ('' !== $leading && str_starts_with($token, $leading)) {
return substr($token, \strlen($leading));
}
}

View File

@ -133,9 +133,9 @@ class ArrayInput extends Input
if ('--' === $key) {
return;
}
if (0 === strpos($key, '--')) {
if (str_starts_with($key, '--')) {
$this->addLongOption(substr($key, 2), $value);
} elseif (0 === strpos($key, '-')) {
} elseif (str_starts_with($key, '-')) {
$this->addShortOption(substr($key, 1), $value);
} else {
$this->addArgument($key, $value);

View File

@ -56,7 +56,7 @@ class InputOption
*/
public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
{
if (0 === strpos($name, '--')) {
if (str_starts_with($name, '--')) {
$name = substr($name, 2);
}

View File

@ -104,7 +104,7 @@ class ConsoleLogger extends AbstractLogger
*/
private function interpolate(string $message, array $context): string
{
if (false === strpos($message, '{')) {
if (!str_contains($message, '{')) {
return $message;
}

View File

@ -447,7 +447,7 @@ class SymfonyStyle extends OutputStyle
{
$fetched = $this->bufferedOutput->fetch();
//Prepend new line if last char isn't EOL:
if ("\n" !== substr($fetched, -1)) {
if (!str_ends_with($fetched, "\n")) {
$this->newLine();
}
}

View File

@ -19,7 +19,7 @@
"php": ">=7.2.5",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.8",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.1|^2",
"symfony/string": "^5.1"
},

View File

@ -79,7 +79,7 @@ class Parser implements ParserInterface
return [2, 0];
case 'n' === $joined:
return [1, 0];
case false === strpos($joined, 'n'):
case !str_contains($joined, 'n'):
return [0, $int($joined)];
}

View File

@ -63,11 +63,11 @@ class Translator implements TranslatorInterface
public static function getXpathLiteral(string $element): string
{
if (false === strpos($element, "'")) {
if (!str_contains($element, "'")) {
return "'".$element."'";
}
if (false === strpos($element, '"')) {
if (!str_contains($element, '"')) {
return '"'.$element.'"';
}

View File

@ -20,7 +20,8 @@
}
],
"require": {
"php": ">=7.2.5"
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
},
"autoload": {
"psr-4": { "Symfony\\Component\\CssSelector\\": "" },

View File

@ -112,7 +112,7 @@ class Alias
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
}
if (false === strpos($message, '%alias_id%')) {
if (!str_contains($message, '%alias_id%')) {
throw new InvalidArgumentException('The deprecation template must contain the "%alias_id%" placeholder.');
}
}

View File

@ -93,7 +93,7 @@ class ChildDefinition extends Definition
{
if (\is_int($index)) {
$this->arguments['index_'.$index] = $value;
} elseif (0 === strpos($index, '$')) {
} elseif (str_starts_with($index, '$')) {
$this->arguments[$index] = $value;
} else {
throw new InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.');

View File

@ -297,7 +297,7 @@ class AutowirePass extends AbstractRecursivePass
if ($this->container->has($name) && !$this->container->findDefinition($name)->isAbstract()) {
foreach ($this->container->getAliases() as $id => $alias) {
if ($name === (string) $alias && 0 === strpos($id, $type.' $')) {
if ($name === (string) $alias && str_starts_with($id, $type.' $')) {
return new TypedReference($name, $type, $reference->getInvalidBehavior());
}
}

View File

@ -49,7 +49,7 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
}
if (class_exists($id) || interface_exists($id, false)) {
if (0 === strpos($id, '\\') && 1 < substr_count($id, '\\')) {
if (str_starts_with($id, '\\') && 1 < substr_count($id, '\\')) {
throw new RuntimeException(sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "%s" to get rid of this error.', $id, substr($id, 1)));
}

View File

@ -231,7 +231,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
$value = $this->container->getParameter(substr($value, 1, -1));
}
if ($envPlaceholderUniquePrefix && \is_string($value) && false !== strpos($value, 'env_')) {
if ($envPlaceholderUniquePrefix && \is_string($value) && str_contains($value, 'env_')) {
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it.
// We don't need to change the value because it is already a string.
if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) {

View File

@ -64,7 +64,7 @@ class Compiler
*/
public function log(CompilerPassInterface $pass, string $message)
{
if (false !== strpos($message, "\n")) {
if (str_contains($message, "\n")) {
$message = str_replace("\n", "\n".\get_class($pass).': ', trim($message));
}

View File

@ -209,7 +209,7 @@ class MergeExtensionConfigurationContainerBuilder extends ContainerBuilder
}
foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
if (false === strpos($env, ':')) {
if (!str_contains($env, ':')) {
continue;
}
foreach ($placeholders as $placeholder) {

View File

@ -91,7 +91,7 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
if ($name) {
if (false !== $i = strpos($name, '::get')) {
$name = lcfirst(substr($name, 5 + $i));
} elseif (false !== strpos($name, '::')) {
} elseif (str_contains($name, '::')) {
$name = null;
}
}

View File

@ -44,7 +44,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
foreach ($this->unusedBindings as [$key, $serviceId, $bindingType, $file]) {
$argumentType = $argumentName = $message = null;
if (false !== strpos($key, ' ')) {
if (str_contains($key, ' ')) {
[$argumentType, $argumentName] = explode(' ', $key, 2);
} elseif ('$' === $key[0]) {
$argumentName = $key;

View File

@ -164,7 +164,7 @@ class ResolveChildDefinitionsPass extends AbstractRecursivePass
foreach ($definition->getArguments() as $k => $v) {
if (is_numeric($k)) {
$def->addArgument($v);
} elseif (0 === strpos($k, 'index_')) {
} elseif (str_starts_with($k, 'index_')) {
$def->replaceArgument((int) substr($k, \strlen('index_')), $v);
} else {
$def->setArgument($k, $v);

View File

@ -263,7 +263,7 @@ class Container implements ContainerInterface, ResetInterface
continue;
}
$lev = levenshtein($id, $knownId);
if ($lev <= \strlen($id) / 3 || false !== strpos($knownId, $id)) {
if ($lev <= \strlen($id) / 3 || str_contains($knownId, $id)) {
$alternatives[] = $knownId;
}
}

View File

@ -1588,7 +1588,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
$path = realpath($path) ?: $path;
foreach ($this->vendors as $vendor) {
if (0 === strpos($path, $vendor) && false !== strpbrk(substr($path, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
if (str_starts_with($path, $vendor) && false !== strpbrk(substr($path, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
$this->addResource(new FileResource($vendor.'/composer/installed.json'));
return true;

View File

@ -104,7 +104,7 @@ class Definition
{
$this->changes['factory'] = true;
if (\is_string($factory) && false !== strpos($factory, '::')) {
if (\is_string($factory) && str_contains($factory, '::')) {
$factory = explode('::', $factory, 2);
} elseif ($factory instanceof Reference) {
$factory = [$factory, '__invoke'];
@ -737,7 +737,7 @@ class Definition
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
}
if (false === strpos($message, '%service_id%')) {
if (!str_contains($message, '%service_id%')) {
throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.');
}
}
@ -798,7 +798,7 @@ class Definition
{
$this->changes['configurator'] = true;
if (\is_string($configurator) && false !== strpos($configurator, '::')) {
if (\is_string($configurator) && str_contains($configurator, '::')) {
$configurator = explode('::', $configurator, 2);
} elseif ($configurator instanceof Reference) {
$configurator = [$configurator, '__invoke'];

View File

@ -160,7 +160,7 @@ class PhpDumper extends Dumper
$this->inlineRequires = $options['inline_class_loader_parameter'] && ($this->container->hasParameter($options['inline_class_loader_parameter']) ? $this->container->getParameter($options['inline_class_loader_parameter']) : (\PHP_VERSION_ID < 70400 || $options['debug']));
$this->serviceLocatorTag = $options['service_locator_tag'];
if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {
if (!str_starts_with($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {
$baseClass = sprintf('%s\%s', $options['namespace'] ? '\\'.$options['namespace'] : '', $baseClass);
$this->baseClass = $baseClass;
} elseif ('Container' === $baseClass) {
@ -332,7 +332,7 @@ require __DIR__.'/$preloadedFiles';
EOF;
foreach ($this->preload as $class) {
if (!$class || false !== strpos($class, '$') || \in_array($class, ['int', 'float', 'string', 'bool', 'resource', 'object', 'array', 'null', 'callable', 'iterable', 'mixed', 'void'], true)) {
if (!$class || str_contains($class, '$') || \in_array($class, ['int', 'float', 'string', 'bool', 'resource', 'object', 'array', 'null', 'callable', 'iterable', 'mixed', 'void'], true)) {
continue;
}
if (!(class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false)) || (new \ReflectionClass($class))->isUserDefined()) {
@ -523,7 +523,7 @@ EOF;
return;
}
$file = $r->getFileName();
if (') : eval()\'d code' === substr($file, -17)) {
if (str_ends_with($file, ') : eval()\'d code')) {
$file = substr($file, 0, strrpos($file, '(', -17));
}
if (!$file || $this->doExport($file) === $exportedFile = $this->export($file)) {
@ -656,7 +656,7 @@ EOF;
{
$class = $this->dumpValue($definition->getClass());
if (0 === strpos($class, "'") && false === strpos($class, '$') && !preg_match('/^\'(?:\\\{2})?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) {
if (str_starts_with($class, "'") && !str_contains($class, '$') && !preg_match('/^\'(?:\\\{2})?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
}
@ -783,11 +783,11 @@ EOF;
$class = $this->dumpValue($callable[0]);
// If the class is a string we can optimize away
if (0 === strpos($class, "'") && false === strpos($class, '$')) {
if (str_starts_with($class, "'") && !str_contains($class, '$')) {
return sprintf(" %s::%s(\$%s);\n", $this->dumpLiteralClass($class), $callable[1], $variableName);
}
if (0 === strpos($class, 'new ')) {
if (str_starts_with($class, 'new ')) {
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
}
@ -808,7 +808,7 @@ EOF;
if ($class = $definition->getClass()) {
$class = $class instanceof Parameter ? '%'.$class.'%' : $this->container->resolveEnvPlaceholders($class);
$return[] = sprintf(0 === strpos($class, '%') ? '@return object A %1$s instance' : '@return \%s', ltrim($class, '\\'));
$return[] = sprintf(str_starts_with($class, '%') ? '@return object A %1$s instance' : '@return \%s', ltrim($class, '\\'));
} elseif ($definition->getFactory()) {
$factory = $definition->getFactory();
if (\is_string($factory)) {
@ -821,7 +821,7 @@ EOF;
}
if ($definition->isDeprecated()) {
if ($return && 0 === strpos($return[\count($return) - 1], '@return')) {
if ($return && str_starts_with($return[\count($return) - 1], '@return')) {
$return[] = '';
}
@ -1151,7 +1151,7 @@ EOTXT
$class = $this->dumpValue($callable[0]);
// If the class is a string we can optimize away
if (0 === strpos($class, "'") && false === strpos($class, '$')) {
if (str_starts_with($class, "'") && !str_contains($class, '$')) {
if ("''" === $class) {
throw new RuntimeException(sprintf('Cannot dump definition: "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id ? 'The "'.$id.'"' : 'inline'));
}
@ -1159,7 +1159,7 @@ EOTXT
return $return.sprintf('%s::%s(%s)', $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '').$tail;
}
if (0 === strpos($class, 'new ')) {
if (str_starts_with($class, 'new ')) {
return $return.sprintf('(%s)->%s(%s)', $class, $callable[1], $arguments ? implode(', ', $arguments) : '').$tail;
}
@ -1889,16 +1889,16 @@ EOF;
*/
private function dumpLiteralClass(string $class): string
{
if (false !== strpos($class, '$')) {
if (str_contains($class, '$')) {
return sprintf('${($_ = %s) && false ?: "_"}', $class);
}
if (0 !== strpos($class, "'") || !preg_match('/^\'(?:\\\{2})?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) {
if (!str_starts_with($class, "'") || !preg_match('/^\'(?:\\\{2})?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*\'$/', $class)) {
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s).', $class ?: 'n/a'));
}
$class = substr(str_replace('\\\\', '\\', $class), 1, -1);
return 0 === strpos($class, '\\') ? $class : '\\'.$class;
return str_starts_with($class, '\\') ? $class : '\\'.$class;
}
private function dumpParameter(string $name): string
@ -2146,7 +2146,7 @@ EOF;
if ($shouldCacheValue && isset($this->exportedVariables[$value])) {
return $this->exportedVariables[$value];
}
if (\is_string($value) && false !== strpos($value, "\n")) {
if (\is_string($value) && str_contains($value, "\n")) {
$cleanParts = explode("\n", $value);
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
$export = implode('."\n".', $cleanParts);
@ -2164,7 +2164,7 @@ EOF;
if ($resolveEnv && "'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'")) {
$export = $resolvedExport;
if (".''" === substr($export, -3)) {
if (str_ends_with($export, ".''")) {
$export = substr($export, 0, -3);
if ("'" === $export[1]) {
$export = substr_replace($export, '', 18, 7);
@ -2200,7 +2200,7 @@ EOF;
}
foreach (get_declared_classes() as $class) {
if (0 === strpos($class, 'ComposerAutoloaderInit') && $class::getLoader() === $autoloader[0]) {
if (str_starts_with($class, 'ComposerAutoloaderInit') && $class::getLoader() === $autoloader[0]) {
$file = \dirname((new \ReflectionClass($class))->getFileName(), 2).'/autoload.php';
if (null !== $this->targetDirRegex && preg_match($this->targetDirRegex.'A', $file)) {

View File

@ -347,7 +347,7 @@ class YamlDumper extends Dumper
foreach ($parameters as $key => $value) {
if (\is_array($value)) {
$value = $this->prepareParameters($value, $escape);
} elseif ($value instanceof Reference || \is_string($value) && 0 === strpos($value, '@')) {
} elseif ($value instanceof Reference || \is_string($value) && str_starts_with($value, '@')) {
$value = '@'.$value;
}

View File

@ -129,7 +129,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
$env = $getEnv($name);
} elseif (isset($_ENV[$name])) {
$env = $_ENV[$name];
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
} elseif (isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')) {
$env = $_SERVER[$name];
} elseif (false === ($env = getenv($name)) || null === $env) { // null is a possible value because of thread safety issues
foreach ($this->loadedVars as $vars) {

Some files were not shown because too many files have changed in this diff Show More