Best way to document Array options in PHPDoc?

前端 未结 9 604
天命终不由人
天命终不由人 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:21

    A bit too late to the party but this is how I do it instead:

    /**
     * Class constructor.
     *
     * @param array $params Array containing the necessary params.
     *    $params = [
     *      'hostname'     => (string) DB hostname. Required.
     *      'databaseName' => (string) DB name. Required.
     *      'username'     => (string) DB username. Required.
     *      'password'     => (string) DB password. Required.
     *      'port'         => (int) DB port. Default: 1433.
     *      'sublevel'     => [
     *          'key' => (\stdClass) Value description.
     *      ]
     *    ]
     */
     public function __construct(array $params){}
    

    Think it's quite clean and easy to understand what $params should be.

提交回复
热议问题