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

keradus / PHP-CS-Fixer / 17293274407

28 Aug 2025 10:35AM UTC coverage: 94.693%. Remained the same
17293274407

push

github

web-flow
chore: Add TODO for ENUM conversion in ProgressOutputType (#8991)

28316 of 29903 relevant lines covered (94.69%)

45.61 hits per line

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

0.0
/src/Runner/Parallel/ProcessUtils.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz RumiƄski <dariusz.ruminski@gmail.com>
10
 *
11
 * This file was copied (and slightly modified) from Symfony:
12
 * - https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Process/ProcessUtils.php#L41
13
 * - (c) Fabien Potencier <fabien@symfony.com>
14
 * - For the full copyright and license information, please see https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Process/LICENSE
15
 *
16
 * This source file is subject to the MIT license that is bundled
17
 * with this source code in the file LICENSE.
18
 */
19

20
namespace PhpCsFixer\Runner\Parallel;
21

22
/**
23
 * @internal
24
 *
25
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
26
 */
27
final class ProcessUtils
28
{
29
    /**
30
     * This class should not be instantiated.
31
     */
32
    private function __construct() {}
33

34
    /**
35
     * Escapes a string to be used as a shell argument.
36
     *
37
     * @param string $argument The argument that will be escaped
38
     *
39
     * @return string The escaped argument
40
     */
41
    public static function escapeArgument(string $argument): string
42
    {
43
        // Fix for PHP bug #43784 escapeshellarg removes % from given string
44
        // Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
45
        // @see https://bugs.php.net/43784
46
        // @see https://bugs.php.net/49446
47
        if ('\\' === \DIRECTORY_SEPARATOR) {
×
48
            if ('' === $argument) {
×
49
                return escapeshellarg($argument);
×
50
            }
51

52
            $escapedArgument = '';
×
53
            $quote = false;
×
54
            foreach (preg_split('/(")/', $argument, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE) as $part) { // @phpstan-ignore foreach.nonIterable
×
55
                if ('"' === $part) {
×
56
                    $escapedArgument .= '\"';
×
57
                } elseif (self::isSurroundedBy($part, '%')) {
×
58
                    // Avoid environment variable expansion
59
                    $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
×
60
                } else {
61
                    // escape trailing backslash
62
                    if ('\\' === substr($part, -1)) {
×
63
                        $part .= '\\';
×
64
                    }
65
                    $quote = true;
×
66
                    $escapedArgument .= $part;
×
67
                }
68
            }
69
            if ($quote) {
×
70
                $escapedArgument = '"'.$escapedArgument.'"';
×
71
            }
72

73
            return $escapedArgument;
×
74
        }
75

76
        return "'".str_replace("'", "'\\''", $argument)."'";
×
77
    }
78

79
    private static function isSurroundedBy(string $arg, string $char): bool
80
    {
81
        return 2 < \strlen($arg) && $char === $arg[0] && $char === $arg[\strlen($arg) - 1];
×
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc