Skip to content

Leverage str_contains/str_starts_with #41576

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
Jul 21, 2021
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php72": "~1.5",
"symfony/polyfill-php73": "^1.11",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-php80": "^1.16",
"symfony/polyfill-php81": "^1.22"
},
"replace": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function registerMappingDrivers($objectManager, ContainerBuilder $cont
]);
}
$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 @@ -68,7 +68,7 @@ public function getProperties($class, array $context = [])

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
}

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'])) {
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"doctrine/persistence": "^1.3|^2",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.1|^2"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'multiline' => OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity(),
]));

if (false === strpos($host = $input->getOption('host'), '://')) {
if (!str_contains($host = $input->getOption('host'), '://')) {
$host = 'tcp://'.$host;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function replacePlaceHolder(array $record): array
{
$message = $record['message'];

if (false === strpos($message, '{')) {
if (!str_contains($message, '{')) {
return $record;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(string $host, $level = Logger::DEBUG, bool $bubble =
{
parent::__construct($level, $bubble);

if (false === strpos($host, '://')) {
if (!str_contains($host, '://')) {
$host = 'tcp://'.$host;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Monolog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"php": ">=7.1.3",
"monolog/monolog": "^1.25.1",
"symfony/service-contracts": "^1.1|^2",
"symfony/http-kernel": "^4.3"
"symfony/http-kernel": "^4.3",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"symfony/console": "^3.4|^4.0|^5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function generate(\ReflectionClass $originalClass, ClassGenerator $classG
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()));
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/ProxyManager/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"php": ">=7.1.3",
"composer/package-versions-deprecated": "^1.8",
"friendsofphp/proxy-manager-lts": "^1.0.2",
"symfony/dependency-injection": "^4.0|^5.0"
"symfony/dependency-injection": "^4.0|^5.0",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"symfony/config": "^3.4|^4.0|^5.0"
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,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 @@ -259,7 +259,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 @@ -409,7 +409,7 @@ private function findWrongBundleOverrides(): array
$folders = glob($this->rootDir.'/Resources/*/views', \GLOB_ONLYDIR);
$relativePath = ltrim(substr($this->rootDir.\DIRECTORY_SEPARATOR.'Resources/', \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(\dirname($absolutePath));
$path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR);
$carry[$name] = $path;
Expand All @@ -425,7 +425,7 @@ private function findWrongBundleOverrides(): array
$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;
Expand Down Expand Up @@ -555,7 +555,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 All @@ -569,7 +569,7 @@ private function findAlternatives(string $name, array $collection): array

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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function abbrClass($class)

public function abbrMethod($method)
{
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 @@ -219,7 +219,7 @@ public function getFileRelative(string $file): ?string
{
$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)), '/');
}

Expand All @@ -238,7 +238,7 @@ public function formatFileFromText($text)
*/
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
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=7.1.3",
"symfony/polyfill-php80": "^1.16",
"symfony/translation-contracts": "^1.1|^2",
"twig/twig": "^1.43|^2.13|^3.0.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function load(array $configs, ContainerBuilder $container)
$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'))
;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/DebugBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"php": ">=7.1.3",
"ext-xml": "*",
"symfony/http-kernel": "^3.4|^4.0|^5.0",
"symfony/polyfill-php80": "^1.16",
"symfony/twig-bridge": "^3.4|^4.0|^5.0",
"symfony/var-dumper": "^4.1.1|^5.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function getScript($request)

$requires = '';
foreach (get_declared_classes() as $class) {
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
if (str_starts_with($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$file = \dirname($r->getFileName(), 2).'/autoload.php';
if (file_exists($file)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$mount = implode(' ', $mount).'/';

if (0 === strpos($realCacheDir, $mount)) {
if (str_starts_with($realCacheDir, $mount)) {
$io->note('For better performances, you should move the cache and log directories to a non-shared folder of the VM.');
$oldCacheDir = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
$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)) {
Expand All @@ -295,7 +295,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 @@ -104,7 +104,7 @@ private function getContainerBuilder(): ContainerBuilder

$skippedIds = [];
foreach ($container->getServiceIds() as $serviceId) {
if (0 === strpos($serviceId, '.errored.')) {
if (str_starts_with($serviceId, '.errored.')) {
$skippedIds[$serviceId] = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

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)) {
Expand All @@ -104,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
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])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct()
};

$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
};

parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
};

$isReadableProvider = function ($fileOrDirectory, $default) {
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
};

parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function getCallableData($callable): array
$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;
Expand All @@ -304,7 +304,7 @@ private function getCallableData($callable): array
if (\is_string($callable)) {
$data['type'] = 'function';

if (false === strpos($callable, '::')) {
if (!str_contains($callable, '::')) {
$data['name'] = $callable;
} else {
$callableParts = explode('::', $callable);
Expand All @@ -321,7 +321,7 @@ private function getCallableData($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 @@ -300,7 +300,7 @@ protected function describeCallable($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_starts_with($callable[1], 'parent::')) {
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
$string .= "\n".sprintf('- Class: `%s`', $callable[0]);
$string .= "\n- Static: yes";
Expand All @@ -318,7 +318,7 @@ protected function describeCallable($callable, array $options = [])
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);
Expand All @@ -335,7 +335,7 @@ protected function describeCallable($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 @@ -514,7 +514,7 @@ private function formatControllerLink($controller, string $anchorText): string
$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 @@ -547,7 +547,7 @@ private function formatCallable($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