Best way to document Array options in PHPDoc?

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

    Can you use objects instead of arrays? That would make documentation easy.

    class Field {
    
        /**
         * The name of the thing.
         * @var string
         */
        protected $name;
    
        protected $model;
        protected $width;
        //...
    
        public function getName() {...}
        public function setName() {...}
        //...
    }
    
    class FieldList implements SomeKindOfIterator {
    
        /**
         * Some fields.
         * @var Field[]
         */
        protected $fields = array();
    
        /**
         * ...
         */
        public function push(Field $field) {
             $this->fields[] = $field;
        }
    
        //...
    }
    

    Then you can use a type hint where the class is required.

    /**
     * Do something.
     * @param FieldList $field_list The field.
     */
    function doSomething(FieldList $field_list) {...}
    

提交回复
热议问题