Best way to document Array options in PHPDoc?

前端 未结 9 603
天命终不由人
天命终不由人 2020-12-04 09:57

I\'m struggling to write readable and easy to understand documentation that describes the multi-tree structure for Array options that are passed to a function.

Here

9条回答
  •  孤城傲影
    2020-12-04 10:09

    Among widely accepted key type documenting formats, I'd like to mention few popular ones here:

    Psalm/PHPStan/phan format

    /** @param array{foo: string, bar: int} $args */
    

    as a bonus, can also be used for static code analysis with their tools

    Wordpress format

    /**
     * @param array $args {
     *     Optional. An array of arguments.
     *
     *     @type type $key Description. Default 'value'. Accepts 'value', 'value'.
     *                     (aligned with Description, if wraps to a new line)
     *     @type type $key Description.
     * }
     */
    

    and both are supported by deep-assoc-completion plugin

提交回复
热议问题