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

keradus / PHP-CS-Fixer / 17253245287

23 Aug 2025 07:51PM UTC coverage: 94.669% (-0.06%) from 94.728%
17253245287

push

github

keradus
phpstan

0 of 1 new or added line in 1 file covered. (0.0%)

180 existing lines in 15 files now uncovered.

28255 of 29846 relevant lines covered (94.67%)

45.84 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
final class ProcessUtils
26
{
27
    /**
28
     * This class should not be instantiated.
29
     */
30
    private function __construct() {}
31

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

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

71
            return $escapedArgument;
×
72
        }
73

74
        return "'".str_replace("'", "'\\''", $argument)."'";
×
75
    }
76

77
    private static function isSurroundedBy(string $arg, string $char): bool
78
    {
79
        return 2 < \strlen($arg) && $char === $arg[0] && $char === $arg[\strlen($arg) - 1];
×
80
    }
81
}
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