@@ -77,7 +77,7 @@ public function __invoke( $args, $assoc_args ) {
7777 $ this ->checker = new GitIgnoreChecker ( $ source_dir_path , '.distignore ' );
7878 $ dist_ignore_filepath = $ source_dir_path . '/.distignore ' ;
7979 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 ) );
8181 } else {
8282 WP_CLI ::warning ( 'No .distignore file found. All files in directory included in archive. ' );
8383 $ file_ignore_rules = [];
@@ -124,6 +124,8 @@ public function __invoke( $args, $assoc_args ) {
124124
125125 chdir ( dirname ( $ source_path ) );
126126
127+ $ cmd = "zip -r ' {$ archive_absolute_filepath }' {$ archive_output_dir_name }" ;
128+
127129 // If the files are being zipped in place, we need the exclusion rules.
128130 // whereas if they were copied for any reasons above, the rules have already been applied.
129131 if ( $ source_path !== $ source_dir_path || empty ( $ file_ignore_rules ) ) {
@@ -175,10 +177,14 @@ function ( $ignored_file ) use ( $source_path ) {
175177 $ escape_whitelist = 'targz ' === $ assoc_args ['format ' ] ? array ( '^ ' , '* ' ) : array ();
176178 WP_CLI ::debug ( "Running: {$ cmd }" , 'dist-archive ' );
177179 $ 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 );
179185 if ( 0 === $ ret ->return_code ) {
180186 $ 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 );
182188
183189 WP_CLI ::success ( "Created {$ filename } (Size: {$ file_size }) " );
184190 } else {
@@ -201,7 +207,7 @@ function ( $ignored_file ) use ( $source_path ) {
201207 private function get_file_paths_and_names ( $ args , $ assoc_args ) {
202208
203209 $ source_dir_path = realpath ( $ args [0 ] );
204- if ( ! is_dir ( $ source_dir_path ) ) {
210+ if ( ! $ source_dir_path || ! is_dir ( $ source_dir_path ) ) {
205211 WP_CLI ::error ( 'Provided input path is not a directory. ' );
206212 }
207213
@@ -239,7 +245,7 @@ private function get_file_paths_and_names( $args, $assoc_args ) {
239245
240246 $ destination_dir_path = realpath ( $ destination_dir_path );
241247
242- if ( ! is_dir ( $ destination_dir_path ) ) {
248+ if ( ! $ destination_dir_path || ! is_dir ( $ destination_dir_path ) ) {
243249 WP_CLI ::error ( "Target directory does not exist: {$ destination_dir_path }" );
244250 }
245251
@@ -285,33 +291,42 @@ private function get_version( $source_dir_path ) {
285291 * @link https://developer.wordpress.org/reference/functions/get_file_data/
286292 */
287293 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 );
289295 $ contents = str_replace ( "\r" , "\n" , $ contents );
290296 $ pattern = '/^ ' . preg_quote ( 'Version ' , ', ' ) . ':(.*)$/mi ' ;
291297 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 ] ) );
293299 }
294300 }
295301
296302 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 );
302311 break ;
303312 }
304313 }
305314 }
306315
307316 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 ) ) {
310322 $ version = trim ( $ composer_obj ->version );
311323 }
312324 }
313325
314326 if ( ! empty ( $ version ) && false !== stripos ( $ version , '-alpha ' ) && is_dir ( $ source_dir_path . '/.git ' ) ) {
327+ /**
328+ * @var WP_CLI\ProcessRun $response
329+ */
315330 $ response = WP_CLI ::launch ( "cd {$ source_dir_path }; git log --pretty=format:'%h' -n 1 " , false , true );
316331 $ maybe_hash = trim ( $ response ->stdout );
317332 if ( $ maybe_hash && 7 === strlen ( $ maybe_hash ) ) {
@@ -387,7 +402,7 @@ private function get_version_in_docblock( $docblock ) {
387402 * @see https://github.com/phpactor/docblock/blob/master/lib/Parser.php
388403 *
389404 * @param string $docblock Docblock to parse.
390- * @return array Associative array of parsed data.
405+ * @return array<string, string> Associative array of parsed data.
391406 */
392407 private function parse_doc_block ( $ docblock ) {
393408 $ tag_documentor = '{@([a-zA-Z0-9-_ \\\]+)\s*?(.*)?} ' ;
@@ -402,7 +417,7 @@ private function parse_doc_block( $docblock ) {
402417 }
403418 }
404419
405- $ tag_name = strtolower ( $ matches [1 ] );
420+ $ tag_name = trim ( isset ( $ matches [ 1 ] ) ? strtolower ( $ matches [1 ] ) : '' );
406421 $ metadata = trim ( isset ( $ matches [2 ] ) ? $ matches [2 ] : '' );
407422
408423 $ tags [ $ tag_name ] = $ metadata ;
@@ -456,7 +471,6 @@ protected function is_path_contains_symlink( $source_dir_path ) {
456471 );
457472
458473 /**
459- * @var RecursiveIteratorIterator $iterator
460474 * @var SplFileInfo $item
461475 */
462476 foreach ( $ iterator as $ item ) {
@@ -487,7 +501,6 @@ private function get_file_list( $source_dir_path, $excluded = false ) {
487501 );
488502
489503 /**
490- * @var RecursiveIteratorIterator $iterator
491504 * @var SplFileInfo $item
492505 */
493506 foreach ( $ iterator as $ item ) {
@@ -499,7 +512,7 @@ private function get_file_list( $source_dir_path, $excluded = false ) {
499512 $ included_files [] = $ relative_filepath ;
500513 }
501514 } 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 () ) ) ) {
503516 WP_CLI ::error ( "Broken symlink at {$ relative_filepath }. Target missing at {$ item ->getLinkTarget ()}. " );
504517 } else {
505518 WP_CLI ::error ( $ exception ->getMessage () );
0 commit comments