-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fixed bug where autoload.php was not being found correctly
♻️ Refactored ProcessDirectory and ProcessFile classes 🔧 Added bin entry to composer.json ✨ Added readme with installation instructions and usage examples
- Loading branch information
Showing
7 changed files
with
191 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
if (file_exists(__DIR__.'/../../../autoload.php')) { | ||
require __DIR__.'/../../../autoload.php'; | ||
} else { | ||
require __DIR__.'/../vendor/autoload.php'; | ||
} | ||
|
||
use Molbal\AiPhpdoc\ProcessDirectory; | ||
use Molbal\AiPhpdoc\ProcessFile; | ||
use Symfony\Component\Console\Application; | ||
|
||
$application = new Application('AI-PHPDocs by molbal', '1.0.0'); | ||
|
||
$application->add(new ProcessFile()); | ||
$application->add(new ProcessDirectory()); | ||
|
||
$application->run(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<?php | ||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
use Molbal\AiPhpdoc\InsertMissingDocs; | ||
use Molbal\AiPhpdoc\ProcessDirectory; | ||
use Molbal\AiPhpdoc\ProcessFile; | ||
use Symfony\Component\Console\Application; | ||
|
||
$application = new Application(); | ||
$application = new Application('AI-PHPDocs by molbal', '1.0.0'); | ||
|
||
|
||
$application->add(new InsertMissingDocs()); | ||
// ... register commands | ||
$application->add(new ProcessFile()); | ||
$application->add(new ProcessDirectory()); | ||
|
||
$application->run(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,8 @@ | |
"php": "^8.1", | ||
"symfony/console": "^6.2", | ||
"openai-php/client": "^0.3.0" | ||
} | ||
}, | ||
"bin": [ | ||
"bin/aiphpdocs" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# AI PHPDocs | ||
|
||
AI PHPDocs is a tool that uses GPT-3 to automatically add missing PHPDoc comments to your PHP code. | ||
|
||
## Prerequisites | ||
|
||
Before using AI PHPDocs, you will need to have an OpenAI API key set as an environment variable. | ||
|
||
```shell | ||
export OPENAI_KEY=... | ||
``` | ||
|
||
## Installation | ||
|
||
To install AI PHPDocs, run the following command: | ||
|
||
|
||
```shell | ||
composer global require molbal/ai-phpdocs | ||
``` | ||
|
||
## Usage | ||
|
||
To add missing PHPDoc comments to a single file, use the following command: | ||
|
||
```shell | ||
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: | ||
|
||
```shell | ||
aiphpdocs directory | ||
``` | ||
|
||
|
||
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. | ||
|
||
```shell | ||
aiphpdocs directory --r /somewhere/else | ||
``` | ||
|
||
## License | ||
|
||
AI PHPDocs is licensed under the AGPL-3.0 license. See LICENSE for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Molbal\AiPhpdoc; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ProcessDirectory extends Command | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('directory') | ||
->setDescription('Adds missing PHPDoc blocks to functions in a directory') | ||
->addArgument('directory', InputArgument::OPTIONAL, 'The directory to iterate through. Defaults to `.`') | ||
->addOption('recursive', 'r', InputOption::VALUE_NONE,'Iterate recusrively? Defaults to no'); | ||
} | ||
|
||
|
||
/** | ||
* Execute the function | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$dirPath = $input->getArgument('file'); | ||
$recursive = $input->getOption('recursive') !== false; | ||
return (new ProcessFacade())->processDirectory($dirPath, $recursive, $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Molbal\AiPhpdoc; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ProcessFile extends Command | ||
{ | ||
|
||
/** | ||
* Configures the current command. | ||
* | ||
* @param string $file The file to list the functions of | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('file') | ||
->setDescription('Adds missing PHPDoc blocks to functions in a file') | ||
->addArgument('file', InputArgument::REQUIRED, 'The file to process.'); | ||
} | ||
|
||
|
||
/** | ||
* Execute the function | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$filePath = $input->getArgument('file'); | ||
return (new ProcessFacade())->processFile($filePath, $output); | ||
} | ||
} |