Skip to content

Commit af75ea2

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

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

Process.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ protected function isSigchildEnabled()
13951395
ob_start();
13961396
phpinfo(\INFO_GENERAL);
13971397

1398-
return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
1398+
return self::$sigchild = str_contains(ob_get_clean(), '--enable-sigchild');
13991399
}
14001400

14011401
/**
@@ -1582,7 +1582,7 @@ function ($m) use (&$env, &$varCache, &$varCount, $uid) {
15821582
if (isset($varCache[$m[0]])) {
15831583
return $varCache[$m[0]];
15841584
}
1585-
if (false !== strpos($value = $m[1], "\0")) {
1585+
if (str_contains($value = $m[1], "\0")) {
15861586
$value = str_replace("\0", '?', $value);
15871587
}
15881588
if (false === strpbrk($value, "\"%!\n")) {
@@ -1643,7 +1643,7 @@ private function escapeArgument(?string $argument): string
16431643
if ('\\' !== \DIRECTORY_SEPARATOR) {
16441644
return "'".str_replace("'", "'\\''", $argument)."'";
16451645
}
1646-
if (false !== strpos($argument, "\0")) {
1646+
if (str_contains($argument, "\0")) {
16471647
$argument = str_replace("\0", '?', $argument);
16481648
}
16491649
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {

Tests/ErrorProcessInitiator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
$process = new Process("exec $php -r \"echo 'ready'; trigger_error('error', E_USER_ERROR);\"");
2323
$process->start();
2424
$process->setTimeout(0.5);
25-
while (false === strpos($process->getOutput(), 'ready')) {
25+
while (!str_contains($process->getOutput(), 'ready')) {
2626
usleep(1000);
2727
}
2828
$process->signal(\SIGSTOP);

Tests/ProcessTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function setUpBeforeClass(): void
3939

4040
ob_start();
4141
phpinfo(\INFO_GENERAL);
42-
self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
42+
self::$sigchild = str_contains(ob_get_clean(), '--enable-sigchild');
4343
}
4444

4545
protected function tearDown(): void
@@ -114,7 +114,7 @@ public function testStopWithTimeoutIsActuallyWorking()
114114
$p = $this->getProcess([self::$phpBin, __DIR__.'/NonStopableProcess.php', 30]);
115115
$p->start();
116116

117-
while ($p->isRunning() && false === strpos($p->getOutput(), 'received')) {
117+
while ($p->isRunning() && !str_contains($p->getOutput(), 'received')) {
118118
usleep(1000);
119119
}
120120

@@ -143,7 +143,7 @@ public function testWaitUntilSpecificOutput()
143143

144144
$completeOutput = '';
145145
$result = $p->waitUntil(function ($type, $output) use (&$completeOutput) {
146-
return false !== strpos($completeOutput .= $output, 'One more');
146+
return str_contains($completeOutput .= $output, 'One more');
147147
});
148148
$this->assertTrue($result);
149149
$this->assertLessThan(20, microtime(true) - $start);
@@ -409,7 +409,7 @@ public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
409409
$p->start();
410410

411411
foreach (['foo', 'bar'] as $s) {
412-
while (false === strpos($p->$getOutput(), $s)) {
412+
while (!str_contains($p->$getOutput(), $s)) {
413413
usleep(1000);
414414
}
415415

@@ -842,7 +842,7 @@ public function testIdleTimeoutNotExceededWhenOutputIsSent()
842842
$process->setTimeout(1);
843843
$process->start();
844844

845-
while (false === strpos($process->getOutput(), 'foo')) {
845+
while (!str_contains($process->getOutput(), 'foo')) {
846846
usleep(1000);
847847
}
848848

@@ -907,7 +907,7 @@ public function testSignal()
907907
$process = $this->getProcess([self::$phpBin, __DIR__.'/SignalListener.php']);
908908
$process->start();
909909

910-
while (false === strpos($process->getOutput(), 'Caught')) {
910+
while (!str_contains($process->getOutput(), 'Caught')) {
911911
usleep(1000);
912912
}
913913
$process->signal(\SIGUSR1);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.1.3"
19+
"php": ">=7.1.3",
20+
"symfony/polyfill-php80": "^1.16"
2021
},
2122
"autoload": {
2223
"psr-4": { "Symfony\\Component\\Process\\": "" },

0 commit comments

Comments
 (0)