Skip to content

Commit 5ad1f8e

Browse files
authored
Merge branch 'main' into copilot/add-github-actions-for-handbook
2 parents 55e7175 + 7aa361f commit 5ad1f8e

File tree

14 files changed

+1099
-844
lines changed

14 files changed

+1099
-844
lines changed

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
labels:
9+
- scope:distribution
10+
- package-ecosystem: github-actions
11+
directory: "/"
12+
schedule:
13+
interval: daily
14+
open-pull-requests-limit: 10
15+
labels:
16+
- scope:distribution
17+

bin/command.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace WP_CLI\Handbook;
77

8-
use Mustache_Engine;
8+
use Mustache\Engine as Mustache_Engine;
99
use Reflection;
1010
use WP_CLI;
1111
use WP_CLI\Utils;
@@ -28,6 +28,10 @@ class Command {
2828
* : If set will list command pages as they are generated.
2929
*
3030
* @subcommand gen-all
31+
*
32+
* @param string[] $args Positional arguments. Unused.
33+
* @param array{verbose?: bool} $assoc_args Associative arguments.
34+
* @return void
3135
*/
3236
public function gen_all( $args, $assoc_args ) {
3337
// Warn if not invoked with null WP_CLI_CONFIG_PATH.
@@ -43,7 +47,7 @@ public function gen_all( $args, $assoc_args ) {
4347
WP_CLI::success( 'Generated all doc pages.' );
4448
}
4549

46-
private function prepare_api_slug( $full_name ) {
50+
private function prepare_api_slug( string $full_name ): string {
4751
$replacements = [
4852
'\\w+' => '',
4953
'\\s' => '',
@@ -68,6 +72,8 @@ private function prepare_api_slug( $full_name ) {
6872
* Generates internal API doc pages.
6973
*
7074
* @subcommand gen-api-docs
75+
*
76+
* @return void
7177
*/
7278
public function gen_api_docs() {
7379
$apis = $this->get_internal_apis();
@@ -147,6 +153,8 @@ function ( $parameter ) {
147153
* Generates Behat steps doc pages.
148154
*
149155
* @subcommand gen-behat-docs
156+
*
157+
* @return void
150158
*/
151159
public function gen_behat_docs() {
152160
$apis = $this->get_behat_steps();
@@ -227,6 +235,10 @@ function ( $parameter ) {
227235
* : If set will list command pages as they are generated.
228236
*
229237
* @subcommand gen-commands
238+
*
239+
* @param string[] $args Positional arguments. Unused.
240+
* @param array{verbose?: bool} $assoc_args Associative arguments.
241+
* @return void
230242
*/
231243
public function gen_commands( $args, $assoc_args ) {
232244
// Check invoked with packages directory set to `bin/packages'.
@@ -269,6 +281,11 @@ public function gen_commands( $args, $assoc_args ) {
269281

270282
/**
271283
* Update the commands data array with new data
284+
*
285+
* @param WP_CLI\Dispatcher\CompositeCommand $command
286+
* @param array<string, array{repo_url: string}> $commands_data
287+
* @param string $full
288+
* @return void
272289
*/
273290
private static function update_commands_data( $command, &$commands_data, $full ) {
274291
$reflection = new \ReflectionClass( $command );
@@ -324,6 +341,8 @@ private static function update_commands_data( $command, &$commands_data, $full )
324341
* Generates a manifest document of all command pages.
325342
*
326343
* @subcommand gen-commands-manifest
344+
*
345+
* @return void
327346
*/
328347
public function gen_commands_manifest() {
329348
$manifest = [];
@@ -386,6 +405,8 @@ public function gen_commands_manifest() {
386405
* Generates a manifest document of all handbook pages.
387406
*
388407
* @subcommand gen-hb-manifest
408+
*
409+
* @return void
389410
*/
390411
public function gen_hb_manifest() {
391412
$manifest = [];
@@ -402,7 +423,7 @@ public function gen_hb_manifest() {
402423
new \RecursiveCallbackFilterIterator(
403424
new \RecursiveDirectoryIterator( WP_CLI_HANDBOOK_PATH, \RecursiveDirectoryIterator::SKIP_DOTS ),
404425
static function ( $file ) use ( $ignored_dirs ) {
405-
/** @var SplFileInfo $file */
426+
/** @var \SplFileInfo $file */
406427

407428
if ( $file->isDir() && in_array( $file->getBasename(), $ignored_dirs, true ) ) {
408429
return false;
@@ -460,6 +481,9 @@ static function ( $file ) use ( $ignored_dirs ) {
460481
WP_CLI::success( 'Generated bin/handbook-manifest.json' );
461482
}
462483

484+
/**
485+
* @return array<int,array{phpdoc: array<string, mixed>, type: string, signature: string, short_name: string, full_name: string, class: string, api_slug?: string}>
486+
*/
463487
private function get_internal_apis() {
464488
$apis = [];
465489
$functions = get_defined_functions();
@@ -492,6 +516,9 @@ private function get_internal_apis() {
492516
return $apis;
493517
}
494518

519+
/**
520+
* @return array<int, array{phpdoc: array<string, mixed>, type: string, signature: string, short_name: string, full_name: string, class: string, api_slug?: string}>
521+
*/
495522
private function get_behat_steps() {
496523
$apis = [];
497524
$classes = [
@@ -517,6 +544,12 @@ private function get_behat_steps() {
517544
return $apis;
518545
}
519546

547+
/**
548+
* @param array<string, mixed> $cmd
549+
* @param string[] $parent
550+
* @param bool $verbose
551+
* @return void
552+
*/
520553
private static function gen_cmd_pages( $cmd, $parent = [], $verbose = false ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.parentFound
521554
$parent[] = $cmd['name'];
522555

@@ -649,6 +682,10 @@ private static function gen_cmd_pages( $cmd, $parent = [], $verbose = false ) {
649682
}
650683
$docs = preg_replace( '/(#?## GLOBAL PARAMETERS).+/s', $replace_global, $docs );
651684

685+
// Add link to argument syntax documentation after OPTIONS heading.
686+
$options_note = 'See the [argument syntax](https://make.wordpress.org/cli/handbook/references/argument-syntax/) reference for a detailed explanation of the syntax conventions used.';
687+
$docs = preg_replace( '/(### OPTIONS)/', '$1' . PHP_EOL . PHP_EOL . $options_note, $docs );
688+
652689
$binding['docs'] = $docs;
653690
}
654691

@@ -673,8 +710,8 @@ private static function gen_cmd_pages( $cmd, $parent = [], $verbose = false ) {
673710
/**
674711
* Get a simple representation of a function or method
675712
*
676-
* @param Reflection
677-
* @return array
713+
* @param \ReflectionMethod|\ReflectionFunction $reflection
714+
* @return array{phpdoc: array<string, mixed>, type: string, signature: string, short_name: string, full_name: string, class: string, api_slug?: string}
678715
*/
679716
private static function get_simple_representation( $reflection ) {
680717
$signature = $reflection->getName();
@@ -738,7 +775,7 @@ private static function get_simple_representation( $reflection ) {
738775
* Parse PHPDoc into a structured representation.
739776
*
740777
* @param string $docblock
741-
* @return array
778+
* @return array{description: string, short_description?: string, long_description?:string, behat_step?: string, parameters: array<string, mixed>}
742779
*/
743780
private static function parse_docblock( $docblock ) {
744781
$ret = [
@@ -797,7 +834,11 @@ private static function parse_docblock( $docblock ) {
797834
return $ret;
798835
}
799836

800-
private static function render( $path, $binding ) {
837+
/**
838+
* @param string $path
839+
* @param array<string, array<int, array<string, array<string, mixed>|string>>> $binding
840+
*/
841+
private static function render( string $path, $binding ): string {
801842
$m = new Mustache_Engine();
802843
$template = file_get_contents( WP_CLI_HANDBOOK_PATH . "/bin/templates/$path" );
803844
return $m->render( $template, $binding );
@@ -807,6 +848,8 @@ private static function render( $path, $binding ) {
807848
* Removes existing contents of given directory.
808849
*
809850
* @param string $dir Name of directory to empty.
851+
*
852+
* @return void
810853
*/
811854
private static function empty_dir( $dir ) {
812855
$cmd = Utils\esc_cmd( 'rm -rf %s', $dir );

0 commit comments

Comments
 (0)