|
5 | 5 | use WP_CLI; |
6 | 6 | use WP_CLI\Utils; |
7 | 7 |
|
| 8 | +/** |
| 9 | + * @phpstan-type ComposerConfig array{name: string, description: string, extra: array{readme: array{shields: array<string>}, commands: array<string>}, require: array<string, string>, 'require-dev': array<string, string>} |
| 10 | + */ |
8 | 11 | class ScaffoldPackageCommand { |
9 | 12 |
|
10 | 13 | /** |
@@ -43,13 +46,13 @@ class ScaffoldPackageCommand { |
43 | 46 | * [--require_wp_cli=<version>] |
44 | 47 | * : Required WP-CLI version for the package. |
45 | 48 | * --- |
46 | | - * default: ^2.11 |
| 49 | + * default: ^2.12 |
47 | 50 | * --- |
48 | 51 | * |
49 | 52 | * [--require_wp_cli_tests=<version>] |
50 | 53 | * : Required WP-CLI testing framework version for the package. |
51 | 54 | * --- |
52 | | - * default: ^4.3.9 |
| 55 | + * default: ^5.0.0 |
53 | 56 | * --- |
54 | 57 |
|
55 | 58 | * [--skip-tests] |
@@ -242,7 +245,10 @@ public function package_readme( $args, $assoc_args ) { |
242 | 245 |
|
243 | 246 | self::check_if_valid_package_dir( $package_dir ); |
244 | 247 |
|
245 | | - $composer_obj = json_decode( file_get_contents( $package_dir . '/composer.json' ), true ); |
| 248 | + /** |
| 249 | + * @var null|ComposerConfig $composer_obj |
| 250 | + */ |
| 251 | + $composer_obj = json_decode( (string) file_get_contents( $package_dir . '/composer.json' ), true ); |
246 | 252 | if ( ! $composer_obj ) { |
247 | 253 | WP_CLI::error( 'Invalid composer.json in package directory.' ); |
248 | 254 | } |
@@ -334,8 +340,8 @@ public function package_readme( $args, $assoc_args ) { |
334 | 340 | */ |
335 | 341 |
|
336 | 342 | $longdesc = isset( $parent_command['longdesc'] ) ? $parent_command['longdesc'] : ''; |
337 | | - $longdesc = preg_replace( '/## GLOBAL PARAMETERS(.+)/s', '', $longdesc ); |
338 | | - $longdesc = preg_replace( '/##\s(.+)/', '**$1**', $longdesc ); |
| 343 | + $longdesc = (string) preg_replace( '/## GLOBAL PARAMETERS(.+)/s', '', $longdesc ); |
| 344 | + $longdesc = (string) preg_replace( '/##\s(.+)/', '**$1**', $longdesc ); |
339 | 345 |
|
340 | 346 | // definition lists |
341 | 347 | $longdesc = preg_replace_callback( '/([^\n]+)\n: (.+?)(\n\n|$)/s', [ __CLASS__, 'rewrap_param_desc' ], $longdesc ); |
@@ -405,7 +411,9 @@ public function package_readme( $args, $assoc_args ) { |
405 | 411 | $v = $composer_obj['extra']['readme'][ $section ][ $k ]; |
406 | 412 | if ( filter_var( $v, FILTER_VALIDATE_URL ) === $v ) { |
407 | 413 | $response = Utils\http_request( 'GET', $v ); |
408 | | - $v = $response->body; |
| 414 | + |
| 415 | + // @phpstan-ignore class.notFound |
| 416 | + $v = $response->body; |
409 | 417 | } elseif ( preg_match( $ext_regex, $v ) ) { |
410 | 418 | $v = $package_dir . '/' . $v; |
411 | 419 | } |
@@ -479,7 +487,10 @@ public function package_github( $args, $assoc_args ) { |
479 | 487 | $force = Utils\get_flag_value( $assoc_args, 'force' ); |
480 | 488 | $template_path = dirname( __DIR__ ) . '/templates'; |
481 | 489 |
|
482 | | - $composer_obj = json_decode( file_get_contents( $package_dir . '/composer.json' ), true ); |
| 490 | + /** |
| 491 | + * @var ComposerConfig $composer_obj |
| 492 | + */ |
| 493 | + $composer_obj = json_decode( (string) file_get_contents( $package_dir . '/composer.json' ), true ); |
483 | 494 | $settings_vars = [ |
484 | 495 | 'has_description' => false, |
485 | 496 | 'description' => '', |
@@ -709,27 +720,10 @@ public function package_tests( $args, $assoc_args ) { |
709 | 720 | $files_written = []; |
710 | 721 | foreach ( $copy_source as $source => $to_copy ) { |
711 | 722 | foreach ( $to_copy as $file => $dir ) { |
712 | | - if ( 'php/WP_CLI/ProcessRun.php' === $file && ! file_exists( $source . "/{$file}" ) ) { |
713 | | - continue; |
714 | | - } |
715 | 723 | // file_get_contents() works with Phar-archived files |
716 | | - $contents = file_get_contents( $source . "/{$file}" ); |
| 724 | + $contents = (string) file_get_contents( $source . "/{$file}" ); |
717 | 725 | $file_path = $dir . basename( $file ); |
718 | 726 |
|
719 | | - if ( '.travis.yml' === $file ) { |
720 | | - foreach ( $travis_tags as $travis_tag ) { |
721 | | - if ( isset( $travis_tag_overwrites[ $travis_tag ] ) ) { |
722 | | - // Note the contents fully overwrite, so should include the tag, eg `env:` etc (or nothing if want to remove totally). |
723 | | - $contents = preg_replace( '/^' . $travis_tag . ':.*?(?:^$|\z)/ms', $travis_tag_overwrites[ $travis_tag ], $contents ); |
724 | | - } elseif ( isset( $travis_tag_appends[ $travis_tag ] ) ) { |
725 | | - $contents = preg_replace( '/^' . $travis_tag . ':.*?(?:^$|\z)/ms', '\0' . $travis_tag_appends[ $travis_tag ], $contents ); |
726 | | - } |
727 | | - } |
728 | | - if ( $travis_append ) { |
729 | | - $contents .= $travis_append; |
730 | | - } |
731 | | - } |
732 | | - |
733 | 727 | $force = Utils\get_flag_value( $assoc_args, 'force' ); |
734 | 728 | $should_write_file = $this->prompt_if_files_will_be_overwritten( $file_path, $force ); |
735 | 729 | if ( ! $should_write_file ) { |
|
0 commit comments