Skip to content

Commit 8132e8d

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 5ea0e23 commit 8132e8d

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

Definition/ArrayNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function preNormalize($value)
5555
$normalized = [];
5656

5757
foreach ($value as $k => $v) {
58-
if (false !== strpos($k, '-') && false === strpos($k, '_') && !\array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
58+
if (str_contains($k, '-') && !str_contains($k, '_') && !\array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
5959
$normalized[$normalizedKey] = $v;
6060
} else {
6161
$normalized[$k] = $v;

Definition/BaseNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract class BaseNode implements NodeInterface
4747
*/
4848
public function __construct(?string $name, NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
4949
{
50-
if (false !== strpos($name = (string) $name, $pathSeparator)) {
50+
if (str_contains($name = (string) $name, $pathSeparator)) {
5151
throw new \InvalidArgumentException('The name must not contain ".'.$pathSeparator.'".');
5252
}
5353

@@ -514,7 +514,7 @@ private static function resolvePlaceholderValue($value)
514514
}
515515

516516
foreach (self::$placeholderUniquePrefixes as $placeholderUniquePrefix) {
517-
if (0 === strpos($value, $placeholderUniquePrefix)) {
517+
if (str_starts_with($value, $placeholderUniquePrefix)) {
518518
return [];
519519
}
520520
}

Loader/FileLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public function getLocator()
7373
*/
7474
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null/*, $exclude = null*/)
7575
{
76-
if (\func_num_args() < 5 && __CLASS__ !== static::class && 0 !== strpos(static::class, 'Symfony\Component\\') && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
76+
if (\func_num_args() < 5 && __CLASS__ !== static::class && !str_starts_with(static::class, 'Symfony\Component\\') && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
7777
@trigger_error(sprintf('The "%s()" method will have a new "$exclude = null" argument in version 5.0, not defining it is deprecated since Symfony 4.4.', __METHOD__), \E_USER_DEPRECATED);
7878
}
7979
$exclude = \func_num_args() >= 5 ? func_get_arg(4) : null;
8080

81-
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && false === strpos($resource, "\n")) {
81+
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && !str_contains($resource, "\n")) {
8282
$excluded = [];
8383
foreach ((array) $exclude as $pattern) {
8484
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {
@@ -88,7 +88,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
8888
}
8989

9090
$ret = [];
91-
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
91+
$isSubpath = 0 !== $i && str_contains(substr($resource, 0, $i), '/');
9292
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath, false, $excluded) as $path => $info) {
9393
if (null !== $res = $this->doImport($path, 'glob' === $type ? null : $type, $ignoreErrors, $sourceResource)) {
9494
$ret[] = $res;
@@ -112,7 +112,7 @@ protected function glob(string $pattern, bool $recursive, &$resource = null, boo
112112
if (\strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
113113
$prefix = $pattern;
114114
$pattern = '';
115-
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
115+
} elseif (0 === $i || !str_contains(substr($pattern, 0, $i), '/')) {
116116
$prefix = '.';
117117
$pattern = '/'.$pattern;
118118
} else {

Resource/ComposerResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static function refresh()
5555
self::$runtimeVendors = [];
5656

5757
foreach (get_declared_classes() as $class) {
58-
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
58+
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
5959
$r = new \ReflectionClass($class);
6060
$v = \dirname($r->getFileName(), 2);
6161
if (file_exists($v.'/composer/installed.json')) {

Resource/GlobResource.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ public function getIterator()
110110
$prefix = str_replace('\\', '/', $this->prefix);
111111
$paths = null;
112112

113-
if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/')) {
114-
if ($this->globBrace || false === strpos($this->pattern, '{')) {
113+
if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
114+
if ($this->globBrace || !str_contains($this->pattern, '{')) {
115115
$paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace);
116-
} elseif (false === strpos($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
116+
} elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
117117
foreach ($this->expandGlob($this->pattern) as $p) {
118118
$paths[] = glob($this->prefix.$p, \GLOB_NOSORT);
119119
}
@@ -226,7 +226,7 @@ private function expandGlob(string $pattern): array
226226

227227
$j = 0;
228228
foreach ($patterns as $i => $p) {
229-
if (false !== strpos($p, '{')) {
229+
if (str_contains($p, '{')) {
230230
$p = $this->expandGlob($p);
231231
array_splice($paths, $i + $j, 1, $p);
232232
$j += \count($p) - 1;

Resource/ReflectionClassResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function loadFiles(\ReflectionClass $class)
8383
$file = $class->getFileName();
8484
if (false !== $file && file_exists($file)) {
8585
foreach ($this->excludedVendors as $vendor) {
86-
if (0 === strpos($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
86+
if (str_starts_with($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
8787
$file = false;
8888
break;
8989
}

Tests/Resource/ComposerResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testGetVendor()
2525
$found = false;
2626

2727
foreach ($res->getVendors() as $vendor) {
28-
if ($vendor && 0 === strpos($r->getFileName(), $vendor)) {
28+
if ($vendor && str_starts_with($r->getFileName(), $vendor)) {
2929
$found = true;
3030
break;
3131
}

0 commit comments

Comments
 (0)