Skip to content

Commit 4268f30

Browse files
Merge branch '5.2' into 5.3
* 5.2: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents eb4670a + 32f6be0 commit 4268f30

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
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

@@ -542,7 +542,7 @@ private static function resolvePlaceholderValue($value)
542542
}
543543

544544
foreach (self::$placeholderUniquePrefixes as $placeholderUniquePrefix) {
545-
if (0 === strpos($value, $placeholderUniquePrefix)) {
545+
if (str_starts_with($value, $placeholderUniquePrefix)) {
546546
return [];
547547
}
548548
}

Loader/FileLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function getLocator()
7272
*/
7373
public function import($resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null, $exclude = null)
7474
{
75-
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && false === strpos($resource, "\n")) {
75+
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && !str_contains($resource, "\n")) {
7676
$excluded = [];
7777
foreach ((array) $exclude as $pattern) {
7878
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {
@@ -82,7 +82,7 @@ public function import($resource, string $type = null, bool $ignoreErrors = fals
8282
}
8383

8484
$ret = [];
85-
$isSubpath = 0 !== $i && false !== strpos(substr($resource, 0, $i), '/');
85+
$isSubpath = 0 !== $i && str_contains(substr($resource, 0, $i), '/');
8686
foreach ($this->glob($resource, false, $_, $ignoreErrors || !$isSubpath, false, $excluded) as $path => $info) {
8787
if (null !== $res = $this->doImport($path, 'glob' === $type ? null : $type, $ignoreErrors, $sourceResource)) {
8888
$ret[] = $res;
@@ -106,7 +106,7 @@ protected function glob(string $pattern, bool $recursive, &$resource = null, boo
106106
if (\strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
107107
$prefix = $pattern;
108108
$pattern = '';
109-
} elseif (0 === $i || false === strpos(substr($pattern, 0, $i), '/')) {
109+
} elseif (0 === $i || !str_contains(substr($pattern, 0, $i), '/')) {
110110
$prefix = '.';
111111
$pattern = '/'.$pattern;
112112
} 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 (is_file($v.'/composer/installed.json')) {

Resource/DirectoryResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function isFresh(int $timestamp): bool
8181

8282
// always monitor directories for changes, except the .. entries
8383
// (otherwise deleted files wouldn't get detected)
84-
if ($file->isDir() && '/..' === substr($file, -3)) {
84+
if ($file->isDir() && str_ends_with($file, '/..')) {
8585
continue;
8686
}
8787

Resource/GlobResource.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public function getIterator(): \Traversable
107107
$prefix = str_replace('\\', '/', $this->prefix);
108108
$paths = null;
109109

110-
if (0 !== strpos($this->prefix, 'phar://') && false === strpos($this->pattern, '/**/')) {
111-
if ($this->globBrace || false === strpos($this->pattern, '{')) {
110+
if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) {
111+
if ($this->globBrace || !str_contains($this->pattern, '{')) {
112112
$paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace);
113-
} elseif (false === strpos($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
113+
} elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) {
114114
foreach ($this->expandGlob($this->pattern) as $p) {
115115
$paths[] = glob($this->prefix.$p, \GLOB_NOSORT);
116116
}
@@ -223,7 +223,7 @@ private function expandGlob(string $pattern): array
223223

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

Resource/ReflectionClassResource.php

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

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
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.1",
2121
"symfony/filesystem": "^4.4|^5.0",
2222
"symfony/polyfill-ctype": "~1.8",
23-
"symfony/polyfill-php80": "^1.15",
23+
"symfony/polyfill-php80": "^1.16",
2424
"symfony/polyfill-php81": "^1.22"
2525
},
2626
"require-dev": {

0 commit comments

Comments
 (0)