cristisst
cristisst

Reputation: 41

How to autogenerate phpDOC for classes/function on VSCode

Any idea how to generate phpdoc on VSCode? I have installed intellisense, intelephense extensions but when I type /** it just adds */ so it becomes something like /** */ and that's all. No autogenerated PHP doc, nothing no matter this is done above the class definition or a regular function.

Upvotes: 2

Views: 11420

Answers (3)

Miloslav Beňo
Miloslav Beňo

Reputation: 168

To autogenerate PHPDoc in VSCode, check out the PHP Tools for VS Code extension.

Just ensure you have Format On Type enabled by adding "editor.formatOnType": true to your settings.json.

Once set up, type /** above the desired element and hit Enter. It will generate a PHPDoc block with all the necessary annotations for you.

Disclaimer: I work on this extension.

Upvotes: 2

Joel Mellon
Joel Mellon

Reputation: 3855

As of 2024, the most popular VSCode extension for this seems to be PHP DocBlocker.

Create a new blank line above your function/method/class/var and type / * * (Enter or Tab).

You can then type your comments and Tab through each "field" in the doc block, eg. type "My function name" then hit Tab to highlight the next field, eg. @param where you can type "string $str The string to pass to my function", then Tab to the @return portion, etc., etc.

Upvotes: 0

S2LF
S2LF

Reputation: 73

with a VSCode extension you can do it, but not with the same shortcut ("/**" + ENTER)

I found 3 :

  • PHPDoc Comment

VSCode Marketplace for PHPDoc Comment

Shortcut : CMD + SHIFT + I

  • PHPDoc Generator

VSCode Marketplace for PHPDoc Generator

Shortcut : CTRL + ENTER

  • PHPDoc Generator 2022

VSCode Marketplace for PHPDoc Generator 2022

Shortcut : CTRL + ENTER

I don't find another way do to this like PHPStorm


I tried the first one :

function getNameFromNumber($num) {
    $numeric = $num % 26;
    $letter = chr(65 + $numeric);
    $num2 = intval($num / 26);
    if ($num2 > 0) {
        return $this->getNameFromNumber($num2 - 1) . $letter;
    } else {
        return $letter;
    }
}

With a right click I can :

enter image description here

/**
 * getNameFromNumber
 *
 * @param  mixed $num
 * @return void
 */
function getNameFromNumber($num) {
    $numeric = $num % 26;
    $letter = chr(65 + $numeric);
    $num2 = intval($num / 26);
    if ($num2 > 0) {
        return $this->getNameFromNumber($num2 - 1) . $letter;
    } else {
        return $letter;
    }
}

I work like a charm ;)


Hope it can help you

Bye

Upvotes: 2

Related Questions