Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kschroeder/0145f952f2252b7df9df52a183719446 to your computer and use it in GitHub Desktop.
Save kschroeder/0145f952f2252b7df9df52a183719446 to your computer and use it in GitHub Desktop.
Simple script that generates the PHPDoc for methods based off of the column names in a table. To use copy the column names from your DB and execute
<?php
$returnValue = $argv[1]??'void';
$output = "/**\n";
$lines = explode("\n", file_get_contents('php://stdin'));
foreach ($lines as $line) {
$column = explode(' ', $line);
$column = array_shift($column);
$generatedName = explode('_', $column);
if (!$generatedName) continue;
array_walk($generatedName, function(&$value) {$value = ucfirst($value); }, null, );
$generatedName = implode('', $generatedName);
$output .= sprintf(
" * @method string get%s()\n * @method %s set%s(string \$value)\n",
$generatedName,
$returnValue,
$generatedName
);
}
$output .= " */\n";
echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment