@@ -77,7 +77,7 @@ public function __invoke( $args, $assoc_args ) {
77
77
$ this ->checker = new GitIgnoreChecker ( $ source_dir_path , '.distignore ' );
78
78
$ dist_ignore_filepath = $ source_dir_path . '/.distignore ' ;
79
79
if ( file_exists ( $ dist_ignore_filepath ) ) {
80
- $ file_ignore_rules = explode ( PHP_EOL , file_get_contents ( $ dist_ignore_filepath ) );
80
+ $ file_ignore_rules = explode ( PHP_EOL , ( string ) file_get_contents ( $ dist_ignore_filepath ) );
81
81
} else {
82
82
WP_CLI ::warning ( 'No .distignore file found. All files in directory included in archive. ' );
83
83
$ file_ignore_rules = [];
@@ -124,6 +124,8 @@ public function __invoke( $args, $assoc_args ) {
124
124
125
125
chdir ( dirname ( $ source_path ) );
126
126
127
+ $ cmd = "zip -r ' {$ archive_absolute_filepath }' {$ archive_output_dir_name }" ;
128
+
127
129
// If the files are being zipped in place, we need the exclusion rules.
128
130
// whereas if they were copied for any reasons above, the rules have already been applied.
129
131
if ( $ source_path !== $ source_dir_path || empty ( $ file_ignore_rules ) ) {
@@ -175,10 +177,14 @@ function ( $ignored_file ) use ( $source_path ) {
175
177
$ escape_whitelist = 'targz ' === $ assoc_args ['format ' ] ? array ( '^ ' , '* ' ) : array ();
176
178
WP_CLI ::debug ( "Running: {$ cmd }" , 'dist-archive ' );
177
179
$ escaped_shell_command = $ this ->escapeshellcmd ( $ cmd , $ escape_whitelist );
178
- $ ret = WP_CLI ::launch ( $ escaped_shell_command , false , true );
180
+
181
+ /**
182
+ * @var WP_CLI\ProcessRun $ret
183
+ */
184
+ $ ret = WP_CLI ::launch ( $ escaped_shell_command , false , true );
179
185
if ( 0 === $ ret ->return_code ) {
180
186
$ filename = pathinfo ( $ archive_absolute_filepath , PATHINFO_BASENAME );
181
- $ file_size = $ this ->get_size_format ( filesize ( $ archive_absolute_filepath ), 2 );
187
+ $ file_size = $ this ->get_size_format ( ( int ) filesize ( $ archive_absolute_filepath ), 2 );
182
188
183
189
WP_CLI ::success ( "Created {$ filename } (Size: {$ file_size }) " );
184
190
} else {
@@ -201,7 +207,7 @@ function ( $ignored_file ) use ( $source_path ) {
201
207
private function get_file_paths_and_names ( $ args , $ assoc_args ) {
202
208
203
209
$ source_dir_path = realpath ( $ args [0 ] );
204
- if ( ! is_dir ( $ source_dir_path ) ) {
210
+ if ( ! $ source_dir_path || ! is_dir ( $ source_dir_path ) ) {
205
211
WP_CLI ::error ( 'Provided input path is not a directory. ' );
206
212
}
207
213
@@ -239,7 +245,7 @@ private function get_file_paths_and_names( $args, $assoc_args ) {
239
245
240
246
$ destination_dir_path = realpath ( $ destination_dir_path );
241
247
242
- if ( ! is_dir ( $ destination_dir_path ) ) {
248
+ if ( ! $ destination_dir_path || ! is_dir ( $ destination_dir_path ) ) {
243
249
WP_CLI ::error ( "Target directory does not exist: {$ destination_dir_path }" );
244
250
}
245
251
@@ -285,33 +291,42 @@ private function get_version( $source_dir_path ) {
285
291
* @link https://developer.wordpress.org/reference/functions/get_file_data/
286
292
*/
287
293
if ( file_exists ( $ source_dir_path . '/style.css ' ) ) {
288
- $ contents = file_get_contents ( $ source_dir_path . '/style.css ' , false , null , 0 , 5000 );
294
+ $ contents = ( string ) file_get_contents ( $ source_dir_path . '/style.css ' , false , null , 0 , 5000 );
289
295
$ contents = str_replace ( "\r" , "\n" , $ contents );
290
296
$ pattern = '/^ ' . preg_quote ( 'Version ' , ', ' ) . ':(.*)$/mi ' ;
291
297
if ( preg_match ( $ pattern , $ contents , $ match ) && $ match [1 ] ) {
292
- $ version = trim ( preg_replace ( '/\s*(?:\*\/|\?>).*/ ' , '' , $ match [1 ] ) );
298
+ $ version = trim ( ( string ) preg_replace ( '/\s*(?:\*\/|\?>).*/ ' , '' , $ match [1 ] ) );
293
299
}
294
300
}
295
301
296
302
if ( empty ( $ version ) ) {
297
- foreach ( glob ( $ source_dir_path . '/*.php ' ) as $ php_file ) {
298
- $ contents = file_get_contents ( $ php_file , false , null , 0 , 5000 );
299
- $ version = $ this ->get_version_in_code ( $ contents );
300
- if ( ! empty ( $ version ) ) {
301
- $ version = trim ( $ version );
303
+ foreach ( (array ) glob ( $ source_dir_path . '/*.php ' ) as $ php_file ) {
304
+ if ( ! $ php_file ) {
305
+ continue ;
306
+ }
307
+ $ contents = (string ) file_get_contents ( $ php_file , false , null , 0 , 5000 );
308
+ $ ver = $ this ->get_version_in_code ( $ contents );
309
+ if ( ! empty ( $ ver ) ) {
310
+ $ version = trim ( $ ver );
302
311
break ;
303
312
}
304
313
}
305
314
}
306
315
307
316
if ( empty ( $ version ) && file_exists ( $ source_dir_path . '/composer.json ' ) ) {
308
- $ composer_obj = json_decode ( file_get_contents ( $ source_dir_path . '/composer.json ' ) );
309
- if ( ! empty ( $ composer_obj ->version ) ) {
317
+ /**
318
+ * @var null|object{version?: string} $composer_obj
319
+ */
320
+ $ composer_obj = json_decode ( (string ) file_get_contents ( $ source_dir_path . '/composer.json ' ) );
321
+ if ( $ composer_obj && ! empty ( $ composer_obj ->version ) ) {
310
322
$ version = trim ( $ composer_obj ->version );
311
323
}
312
324
}
313
325
314
326
if ( ! empty ( $ version ) && false !== stripos ( $ version , '-alpha ' ) && is_dir ( $ source_dir_path . '/.git ' ) ) {
327
+ /**
328
+ * @var WP_CLI\ProcessRun $response
329
+ */
315
330
$ response = WP_CLI ::launch ( "cd {$ source_dir_path }; git log --pretty=format:'%h' -n 1 " , false , true );
316
331
$ maybe_hash = trim ( $ response ->stdout );
317
332
if ( $ maybe_hash && 7 === strlen ( $ maybe_hash ) ) {
@@ -387,7 +402,7 @@ private function get_version_in_docblock( $docblock ) {
387
402
* @see https://github.com/phpactor/docblock/blob/master/lib/Parser.php
388
403
*
389
404
* @param string $docblock Docblock to parse.
390
- * @return array Associative array of parsed data.
405
+ * @return array<string, string> Associative array of parsed data.
391
406
*/
392
407
private function parse_doc_block ( $ docblock ) {
393
408
$ tag_documentor = '{@([a-zA-Z0-9-_ \\\]+)\s*?(.*)?} ' ;
@@ -402,7 +417,7 @@ private function parse_doc_block( $docblock ) {
402
417
}
403
418
}
404
419
405
- $ tag_name = strtolower ( $ matches [1 ] );
420
+ $ tag_name = trim ( isset ( $ matches [ 1 ] ) ? strtolower ( $ matches [1 ] ) : '' );
406
421
$ metadata = trim ( isset ( $ matches [2 ] ) ? $ matches [2 ] : '' );
407
422
408
423
$ tags [ $ tag_name ] = $ metadata ;
@@ -456,7 +471,6 @@ protected function is_path_contains_symlink( $source_dir_path ) {
456
471
);
457
472
458
473
/**
459
- * @var RecursiveIteratorIterator $iterator
460
474
* @var SplFileInfo $item
461
475
*/
462
476
foreach ( $ iterator as $ item ) {
@@ -487,7 +501,6 @@ private function get_file_list( $source_dir_path, $excluded = false ) {
487
501
);
488
502
489
503
/**
490
- * @var RecursiveIteratorIterator $iterator
491
504
* @var SplFileInfo $item
492
505
*/
493
506
foreach ( $ iterator as $ item ) {
@@ -499,7 +512,7 @@ private function get_file_list( $source_dir_path, $excluded = false ) {
499
512
$ included_files [] = $ relative_filepath ;
500
513
}
501
514
} catch ( \Inmarelibero \GitIgnoreChecker \Exception \InvalidArgumentException $ exception ) {
502
- if ( $ item ->isLink () && ! file_exists ( readlink ( $ item ->getPathname () ) ) ) {
515
+ if ( $ item ->isLink () && ! file_exists ( ( string ) readlink ( $ item ->getPathname () ) ) ) {
503
516
WP_CLI ::error ( "Broken symlink at {$ relative_filepath }. Target missing at {$ item ->getLinkTarget ()}. " );
504
517
} else {
505
518
WP_CLI ::error ( $ exception ->getMessage () );
0 commit comments