@@ -215,6 +215,11 @@ public function create( $_, $assoc_args ) {
215215 if ( ! Utils \get_flag_value ( $ assoc_args , 'skip-check ' ) ) {
216216 // phpcs:disable WordPress.DB.RestrictedFunctions
217217 $ mysql = mysqli_init ();
218+
219+ if ( ! $ mysql ) {
220+ WP_CLI ::error ( 'Database connection error. Could not initialize MySQLi. ' );
221+ }
222+
218223 mysqli_report ( MYSQLI_REPORT_STRICT );
219224 try {
220225 // Accept similar format to one used by parse_db_host() e.g. 'localhost:/tmp/mysql.sock'
@@ -259,12 +264,6 @@ public function create( $_, $assoc_args ) {
259264 }
260265 }
261266
262- if ( Utils \wp_version_compare ( '4.0 ' , '< ' ) ) {
263- $ assoc_args ['add-wplang ' ] = true ;
264- } else {
265- $ assoc_args ['add-wplang ' ] = false ;
266- }
267-
268267 foreach ( $ assoc_args as $ key => $ value ) {
269268 $ assoc_args [ $ key ] = $ this ->escape_config_value ( $ key , $ value );
270269 }
@@ -319,7 +318,7 @@ private function config_file_already_exist_error( $wp_config_file_name ) {
319318 public function edit ( $ _ , $ assoc_args ) {
320319 $ path = $ this ->get_config_path ( $ assoc_args );
321320 $ wp_config_file_name = basename ( $ path );
322- $ contents = file_get_contents ( $ path );
321+ $ contents = ( string ) file_get_contents ( $ path );
323322 $ r = Utils \launch_editor_for_input ( $ contents , $ wp_config_file_name , 'php ' );
324323 if ( false === $ r ) {
325324 WP_CLI ::warning ( "No changes made to {$ wp_config_file_name }, aborted. " );
@@ -415,7 +414,7 @@ public function path() {
415414 public function list_ ( $ args , $ assoc_args ) {
416415 $ path = $ this ->get_config_path ( $ assoc_args );
417416 $ wp_config_file_name = basename ( $ path );
418- $ strict = Utils \get_flag_value ( $ assoc_args , 'strict ' );
417+ $ strict = ( bool ) Utils \get_flag_value ( $ assoc_args , 'strict ' );
419418 if ( $ strict && empty ( $ args ) ) {
420419 WP_CLI ::error ( 'The --strict option can only be used in combination with a filter. ' );
421420 }
@@ -569,7 +568,9 @@ private static function get_wp_config_vars( $wp_config_path = '' ) {
569568 }
570569 }
571570
572- unset( $ wp_config_vars [ $ name_backup ] );
571+ if ( isset ( $ name_backup ) ) {
572+ unset( $ wp_config_vars [ $ name_backup ] );
573+ }
573574 $ wp_config_vars = array_values ( $ wp_config_vars );
574575 $ wp_config_includes = array_diff ( get_included_files (), $ wp_cli_original_includes );
575576 $ wp_config_includes_array = [];
@@ -648,7 +649,11 @@ public function set( $args, $assoc_args ) {
648649 $ path = $ this ->get_config_path ( $ assoc_args );
649650 $ wp_config_file_name = basename ( $ path );
650651 list ( $ name , $ value ) = $ args ;
651- $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
652+
653+ /**
654+ * @var string $type
655+ */
656+ $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
652657
653658 $ options = [];
654659
@@ -661,8 +666,14 @@ public function set( $args, $assoc_args ) {
661666 ];
662667
663668 foreach ( $ option_flags as $ option => $ default ) {
669+ /**
670+ * @var string|null $option_value
671+ */
664672 $ option_value = Utils \get_flag_value ( $ assoc_args , $ option , $ default );
665673 if ( null !== $ option_value ) {
674+ /**
675+ * @var array<string, string> $options
676+ */
666677 $ options [ $ option ] = $ option_value ;
667678 if ( 'separator ' === $ option ) {
668679 $ options ['separator ' ] = $ this ->parse_separator ( $ options ['separator ' ] );
@@ -752,7 +763,11 @@ public function delete( $args, $assoc_args ) {
752763 $ path = $ this ->get_config_path ( $ assoc_args );
753764 $ wp_config_file_name = basename ( $ path );
754765 list ( $ name ) = $ args ;
755- $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
766+
767+ /**
768+ * @var string $type
769+ */
770+ $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
756771
757772 try {
758773 $ config_transformer = new WPConfigTransformer ( $ path );
@@ -819,7 +834,11 @@ public function has( $args, $assoc_args ) {
819834 $ path = $ this ->get_config_path ( $ assoc_args );
820835 $ wp_config_file_name = basename ( $ path );
821836 list ( $ name ) = $ args ;
822- $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
837+
838+ /**
839+ * @var string $type
840+ */
841+ $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
823842
824843 try {
825844 $ config_transformer = new WPConfigTransformer ( $ path , true );
@@ -836,6 +855,7 @@ public function has( $args, $assoc_args ) {
836855 } else {
837856 WP_CLI ::halt ( 0 );
838857 }
858+ // @phpstan-ignore deadCode.unreachable
839859 break ;
840860 case 'constant ' :
841861 case 'variable ' :
@@ -993,7 +1013,7 @@ private static function fetch_remote_salts( $insecure = false ) {
9931013 }
9941014
9951015 // Adapt whitespace to adhere to WPCS.
996- $ salts = preg_replace ( '/define\( \'(.*?) \'\);/ ' , 'define( \'$1 \' ); ' , $ salts );
1016+ $ salts = ( string ) preg_replace ( '/define\( \'(.*?) \'\);/ ' , 'define( \'$1 \' ); ' , $ salts );
9971017
9981018 return $ salts ;
9991019 }
@@ -1153,7 +1173,11 @@ protected function get_value( $assoc_args, $args ) {
11531173 $ path = $ this ->get_config_path ( $ assoc_args );
11541174 $ wp_config_file_name = basename ( $ path );
11551175 list ( $ name ) = $ args ;
1156- $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
1176+
1177+ /**
1178+ * @var string $type
1179+ */
1180+ $ type = Utils \get_flag_value ( $ assoc_args , 'type ' );
11571181
11581182 $ value = $ this ->return_value (
11591183 $ name ,
0 commit comments