phpactor / class-mover
Library for moving classes
Requires
- php: ^7.3 || ^8.0
- microsoft/tolerant-php-parser: ^0.1
- phpactor/code-builder: ^0.4.3
- phpactor/code-transform-extension: ^0.2.1
- phpactor/container: ^2.0
- phpactor/text-document: ^1.2
- phpactor/worse-reflection: ^0.4.7
- psr/log: ~1.0
- symfony/filesystem: ^4.2 || ^5.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.0
- friendsofphp/php-cs-fixer: ^2.17
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ~0.12.0
- phpunit/phpunit: ^9.0
- symfony/console: ^4.3 || ^5.1
This package is auto-updated.
Last update: 2022-03-31 19:33:34 UTC
README
This is a library dedicated to refactoring class locations.
It takes care of:
- Finding references to a class: Find all references to a class (or classes).
- Finding references to class methods: Find references to a class method, or all method calls on a class, or all method calls ever.
- Replacing references to the class: Update any references in the code (using a given method, e.g. all under a path or all files in the git repo).
- Modifying use statements: update any use statements for the replaced class.
- Adding use cases: where necessary.
Why?
When using an editor such as VIM, one of the biggest issues I face is moving classes and replacing their references - it is such a big issue for me that I rarely do it.
Current approaches involve git moving the class, then running a for loop in bash over a set of files and applying perl replace to them, piping the output of that to a temporary file and then moving that temporary file to overwrite the old one. And that doesn't always work well.
This package aims to provide a solid way of doing this, and can, for example, be packaged in an
Usage
$targetClass = 'Acme\Blog\Post'; $replacementClass = 'Acme\Blog\Article'; $sourceCode = file_get_contents('SomeSource.php'); $classMover = new ClassMover(); $source = $classMover->replaceReferences( $classMover->findReferences($sourceCode, $targetClass) $replacementClass ); echo (string) $source;
Contributing
This package is open source and welcomes contributions! Feel free to open a pull request on this repository.
Support
- Create an issue on the main Phpactor repository.
- Join the
#phpactor
channel on the Slack Symfony Devs channel.