dev-master
9999999-devCopy / paste code at specific tokens in a list of PHP files
MIT
The Requires
The Development Requires
- phpunit/phpunit ^7.0
- php-vfs/php-vfs ^1.4
- phpstan/phpstan ^0.9.2
- phpro/grumphp ^0.14.0
- infection/infection dev-master
Wallogit.com
2017 © Pedro Peláez
Copy / paste code at specific tokens in a list of PHP files
Copy / paste code at specific locations in a list of files, (*2)
WIP: You can use the executable inside this repo for now ...., (*3)
$
Usage:
copy-paste [options] [--] <src> <location>
Arguments:
src The files you want to copy / paste in
location The location where you want to copy / paste
Options:
--dry-run Dont change the code but print the results to the screen
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
echo " implements MyInterface" | ./bin/injector 'src/Testing' 'T_CLASS { <' --dry-run
echo "\nuse New\Imported\ClassName;" | ./bin/injector 'src/Testing' 'NEWUSE(New\\Imported\\Class)' --dry-run
echo "return 'Do something';\n " | ./bin/injector 'src/Testing' 'METHODNAME(myFunction) { > >' --dry-run
Every operation is split based on a space.
For example.: T_CLASS { < contains out 3 tokens:, (*4)
T_CLASS: Will search for the next occurrence of the class keyword{: Will search for the next occurrence of the brace with type {
<: Will select the previous tokenThese tokens will be detected in this orde., (*5)
Token lookups
- T_*: Detect next token of PHP parser token constant. (Or the CT class in php-cs-fixer), (*6)
Brace lookups
- {}[](): Detect next token of the selected brace type
- ENDBLOCK(]})): Detect the end block of the selected brace type.
- STARTBLOCK([{(): Detect the start block of the selected brace type., (*7)
Next / Previous lookups
- <: Select previous token
- >: Select next token
- <<: Select Previous non-whitespace token
- >>: Select Next non-whitespace token
- <<<: Select Previous meaningful token (no whitespace, comment, docblocks, ...)
- >>>: Select Next meaningful token (no whitespace, comment, docblocks, ...), (*8)
Macro lookups
- METHODNAME(myFunction): Detect the function declaration of method myFunction
- NEWUSE(MyNew\MyNamespace): Detect the best place to insert a new use statement MyNew\MyNamespace, (*9)
Copy / paste code at specific tokens in a list of PHP files
MIT