Skip to content

Commit

Permalink
Fix Object Calisthenics violations on else variations
Browse files Browse the repository at this point in the history
  • Loading branch information
UrGuardian4ngel committed Dec 26, 2017
1 parent ffbe66e commit 13d23b5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Process/ProcessUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ProcessUtils
{
/**
* Escapes a string to be used as a shell argument.
* Taken from the Symfony package.
* Adapted from the Symfony package.
*
* @param string $argument The argument that will be escaped
*
Expand All @@ -37,17 +37,21 @@ public static function escapeArgument($argument)
foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
continue;
}

if (self::isSurroundedBy($part, '%')) {
// Avoid environment variable expansion
$escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
} else {
// escape trailing backslash
if ('\\' === substr($part, -1)) {
$part .= '\\';
}
$quote = true;
$escapedArgument .= $part;
continue;
}

// escape trailing backslash
if ('\\' === substr($part, -1)) {
$part .= '\\';
}
$quote = true;
$escapedArgument .= $part;
}
if ($quote) {
$escapedArgument = '"'.$escapedArgument.'"';
Expand Down

0 comments on commit 13d23b5

Please sign in to comment.