@@ -20,58 +20,74 @@ public function start() {
2020 while ( true ) {
2121 $ line = $ this ->prompt ();
2222
23- if ( '' === $ line ) continue ;
23+ if ( '' === $ line ) {
24+ continue ;
25+ }
2426
2527 $ line = rtrim ( $ line , '; ' ) . '; ' ;
2628
2729 if ( self ::starts_with ( self ::non_expressions (), $ line ) ) {
2830 ob_start ();
2931 eval ( $ line );
3032 $ out = ob_get_clean ();
31- if ( 0 < strlen ( $ out ) ) {
33+ if ( 0 < strlen ( $ out ) ) {
3234 $ out = rtrim ( $ out , "\n" ) . "\n" ;
3335 }
3436 fwrite ( STDOUT , $ out );
3537 } else {
36- if ( !self ::starts_with ( 'return ' , $ line ) )
38+ if ( ! self ::starts_with ( 'return ' , $ line ) ) {
3739 $ line = 'return ' . $ line ;
40+ }
3841
3942 // Write directly to STDOUT, to sidestep any output buffers created by plugins
4043 ob_start ();
41- $ evl = eval ( $ line );
44+ $ evl = eval ( $ line );
4245 $ out = ob_get_clean ();
43- if ( 0 < strlen ( $ out ) ) {
46+ if ( 0 < strlen ( $ out ) ) {
4447 echo rtrim ( $ out , "\n" ) . "\n" ;
4548 }
46- echo " => " ;
49+ echo ' => ' ;
4750 var_dump ( $ evl );
4851 fwrite ( STDOUT , ob_get_clean () );
4952 }
5053 }
5154 }
5255
5356 private static function non_expressions () {
54- return implode ( '| ' , array (
55- 'echo ' , 'global ' , 'unset ' , 'function ' ,
56- 'while ' , 'for ' , 'foreach ' , 'if ' , 'switch ' ,
57- 'include ' , 'include\_once ' , 'require ' , 'require\_once '
58- ) );
57+ return implode (
58+ '| ' ,
59+ array (
60+ 'echo ' ,
61+ 'global ' ,
62+ 'unset ' ,
63+ 'function ' ,
64+ 'while ' ,
65+ 'for ' ,
66+ 'foreach ' ,
67+ 'if ' ,
68+ 'switch ' ,
69+ 'include ' ,
70+ 'include\_once ' ,
71+ 'require ' ,
72+ 'require\_once ' ,
73+ )
74+ );
5975 }
6076
6177 private function prompt () {
6278 $ full_line = false ;
6379
6480 $ done = false ;
6581 do {
66- $ prompt = ( !$ done && $ full_line !== false ) ? '--> ' : $ this ->prompt ;
82+ $ prompt = ( ! $ done && $ full_line !== false ) ? '--> ' : $ this ->prompt ;
6783
6884 $ fp = popen ( self ::create_prompt_cmd ( $ prompt , $ this ->history_file ), 'r ' );
6985
7086 $ line = fgets ( $ fp );
7187
7288 pclose ( $ fp );
7389
74- if ( !$ line ) {
90+ if ( ! $ line ) {
7591 break ;
7692 }
7793
@@ -85,7 +101,7 @@ private function prompt() {
85101
86102 $ full_line .= $ line ;
87103
88- } while ( !$ done );
104+ } while ( ! $ done );
89105
90106 if ( $ full_line === false ) {
91107 return 'exit ' ;
@@ -95,7 +111,7 @@ private function prompt() {
95111 }
96112
97113 private static function create_prompt_cmd ( $ prompt , $ history_path ) {
98- $ prompt = escapeshellarg ( $ prompt );
114+ $ prompt = escapeshellarg ( $ prompt );
99115 $ history_path = escapeshellarg ( $ history_path );
100116 if ( getenv ( 'WP_CLI_CUSTOM_SHELL ' ) ) {
101117 $ shell_binary = getenv ( 'WP_CLI_CUSTOM_SHELL ' );
@@ -109,14 +125,14 @@ private static function create_prompt_cmd( $prompt, $history_path ) {
109125
110126 $ shell_binary = escapeshellarg ( $ shell_binary );
111127
112- $ cmd = " set -f; "
128+ $ cmd = ' set -f; '
113129 . "history -r $ history_path; "
114- . " LINE= \"\ "; "
130+ . ' LINE=" "; '
115131 . "read -re -p $ prompt LINE; "
116- . " [ $? -eq 0 ] || exit; "
117- . " history -s \"\ $LINE \ "; "
132+ . ' [ $? -eq 0 ] || exit; '
133+ . ' history -s " $LINE"; '
118134 . "history -w $ history_path; "
119- . " echo \ $LINE; " ;
135+ . ' echo $LINE; ' ;
120136
121137 return "{$ shell_binary } -c " . escapeshellarg ( $ cmd );
122138 }
0 commit comments