3

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?

5
  • 2
    There's no "formalised" approach to this, you simply add whatever comments you want Commented Jul 18, 2016 at 8:22
  • use simple comments can not create any information about variables inside functions in final API documentation. Commented Jul 18, 2016 at 8:29
  • 1
    No it can't, but why should any end user need to know about the internals of a method? Commented Jul 18, 2016 at 9:06
  • @Mark Baker, no i do not need that end user to know internal method, I want it for me and my contributors. in fact I do not know other companies use which tools to code maintenance Commented Jul 18, 2016 at 13:56
  • 1
    As you and the contributors should have direct access to the code, then there's surely no issue with simply commenting the code itself. Tools like PHPDoc and ApiGen are for documenting the end-user interfaces to the class/methods/properties, not internal code values Commented Jul 18, 2016 at 14:04

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

2 Comments

However, are not there any ways to document local variables? Why so I am working on large project and I want to create a documentation for that to remember that classes , variables , methods , ... what do ?
just use regular comment for local variables, if someone needs to interact with local variable he will need to open the code whatever happen...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.