Skip to content

Commit bf72df1

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

File tree

10 files changed

+17
-17
lines changed

10 files changed

+17
-17
lines changed

Caster/ClassStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(string $identifier, $callable = null)
5555
}
5656
}
5757

58-
if (false !== strpos($identifier, "@anonymous\0")) {
58+
if (str_contains($identifier, "@anonymous\0")) {
5959
$this->value = $identifier = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
6060
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
6161
}, $identifier);

Caster/ExceptionCaster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
149149
$f = self::castFrameStub($frame, [], $frame, true);
150150
if (isset($f[$prefix.'src'])) {
151151
foreach ($f[$prefix.'src']->value as $label => $frame) {
152-
if (0 === strpos($label, "\0~collapse=0")) {
152+
if (str_starts_with($label, "\0~collapse=0")) {
153153
if ($collapse) {
154154
$label = substr_replace($label, '1', 11, 1);
155155
} else {
@@ -281,7 +281,7 @@ private static function filterExceptionArray(string $xClass, array $a, string $x
281281
}
282282
unset($a[$xPrefix.'string'], $a[Caster::PREFIX_DYNAMIC.'xdebug_message'], $a[Caster::PREFIX_DYNAMIC.'__destructorException']);
283283

284-
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && false !== strpos($a[Caster::PREFIX_PROTECTED.'message'], "@anonymous\0")) {
284+
if (isset($a[Caster::PREFIX_PROTECTED.'message']) && str_contains($a[Caster::PREFIX_PROTECTED.'message'], "@anonymous\0")) {
285285
$a[Caster::PREFIX_PROTECTED.'message'] = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
286286
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
287287
}, $a[Caster::PREFIX_PROTECTED.'message']);

Caster/LinkStub.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function __construct(string $label, int $line = 0, string $href = null)
3333
if (!\is_string($href)) {
3434
return;
3535
}
36-
if (0 === strpos($href, 'file://')) {
36+
if (str_starts_with($href, 'file://')) {
3737
if ($href === $label) {
3838
$label = substr($label, 7);
3939
}
4040
$href = substr($href, 7);
41-
} elseif (false !== strpos($href, '://')) {
41+
} elseif (str_contains($href, '://')) {
4242
$this->attr['href'] = $href;
4343

4444
return;
@@ -69,7 +69,7 @@ private function getComposerRoot(string $file, bool &$inVendor)
6969
self::$vendorRoots = [];
7070

7171
foreach (get_declared_classes() as $class) {
72-
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
72+
if ('C' === $class[0] && str_starts_with($class, 'ComposerAutoloaderInit')) {
7373
$r = new \ReflectionClass($class);
7474
$v = \dirname($r->getFileName(), 2);
7575
if (file_exists($v.'/composer/installed.json')) {
@@ -85,7 +85,7 @@ private function getComposerRoot(string $file, bool &$inVendor)
8585
}
8686

8787
foreach (self::$vendorRoots as $root) {
88-
if ($inVendor = 0 === strpos($file, $root)) {
88+
if ($inVendor = str_starts_with($file, $root)) {
8989
return $root;
9090
}
9191
}

Caster/MemcachedCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static function getOptionConstants(): array
7171

7272
$optionConstants = [];
7373
foreach ($reflectedMemcached->getConstants() as $constantKey => $value) {
74-
if (0 === strpos($constantKey, 'OPT_')) {
74+
if (str_starts_with($constantKey, 'OPT_')) {
7575
$optionConstants[$constantKey] = $value;
7676
}
7777
}

Caster/ReflectionCaster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested,
4242

4343
$a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter);
4444

45-
if (false === strpos($c->name, '{closure}')) {
45+
if (!str_contains($c->name, '{closure}')) {
4646
$stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name;
4747
unset($a[$prefix.'class']);
4848
}
@@ -353,7 +353,7 @@ public static function getSignature(array $a)
353353
} elseif (\is_array($v)) {
354354
$signature .= $v ? '[…'.\count($v).']' : '[]';
355355
} elseif (\is_string($v)) {
356-
$signature .= 10 > \strlen($v) && false === strpos($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
356+
$signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
357357
} elseif (\is_bool($v)) {
358358
$signature .= $v ? 'true' : 'false';
359359
} else {

Cloner/AbstractCloner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ protected function castObject(Stub $stub, $isNested)
300300
$obj = $stub->value;
301301
$class = $stub->class;
302302

303-
if (\PHP_VERSION_ID < 80000 ? "\0" === ($class[15] ?? null) : false !== strpos($class, "@anonymous\0")) {
303+
if (\PHP_VERSION_ID < 80000 ? "\0" === ($class[15] ?? null) : str_contains($class, "@anonymous\0")) {
304304
$stub->class = get_debug_type($obj);
305305
}
306306
if (isset($this->classInfo[$class])) {

Dumper/CliDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function dumpScalar(Cursor $cursor, $type, $value)
154154
case is_nan($value): $value = 'NAN'; break;
155155
default:
156156
$value = (string) $value;
157-
if (false === strpos($value, $this->decimalPoint)) {
157+
if (!str_contains($value, $this->decimalPoint)) {
158158
$value .= $this->decimalPoint.'0';
159159
}
160160
break;
@@ -445,7 +445,7 @@ protected function style($style, $value, $attr = [])
445445

446446
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
447447
$prefix = substr($value, 0, -$attr['ellipsis']);
448-
if ('cli' === \PHP_SAPI && 'path' === $attr['ellipsis-type'] && isset($_SERVER[$pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD' : 'PWD']) && 0 === strpos($prefix, $_SERVER[$pwd])) {
448+
if ('cli' === \PHP_SAPI && 'path' === $attr['ellipsis-type'] && isset($_SERVER[$pwd = '\\' === \DIRECTORY_SEPARATOR ? 'CD' : 'PWD']) && str_starts_with($prefix, $_SERVER[$pwd])) {
449449
$prefix = '.'.substr($prefix, \strlen($_SERVER[$pwd]));
450450
}
451451
if (!empty($attr['ellipsis-tail'])) {

Dumper/ContextProvider/SourceContextProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getContext(): ?array
5656
$line = $trace[$i]['line'] ?? $line;
5757

5858
while (++$i < $this->limit) {
59-
if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && 0 !== strpos($trace[$i]['function'], 'call_user_func')) {
59+
if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && !str_starts_with($trace[$i]['function'], 'call_user_func')) {
6060
$file = $trace[$i]['file'];
6161
$line = $trace[$i]['line'];
6262

@@ -98,7 +98,7 @@ public function getContext(): ?array
9898

9999
if (null !== $this->projectDir) {
100100
$context['project_dir'] = $this->projectDir;
101-
if (0 === strpos($file, $this->projectDir)) {
101+
if (str_starts_with($file, $this->projectDir)) {
102102
$context['file_relative'] = ltrim(substr($file, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR);
103103
}
104104
}

Server/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Connection
3131
*/
3232
public function __construct(string $host, array $contextProviders = [])
3333
{
34-
if (false === strpos($host, '://')) {
34+
if (!str_contains($host, '://')) {
3535
$host = 'tcp://'.$host;
3636
}
3737

Server/DumpServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DumpServer
3030

3131
public function __construct(string $host, LoggerInterface $logger = null)
3232
{
33-
if (false === strpos($host, '://')) {
33+
if (!str_contains($host, '://')) {
3434
$host = 'tcp://'.$host;
3535
}
3636

0 commit comments

Comments
 (0)