Last active
May 23, 2019 18:26
-
-
Save kschroeder/e2cba5fdbf8ad2b3090eb06884855d84 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.
This file contains hidden or 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
<?php | |
/** | |
* To use copy the column names from your DB and execute `php magento-phpdoc-getter-setter-generation.php <model?` | |
* Then paste column names into your console and hit CTRL-D | |
* For example | |
*[kschroeder@localhost tests]$ php test.php SomeModel | |
order_id | |
requester_id | |
decider_id | |
/** | |
* @method string getOrderId() | |
* @method SomeModel setOrderId(string $value) | |
* @method string getRequesterId() | |
* @method SomeModel setRequesterId(string $value) | |
* @method string getDeciderId() | |
* @method SomeModel setDeciderId(string $value) | |
*/ | |
*/ | |
$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