Ahmad Badpey
Ahmad Badpey

Reputation: 6612

how to documents variables inside functions via phpDoc

I am using PHPDoc standards for commenting PHP(laravel) code and ApiGen to generate an API Documentation.

I know that there are many Tags that can be used to present information.

define() statements, functions, classes, class methods, and class vars, include() statements, and global variables can all be documented.

But now I want to document variables that are in a function.
for example suppose I have a function like this :

         /**
         * @param Request $request
         * @param         $course_id
         * @param         $lesson_id
         * @param Content $content
         *
         * @return array
         *
         */
        public function SaveOnePageTest (Request $request, $course_id, $lesson_id, \App\Content $content)
        {
            /**
            *I want to document this variable that how does this and What used to be?
            */

            $doneTest = DoneTest::find($done_test_id);

            /**
            *or this variable 
            */
            $parentQuestions = $doneTest->parent_test->questions;
        }

Is there a solution to this case?

Upvotes: 3

Views: 2858

Answers (1)

n00dl3
n00dl3

Reputation: 21564

this kind of documentation tool/syntax have been developed to help people consuming a library/a software API.

Local variables are not accessible to the end user so there is no real need to expose them in the documentation.

While you can document your inner code, there is no standard way to do this using PHPDoc.

Update : Note that You can use phpdoc to define the type of a variable in order to get better code completion, but that will not be part of the API documentation :

/** @var SomeType $someVar */
$someVar = $this->doSomething();

Upvotes: 3

Related Questions