The phpscript cli should add a few subcommands, namely list and fmt. The argument should take "." for the current folder, "./..." for the current folder and subfolders, or a list of php files specifically:
phpscript list . - print routes, files and classes for the current folder as markdown
phpscript list ./... - same but recursive for every file
phpscript fmt . - format code in current folder,
phpscript fmt ./... - format code in current folder and subfolders
phpscript fmt include/Database.php - formats the files given via arguments
The list should print a table as follows:
| Route |
Filename |
Classes |
|
include/Database.php |
Database |
| GET /users/{id} |
get-user-profile.php |
|
| POST /users/{id} |
post-user-profile.php |
|
It should do this for every referenced file, including the fully qualified namespace if any (Namespace\Database). Namespaces are optional and can just be added to the symbol definition. Generally, each file defines a maximum of 1 class, matching the filename. The tool aims to cater to this convention, as well as autoloading via @route annotations and __autoload (spl_register_autoload...).
The formatter should prefer tabs (as go fmt does). It should produce valid php code, including semicolons, loop/conditional braces, and valid php syntax for tokens like function. It should follow the one true brace style, matching similar Go formatting rules. Comments should not be touched, only code for classes, functions and statements. Double-line space should be collapsed to a single line space. Files should have trailing end of line markers. Closing markers (?>) are optional, and should be removed when not required (file contains a single class, no statements, single php open tag, the ?> should be trimmed from the source when formatting. All comments are retained as-is.
Expected
- Add
list and fmt subcommands to the cli
- Implement list to traverse the files given via args, read the files for @route annotations, print markdown table
- Implement a formatter package to reformat the AST to fix indentation/whitespace
- Use the formatter package in the CLI to format passed php files or folders with .php files.
- Create a
usage/cli.md documenting the list, fmt and other CLI commands
The phpscript cli should add a few subcommands, namely list and fmt. The argument should take "." for the current folder, "./..." for the current folder and subfolders, or a list of php files specifically:
phpscript list .- print routes, files and classes for the current folder as markdownphpscript list ./...- same but recursive for every filephpscript fmt .- format code in current folder,phpscript fmt ./...- format code in current folder and subfoldersphpscript fmt include/Database.php- formats the files given via argumentsThe list should print a table as follows:
It should do this for every referenced file, including the fully qualified namespace if any (Namespace\Database). Namespaces are optional and can just be added to the symbol definition. Generally, each file defines a maximum of 1 class, matching the filename. The tool aims to cater to this convention, as well as autoloading via
@routeannotations and__autoload(spl_register_autoload...).The formatter should prefer tabs (as go fmt does). It should produce valid php code, including semicolons, loop/conditional braces, and valid php syntax for tokens like
function. It should follow the one true brace style, matching similar Go formatting rules. Comments should not be touched, only code for classes, functions and statements. Double-line space should be collapsed to a single line space. Files should have trailing end of line markers. Closing markers (?>) are optional, and should be removed when not required (file contains a single class, no statements, single php open tag, the?>should be trimmed from the source when formatting. All comments are retained as-is.Expected
listandfmtsubcommands to the cliusage/cli.mddocumenting the list, fmt and other CLI commands