• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / dresscode / 41232180578

31 Oct 2026 06:57PM UTC coverage: 97.034% (-0.06%) from 97.095%
41232180578

push

github

dg
upgrade: the plan file refuses a name that is no package and a constraint Composer does not read, with the path of the key, rather than handing them to Composer

837123ff-7353-45e9-8cd7-ba68b373e93e

13 of 13 new or added lines in 3 files covered. (100.0%)

141 existing lines in 12 files now uncovered.

27840 of 28691 relevant lines covered (97.03%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.27
/src/Engine/ProcessRunner.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the DressCode, a coding style and upgrade tool for PHP (https://dresscode.run)
5
 * Copyright (c) 2026 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace DressCode\Engine;
9

10
use function is_string;
11
use const PHP_OS_FAMILY;
12

13

14
/**
15
 * Runs a command and ends one that does not end in time: on Windows as a whole tree, the shell, the command and what it
16
 * started, elsewhere the program, which a list of arguments runs without a shell.
17
 * @internal
18
 */
19
final class ProcessRunner
20
{
21
        /**
22
         * The exit code and the output of both streams, the exit code null where the command did not end in time.
23
         * @param  string|list<string>  $command  a command line, or its program and arguments to quote
24
         * @return array{?int, string}
25
         */
26
        public static function run(string|array $command, string $cwd, int $timeout): array
27
        {
28
                // the shell of Windows is what finds `composer.bat`
29
                $command = is_string($command) || PHP_OS_FAMILY !== 'Windows'
1 ✔
30
                        ? $command
1 ✔
UNCOV
31
                        : implode(' ', array_map(escapeshellarg(...), $command));
×
32
                $process = proc_open($command, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes, $cwd);
1 ✔
33
                if ($process === false) {
1 ✔
UNCOV
34
                        return [127, 'The command could not be started.'];
×
35
                }
36

37
                fclose($pipes[0]);
1 ✔
38
                stream_set_blocking($pipes[1], enable: false);
1 ✔
39
                stream_set_blocking($pipes[2], enable: false);
1 ✔
40
                $output = '';
1 ✔
41
                $deadline = microtime(as_float: true) + $timeout;
1 ✔
42
                while (($status = proc_get_status($process))['running'] && microtime(as_float: true) < $deadline) {
1 ✔
43
                        $output .= stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
1 ✔
44
                        usleep(20_000);
1 ✔
45
                }
46

47
                $output .= stream_get_contents($pipes[1]) . stream_get_contents($pipes[2]);
1 ✔
48
                if ($status['running']) {
1 ✔
49
                        // proc_terminate() would end the shell alone and leave what it started orphaned
UNCOV
50
                        PHP_OS_FAMILY === 'Windows' ? exec("taskkill /F /T /PID $status[pid] 2>NUL") : proc_terminate($process);
×
51
                        proc_close($process);
×
52
                        return [null, $output];
×
53
                }
54

55
                proc_close($process);
1 ✔
56
                return [$status['exitcode'], $output];
1 ✔
57
        }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc