Skip to content

Commit 4c21f24

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent e0c1083 commit 4c21f24

24 files changed

+51
-51
lines changed

Alias.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function setDeprecated($status = true, $template = null)
103103
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
104104
}
105105

106-
if (false === strpos($template, '%alias_id%')) {
106+
if (!str_contains($template, '%alias_id%')) {
107107
throw new InvalidArgumentException('The deprecation template must contain the "%alias_id%" placeholder.');
108108
}
109109

ChildDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function replaceArgument($index, $value)
9797
{
9898
if (\is_int($index)) {
9999
$this->arguments['index_'.$index] = $value;
100-
} elseif (0 === strpos($index, '$')) {
100+
} elseif (str_starts_with($index, '$')) {
101101
$this->arguments[$index] = $value;
102102
} else {
103103
throw new InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.');

Compiler/AutowirePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private function getAutowiredReference(TypedReference $reference): ?TypedReferen
297297

298298
if ($this->container->has($name) && !$this->container->findDefinition($name)->isAbstract()) {
299299
foreach ($this->container->getAliases() as $id => $alias) {
300-
if ($name === (string) $alias && 0 === strpos($id, $type.' $')) {
300+
if ($name === (string) $alias && str_starts_with($id, $type.' $')) {
301301
return new TypedReference($name, $type, $reference->getInvalidBehavior());
302302
}
303303
}

Compiler/CheckDefinitionValidityPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function process(ContainerBuilder $container)
4949
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));
5050
}
5151
if (class_exists($id) || interface_exists($id, false)) {
52-
if (0 === strpos($id, '\\') && 1 < substr_count($id, '\\')) {
52+
if (str_starts_with($id, '\\') && 1 < substr_count($id, '\\')) {
5353
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)));
5454
}
5555

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
231231
$value = $this->container->getParameter(substr($value, 1, -1));
232232
}
233233

234-
if ($envPlaceholderUniquePrefix && \is_string($value) && false !== strpos($value, 'env_')) {
234+
if ($envPlaceholderUniquePrefix && \is_string($value) && str_contains($value, 'env_')) {
235235
// 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.
236236
// We don't need to change the value because it is already a string.
237237
if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) {

Compiler/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BE
6767
*/
6868
public function log(CompilerPassInterface $pass, string $message)
6969
{
70-
if (false !== strpos($message, "\n")) {
70+
if (str_contains($message, "\n")) {
7171
$message = str_replace("\n", "\n".\get_class($pass).': ', trim($message));
7272
}
7373

Compiler/MergeExtensionConfigurationPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs
209209
}
210210

211211
foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
212-
if (false === strpos($env, ':')) {
212+
if (!str_contains($env, ':')) {
213213
continue;
214214
}
215215
foreach ($placeholders as $placeholder) {

Compiler/RegisterServiceSubscribersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function processValue($value, $isRoot = false)
9191
if ($name) {
9292
if (false !== $i = strpos($name, '::get')) {
9393
$name = lcfirst(substr($name, 5 + $i));
94-
} elseif (false !== strpos($name, '::')) {
94+
} elseif (str_contains($name, '::')) {
9595
$name = null;
9696
}
9797
}

Compiler/ResolveBindingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
4444
foreach ($this->unusedBindings as [$key, $serviceId, $bindingType, $file]) {
4545
$argumentType = $argumentName = $message = null;
4646

47-
if (false !== strpos($key, ' ')) {
47+
if (str_contains($key, ' ')) {
4848
[$argumentType, $argumentName] = explode(' ', $key, 2);
4949
} elseif ('$' === $key[0]) {
5050
$argumentName = $key;

Compiler/ResolveChildDefinitionsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
158158
foreach ($definition->getArguments() as $k => $v) {
159159
if (is_numeric($k)) {
160160
$def->addArgument($v);
161-
} elseif (0 === strpos($k, 'index_')) {
161+
} elseif (str_starts_with($k, 'index_')) {
162162
$def->replaceArgument((int) substr($k, \strlen('index_')), $v);
163163
} else {
164164
$def->setArgument($k, $v);

0 commit comments

Comments
 (0)