55
66namespace WP_CLI \Handbook ;
77
8- use Mustache_Engine ;
8+ use Mustache \ Engine as Mustache_Engine ;
99use Reflection ;
1010use WP_CLI ;
1111use 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
@@ -677,8 +710,8 @@ private static function gen_cmd_pages( $cmd, $parent = [], $verbose = false ) {
677710 /**
678711 * Get a simple representation of a function or method
679712 *
680- * @param Reflection
681- * @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}
682715 */
683716 private static function get_simple_representation ( $ reflection ) {
684717 $ signature = $ reflection ->getName ();
@@ -742,7 +775,7 @@ private static function get_simple_representation( $reflection ) {
742775 * Parse PHPDoc into a structured representation.
743776 *
744777 * @param string $docblock
745- * @return array
778+ * @return array{description: string, short_description?: string, long_description?:string, behat_step?: string, parameters: array<string, mixed>}
746779 */
747780 private static function parse_docblock ( $ docblock ) {
748781 $ ret = [
@@ -801,7 +834,11 @@ private static function parse_docblock( $docblock ) {
801834 return $ ret ;
802835 }
803836
804- 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 {
805842 $ m = new Mustache_Engine ();
806843 $ template = file_get_contents ( WP_CLI_HANDBOOK_PATH . "/bin/templates/ $ path " );
807844 return $ m ->render ( $ template , $ binding );
@@ -811,6 +848,8 @@ private static function render( $path, $binding ) {
811848 * Removes existing contents of given directory.
812849 *
813850 * @param string $dir Name of directory to empty.
851+ *
852+ * @return void
814853 */
815854 private static function empty_dir ( $ dir ) {
816855 $ cmd = Utils \esc_cmd ( 'rm -rf %s ' , $ dir );
0 commit comments