Skip to content

Commit

Permalink
chore(shell): improve type coverage (#292)
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Dec 1, 2021
1 parent ff5e481 commit 8eece3a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Psl/Shell/execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Psl\Async;
use Psl\Dict;
use Psl\Env;
use Psl\Filesystem;
use Psl\IO;
use Psl\IO\Stream;
use Psl\Regex;
use Psl\SecureRandom;
use Psl\Str;
use Psl\Vec;

use function is_dir;
use function is_resource;
use function proc_close;
use function proc_open;
Expand Down Expand Up @@ -72,7 +72,7 @@ function execute(

$environment = Dict\merge(Env\get_vars(), $environment);
$working_directory ??= Env\current_dir();
if (!is_dir($working_directory)) {
if (!Filesystem\is_directory($working_directory)) {
throw new Exception\RuntimeException('$working_directory does not exist.');
}

Expand Down Expand Up @@ -117,22 +117,29 @@ static function (array $m) use (
return '"' . $value . '"';
}

$value = Str\Byte\replace_every($value, ['!LF!' => "\n", '"^!"' => '!', '"^%"' => '%', '"^^"' => '^', '""' => '"']);
$value = '"' . Regex\replace($value, '/(\\\\*)"/', '$1$1\\"') . '"';
/**
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedOperand
* @var string $var
* @var int $variable_count
*/
$var = $identifier . ++$variable_count;
$var = $identifier . ((string) ++$variable_count);

/**
* @psalm-suppress MixedArrayAssignment
* @var array<string, string> $environment
*/
$environment[$var] = $value;
$environment[$var] = '"' . Regex\replace(
Str\Byte\replace_every(
$value,
['!LF!' => "\n", '"^!"' => '!', '"^%"' => '%', '"^^"' => '^', '""' => '"']
),
'/(\\\\*)"/',
'$1$1\\"',
) . '"';

/**
* @psalm-suppress MixedArrayOffset
* @psalm-suppress MixedArrayAssignment
*
* @var string
*/
return $variable_cache[$m[0]] = '!' . $var . '!';
},
Expand Down

0 comments on commit 8eece3a

Please sign in to comment.