Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f514f9

Browse files
committed
minor #45978 Leverage array_is_list(), get_debug_type(), is_countable(), is_iterable(), str_contains() and str_starts_with() (fancyweb)
This PR was merged into the 6.1 branch. Discussion ---------- Leverage array_is_list(), get_debug_type(), is_countable(), is_iterable(), str_contains() and str_starts_with() | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Found some things from the "past" again 😄 Commits ------- 2591262 Leverage array_is_list(), get_debug_type(), is_countable(), is_iterable(), str_contains() and str_starts_with()
2 parents f923f15 + 2591262 commit 1f514f9

File tree

13 files changed

+18
-18
lines changed

13 files changed

+18
-18
lines changed

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function loginUser(object $user, string $firewallContext = 'main'): stati
115115
}
116116

117117
if (!$user instanceof UserInterface) {
118-
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user)));
118+
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, get_debug_type($user)));
119119
}
120120

121121
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private function writeLine(string $text, int $indent = 0)
193193

194194
private function writeArray(array $array, int $depth)
195195
{
196-
$isIndexed = array_values($array) === $array;
196+
$isIndexed = array_is_list($array);
197197

198198
foreach ($array as $key => $value) {
199199
if (\is_array($value)) {

src/Symfony/Component/DomCrawler/Test/Constraint/CrawlerSelectorTextContains.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function matches($crawler): bool
5656
$this->hasNode = true;
5757
$this->nodeText = $crawler->text(null, true);
5858

59-
return false !== mb_strpos($this->nodeText, $this->expectedText);
59+
return str_contains($this->nodeText, $this->expectedText);
6060
}
6161

6262
/**

src/Symfony/Component/ErrorHandler/Resources/views/exception.html.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
$last = $exceptionAsArrayCount - 1;
3636
foreach ($exceptionAsArray as $i => $e) {
3737
foreach ($e['trace'] as $trace) {
38-
if ($trace['file'] && false === mb_strpos($trace['file'], '/vendor/') && false === mb_strpos($trace['file'], '/var/cache/') && $i < $last) {
38+
if ($trace['file'] && !str_contains($trace['file'], '/vendor/') && !str_contains($trace['file'], '/var/cache/') && $i < $last) {
3939
$exceptionWithUserCode[] = $i;
4040
}
4141
}

src/Symfony/Component/ErrorHandler/Resources/views/traces.html.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<?php
3232
$isFirstUserCode = true;
3333
foreach ($exception['trace'] as $i => $trace) {
34-
$isVendorTrace = $trace['file'] && (false !== mb_strpos($trace['file'], '/vendor/') || false !== mb_strpos($trace['file'], '/var/cache/'));
34+
$isVendorTrace = $trace['file'] && (str_contains($trace['file'], '/vendor/') || str_contains($trace['file'], '/var/cache/'));
3535
$displayCodeSnippet = $isFirstUserCode && !$isVendorTrace;
3636
if ($displayCodeSnippet) {
3737
$isFirstUserCode = false;

src/Symfony/Component/Filesystem/Path.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public static function makeRelative(string $path, string $basePath): string
574574
*/
575575
public static function isLocal(string $path): bool
576576
{
577-
return '' !== $path && false === mb_strpos($path, '://');
577+
return '' !== $path && !str_contains($path, '://');
578578
}
579579

580580
/**
@@ -638,7 +638,7 @@ public static function getLongestCommonBasePath(string ...$paths): ?string
638638

639639
// Prevent false positives for common prefixes
640640
// see isBasePath()
641-
if (0 === mb_strpos($path.'/', $basePath.'/')) {
641+
if (str_starts_with($path.'/', $basePath.'/')) {
642642
// next path
643643
continue 2;
644644
}
@@ -666,7 +666,7 @@ public static function join(string ...$paths): string
666666
if (null === $finalPath) {
667667
// For first part we keep slashes, like '/top', 'C:\' or 'phar://'
668668
$finalPath = $path;
669-
$wasScheme = (false !== mb_strpos($path, '://'));
669+
$wasScheme = str_contains($path, '://');
670670
continue;
671671
}
672672

@@ -717,7 +717,7 @@ public static function isBasePath(string $basePath, string $ofPath): bool
717717
// Don't append a slash for the root "/", because then that root
718718
// won't be discovered as common prefix ("//" is not a prefix of
719719
// "/foobar/").
720-
return 0 === mb_strpos($ofPath.'/', rtrim($basePath, '/').'/');
720+
return str_starts_with($ofPath.'/', rtrim($basePath, '/').'/');
721721
}
722722

723723
/**
@@ -786,7 +786,7 @@ private static function split(string $path): array
786786
$length = mb_strlen($path);
787787

788788
// Remove and remember root directory
789-
if (0 === mb_strpos($path, '/')) {
789+
if (str_starts_with($path, '/')) {
790790
$root .= '/';
791791
$path = $length > 1 ? mb_substr($path, 1) : '';
792792
} elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) {

src/Symfony/Component/Form/Form.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public function isEmpty(): bool
704704

705705
return FormUtil::isEmpty($this->modelData) ||
706706
// arrays, countables
707-
((\is_array($this->modelData) || $this->modelData instanceof \Countable) && 0 === \count($this->modelData)) ||
707+
(is_countable($this->modelData) && 0 === \count($this->modelData)) ||
708708
// traversables that are not countable
709709
($this->modelData instanceof \Traversable && 0 === iterator_count($this->modelData));
710710
}

src/Symfony/Component/HttpClient/MockHttpClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function request(string $method, string $url, array $options = []): Respo
8181
++$this->requestsCount;
8282

8383
if (!$response instanceof ResponseInterface) {
84-
throw new TransportException(sprintf('The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "%s" given.', \is_object($response) ? \get_class($response) : \gettype($response)));
84+
throw new TransportException(sprintf('The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "%s" given.', get_debug_type($response)));
8585
}
8686

8787
return MockResponse::fromRequest($method, $url, $options, $response);

src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function matches($message): bool
4343
throw new \LogicException('Unable to test a message HTML body on a RawMessage or Message instance.');
4444
}
4545

46-
return false !== mb_strpos($message->getHtmlBody(), $this->expectedText);
46+
return str_contains($message->getHtmlBody(), $this->expectedText);
4747
}
4848

4949
/**

src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function matches($message): bool
4343
throw new \LogicException('Unable to test a message text body on a RawMessage or Message instance.');
4444
}
4545

46-
return false !== mb_strpos($message->getTextBody(), $this->expectedText);
46+
return str_contains($message->getTextBody(), $this->expectedText);
4747
}
4848

4949
/**

src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function supports(Request $request): ?bool
9191
if (null !== $this->logger) {
9292
$context = ['firewall_name' => $this->firewallName];
9393

94-
if ($this->authenticators instanceof \Countable || \is_array($this->authenticators)) {
94+
if (is_countable($this->authenticators)) {
9595
$context['authenticators'] = \count($this->authenticators);
9696
}
9797

src/Symfony/Component/Semaphore/Store/RedisStore.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private function evaluate(string $script, string $resource, array $args): mixed
190190
return $this->redis->eval(...array_merge([$script, 1, $resource], $args));
191191
}
192192

193-
throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
193+
throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($this->redis)));
194194
}
195195

196196
private function getUniqueToken(Key $key): string

src/Symfony/Component/String/AbstractString.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ abstract public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF
558558
*/
559559
public function trimPrefix($prefix): static
560560
{
561-
if (\is_array($prefix) || $prefix instanceof \Traversable) {
561+
if (is_iterable($prefix)) {
562562
foreach ($prefix as $s) {
563563
$t = $this->trimPrefix($s);
564564

@@ -592,7 +592,7 @@ abstract public function trimStart(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FE
592592
*/
593593
public function trimSuffix($suffix): static
594594
{
595-
if (\is_array($suffix) || $suffix instanceof \Traversable) {
595+
if (is_iterable($suffix)) {
596596
foreach ($suffix as $s) {
597597
$t = $this->trimSuffix($s);
598598

0 commit comments

Comments
 (0)