Search code examples
documentationphpdocdocblocks

DocBlock documentation for instances of classes


Could you please give me some guidance on how I should document this piece of code with DocBloc documentation?

private $entityManager;

public function __construct($entityManager) {
    parent::__construct();
    $this->entityManager = $entityManager;
}

The $entityManager is an instance of the EnitiyManager class.


Solution

  • For phpdoc, only property annotation is useful.

    Also adding constructor typehint to check the type.
    But consider, that constructor annotation would not bring any new information.

    For more examples, it's good to check some framework source on Github, e.g. Symfony

    /**
     * @var EntityManager
     */
    private $entityManager;
    
    
    /**
     * @var EntityManager $entityManager
     */
    public function __construct(EntityManager $entityManager) {
        parent::__construct();
        $this->entityManager = $entityManager;
    }