AI PHPDocs is a tool that uses LLM (OpenAI or any other OpenAI compatible API) to automatically add missing PHPDoc comments to your PHP code.
If you want to user OpenAI, you will need to have an OpenAI API key set as an environment variable.
export OPENAI_KEY=...
If you want to use another API endpoint, for example Ollama, you need to export other environment variables.
Example with Ollama that runs locally
export BASE_URI=http://localhost:11434/v1
export MODEL=mistral
You can choose the model with an environment variable.
export MODEL=...
To install AI PHPDocs, run the following command:
composer global require acseo/ai-phpdoc
To add missing PHPDoc comments to a single file, use the following command:
aiphpdocs file /path/to/file.php
To add missing PHPDoc comments to a directory of files, use the following command. By default it iterates through the current directory for all files, but does not go into subdirectories:
aiphpdocs dir
You may set the --recursive
flag, or -r
for short for it to go into subdirectories.
If you pass another variable (regardless of the recursive flag) it will treat it as another directory to sweep through instead of the working directory.
aiphpdocs dir -r /somewhere/else
You can use the Docker image acseo/ai-phpdoc to use ai-phpdoc via docker
$ docker run -it -e OPENAI_KEY=sk-xxx -v /path/to/your/code:/code acseo/ai-phpdoc dir -r /code/src
Original PHP File
// file : example.php
<?php
class Calculator
{
public function add(int $a, int $b) : int
{
return $a + $b;
}
}
$ export OPENAI_KEY=sk-...
$ php bin/aiphpdocs file example.php
Result
// file : example.php
<?php
class Calculator
{
/**
* Adds two integers and returns the sum.
*
* @param int $a The first integer to be added.
* @param int $b The second integer to be added.
* @return int The sum of the two integers.
*/
public function add(int $a, int $b) : int
{
return $a + $b;
}
}
AI PHPDocs is licensed under the AGPL-3.0 license. See LICENSE for more information.