Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
level: 9
paths:
- src
- shell-command.php
scanDirectories:
- vendor/wp-cli/wp-cli/php
scanFiles:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
treatPhpDocTypesAsCertain: false
ignoreErrors:
- identifier: class.notFound
- identifier: missingType.property
- identifier: missingType.parameter
- identifier: missingType.return
21 changes: 14 additions & 7 deletions src/Shell_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class Shell_Command extends WP_CLI_Command {
* => string(6) "WP-CLI"
*/
public function __invoke( $_, $assoc_args ) {
$class = WP_CLI\Shell\REPL::class;

$implementations = array(
'Psy\\Shell',
'Boris\\Boris',
'WP_CLI\\Shell\\REPL',
\Psy\Shell::class,
\Boris\Boris::class,
WP_CLI\Shell\REPL::class,
);

if ( Utils\get_flag_value( $assoc_args, 'basic' ) ) {
$class = 'WP_CLI\\Shell\\REPL';
} else {
if ( ! Utils\get_flag_value( $assoc_args, 'basic' ) ) {
foreach ( $implementations as $candidate ) {
if ( class_exists( $candidate ) ) {
$class = $candidate;
Expand All @@ -44,10 +44,17 @@ public function __invoke( $_, $assoc_args ) {
}
}

if ( 'Psy\\Shell' === $class ) {
/**
* @var class-string $class
*/

if ( \Psy\Shell::class === $class ) {
$shell = new Psy\Shell();
$shell->run();
} else {
/**
* @var class-string<WP_CLI\Shell\REPL> $class
*/
$repl = new $class( 'wp> ' );
$repl->start();
}
Expand Down
14 changes: 9 additions & 5 deletions src/WP_CLI/Shell/REPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct( $prompt ) {
}

public function start() {
// @phpstan-ignore while.alwaysTrue
while ( true ) {
$line = $this->prompt();

Expand All @@ -30,7 +31,7 @@ public function start() {
ob_start();
// phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval.
eval( $line );
$out = ob_get_clean();
$out = (string) ob_get_clean();
if ( 0 < strlen( $out ) ) {
$out = rtrim( $out, "\n" ) . "\n";
}
Expand All @@ -44,13 +45,13 @@ public function start() {
ob_start();
// phpcs:ignore Squiz.PHP.Eval.Discouraged -- This is meant to be a REPL, no way to avoid eval.
$evl = eval( $line );
$out = ob_get_clean();
$out = (string) ob_get_clean();
if ( 0 < strlen( $out ) ) {
echo rtrim( $out, "\n" ) . "\n";
}
echo '=> ';
var_dump( $evl );
fwrite( STDOUT, ob_get_clean() );
fwrite( STDOUT, (string) ob_get_clean() );
}
}
}
Expand Down Expand Up @@ -82,13 +83,16 @@ private function prompt() {

$done = false;
do {
// @phpstan-ignore booleanNot.alwaysTrue
$prompt = ( ! $done && false !== $full_line ) ? '--> ' : $this->prompt;

$fp = popen( self::create_prompt_cmd( $prompt, $this->history_file ), 'r' );

$line = fgets( $fp );
$line = $fp ? fgets( $fp ) : '';

pclose( $fp );
if ( $fp ) {
pclose( $fp );
}

if ( ! $line ) {
break;
Expand Down