Skip to content

Commit 5731331

Browse files
CS fixes - native_function_invocation & static_lambda
1 parent 736ed52 commit 5731331

6 files changed

Lines changed: 28 additions & 28 deletions

File tree

Pipes/WindowsPipes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(mixed $input, bool $haveReadSupport)
5050
];
5151
$tmpDir = sys_get_temp_dir();
5252
$lastError = 'unknown reason';
53-
set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; });
53+
set_error_handler(static function ($type, $msg) use (&$lastError) { $lastError = $msg; });
5454
for ($i = 0;; ++$i) {
5555
foreach ($pipes as $pipe => $name) {
5656
$file = \sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);

Process.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ private function getDescriptors(bool $hasCallback): array
12611261
protected function buildCallback(?callable $callback = null): \Closure
12621262
{
12631263
if ($this->outputDisabled) {
1264-
return fn ($type, $data): bool => null !== $callback && $callback($type, $data);
1264+
return static fn ($type, $data): bool => null !== $callback && $callback($type, $data);
12651265
}
12661266

12671267
$out = self::OUT;
@@ -1499,7 +1499,7 @@ private function prepareWindowsCommandLine(string $cmd, array &$env): string
14991499
[^"%!^]*+
15001500
)++
15011501
) | [^"]*+ )"/x',
1502-
function ($m) use (&$env, $uid) {
1502+
static function ($m) use (&$env, $uid) {
15031503
static $varCount = 0;
15041504
static $varCache = [];
15051505
if (!isset($m[1])) {

Tests/ExecutableFinderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function testEmptyDirInPath()
153153

154154
try {
155155
touch('executable');
156-
chmod('executable', 0700);
156+
chmod('executable', 0o700);
157157

158158
$finder = new ExecutableFinder();
159159
$result = $finder->find('executable');

Tests/PipeStdinInStdoutStdErrStreamSelect.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
define('ERR_SELECT_FAILED', 1);
13-
define('ERR_TIMEOUT', 2);
14-
define('ERR_READ_FAILED', 3);
15-
define('ERR_WRITE_FAILED', 4);
12+
\define('ERR_SELECT_FAILED', 1);
13+
\define('ERR_TIMEOUT', 2);
14+
\define('ERR_READ_FAILED', 3);
15+
\define('ERR_WRITE_FAILED', 4);
1616

1717
$read = [\STDIN];
1818
$write = [\STDOUT, \STDERR];
@@ -34,7 +34,7 @@
3434
exit(ERR_TIMEOUT);
3535
}
3636

37-
if (in_array(\STDOUT, $w) && '' !== $out) {
37+
if (\in_array(\STDOUT, $w) && '' !== $out) {
3838
$written = fwrite(\STDOUT, (string) $out, 32768);
3939
if (false === $written) {
4040
exit(ERR_WRITE_FAILED);
@@ -45,7 +45,7 @@
4545
$write = array_diff($write, [\STDOUT]);
4646
}
4747

48-
if (in_array(\STDERR, $w) && '' !== $err) {
48+
if (\in_array(\STDERR, $w) && '' !== $err) {
4949
$written = fwrite(\STDERR, (string) $err, 32768);
5050
if (false === $written) {
5151
exit(ERR_WRITE_FAILED);

Tests/ProcessTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function testWaitUntilSpecificOutput()
141141
$start = microtime(true);
142142

143143
$completeOutput = '';
144-
$result = $p->waitUntil(function ($type, $output) use (&$completeOutput) {
144+
$result = $p->waitUntil(static function ($type, $output) use (&$completeOutput) {
145145
return str_contains($completeOutput .= $output, 'One more');
146146
});
147147
$this->assertTrue($result);
@@ -154,7 +154,7 @@ public function testWaitUntilCanReturnFalse()
154154
{
155155
$p = $this->getProcess('echo foo');
156156
$p->start();
157-
$this->assertFalse($p->waitUntil(fn () => false));
157+
$this->assertFalse($p->waitUntil(static fn () => false));
158158
}
159159

160160
public function testAllOutputIsActuallyReadOnTermination()
@@ -191,7 +191,7 @@ public function testAllOutputIsActuallyReadOnTermination()
191191
public function testCallbacksAreExecutedWithStart()
192192
{
193193
$process = $this->getProcess('echo foo');
194-
$process->start(function ($type, $buffer) use (&$data) {
194+
$process->start(static function ($type, $buffer) use (&$data) {
195195
$data .= $buffer;
196196
});
197197

@@ -209,7 +209,7 @@ public function testReadSupportIsDisabledWithoutCallback()
209209
// disabling output + not passing a callback to start() => read support disabled
210210
$process->disableOutput();
211211
$process->start();
212-
$process->wait(function ($type, $buffer) use (&$data) {
212+
$process->wait(static function ($type, $buffer) use (&$data) {
213213
$data .= $buffer;
214214
});
215215
}
@@ -275,7 +275,7 @@ public function testLiveStreamAsInput()
275275

276276
$p = $this->getProcessForCode('stream_copy_to_stream(STDIN, STDOUT);');
277277
$p->setInput($stream);
278-
$p->start(function ($type, $data) use ($stream) {
278+
$p->start(static function ($type, $data) use ($stream) {
279279
if ('hello' === $data) {
280280
fclose($stream);
281281
}
@@ -369,7 +369,7 @@ public function testCallbackIsExecutedForOutput()
369369
$p = $this->getProcessForCode('echo \'foo\';');
370370

371371
$called = false;
372-
$p->run(function ($type, $buffer) use (&$called) {
372+
$p->run(static function ($type, $buffer) use (&$called) {
373373
$called = 'foo' === $buffer;
374374
});
375375

@@ -382,7 +382,7 @@ public function testCallbackIsExecutedForOutputWheneverOutputIsDisabled()
382382
$p->disableOutput();
383383

384384
$called = false;
385-
$p->run(function ($type, $buffer) use (&$called) {
385+
$p->run(static function ($type, $buffer) use (&$called) {
386386
$called = 'foo' === $buffer;
387387
});
388388

@@ -1152,7 +1152,7 @@ public static function provideOutputFetchingMethods()
11521152
public function testStopTerminatesProcessCleanly()
11531153
{
11541154
$process = $this->getProcessForCode('echo 123; sleep(42);');
1155-
$process->run(function () use ($process) {
1155+
$process->run(static function () use ($process) {
11561156
$process->stop();
11571157
});
11581158
$this->assertTrue(true, 'A call to stop() is not expected to cause wait() to throw a RuntimeException');
@@ -1161,7 +1161,7 @@ public function testStopTerminatesProcessCleanly()
11611161
public function testKillSignalTerminatesProcessCleanly()
11621162
{
11631163
$process = $this->getProcessForCode('echo 123; sleep(43);');
1164-
$process->run(function () use ($process) {
1164+
$process->run(static function () use ($process) {
11651165
$process->signal(9); // SIGKILL
11661166
});
11671167
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
@@ -1170,7 +1170,7 @@ public function testKillSignalTerminatesProcessCleanly()
11701170
public function testTermSignalTerminatesProcessCleanly()
11711171
{
11721172
$process = $this->getProcessForCode('echo 123; sleep(44);');
1173-
$process->run(function () use ($process) {
1173+
$process->run(static function () use ($process) {
11741174
$process->signal(15); // SIGTERM
11751175
});
11761176
$this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
@@ -1239,7 +1239,7 @@ public static function provideVariousIncrementals()
12391239

12401240
public function testIteratorInput()
12411241
{
1242-
$input = function () {
1242+
$input = static function () {
12431243
yield 'ping';
12441244
yield 'pong';
12451245
};
@@ -1256,7 +1256,7 @@ public function testSimpleInputStream()
12561256
$process = $this->getProcessForCode('echo \'ping\'; echo fread(STDIN, 4); echo fread(STDIN, 4);');
12571257
$process->setInput($input);
12581258

1259-
$process->start(function ($type, $data) use ($input) {
1259+
$process->start(static function ($type, $data) use ($input) {
12601260
if ('ping' === $data) {
12611261
$input->write('pang');
12621262
} elseif (!$input->isClosed()) {
@@ -1273,7 +1273,7 @@ public function testInputStreamWithCallable()
12731273
{
12741274
$i = 0;
12751275
$stream = fopen('php://memory', 'w+');
1276-
$stream = function () use ($stream, &$i) {
1276+
$stream = static function () use ($stream, &$i) {
12771277
if ($i < 3) {
12781278
rewind($stream);
12791279
fwrite($stream, ++$i);
@@ -1291,7 +1291,7 @@ public function testInputStreamWithCallable()
12911291

12921292
$process = $this->getProcessForCode('echo fread(STDIN, 3);');
12931293
$process->setInput($input);
1294-
$process->start(function ($type, $data) use ($input) {
1294+
$process->start(static function ($type, $data) use ($input) {
12951295
$input->close();
12961296
});
12971297

@@ -1302,7 +1302,7 @@ public function testInputStreamWithCallable()
13021302
public function testInputStreamWithGenerator()
13031303
{
13041304
$input = new InputStream();
1305-
$input->onEmpty(function ($input) {
1305+
$input->onEmpty(static function ($input) {
13061306
yield 'pong';
13071307
$input->close();
13081308
});
@@ -1319,11 +1319,11 @@ public function testInputStreamOnEmpty()
13191319
{
13201320
$i = 0;
13211321
$input = new InputStream();
1322-
$input->onEmpty(function () use (&$i) { ++$i; });
1322+
$input->onEmpty(static function () use (&$i) { ++$i; });
13231323

13241324
$process = $this->getProcessForCode('echo 123; echo fread(STDIN, 1); echo 456;');
13251325
$process->setInput($input);
1326-
$process->start(function ($type, $data) use ($input) {
1326+
$process->start(static function ($type, $data) use ($input) {
13271327
if ('123' === $data) {
13281328
$input->close();
13291329
}

Tests/SignalListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
pcntl_signal(\SIGUSR1, function () {
12+
pcntl_signal(\SIGUSR1, static function () {
1313
echo 'SIGUSR1';
1414
exit;
1515
});

0 commit comments

Comments
 (0)