1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 10:57:08 +01:00
psalm/docs/manipulating_code/refactoring.md

46 lines
1.7 KiB
Markdown
Raw Normal View History

2019-06-09 06:54:13 +02:00
# Refactoring Code
Sometimes you want to make big changes to your codebase like moving methods or classes.
Psalm has a refactoring tool you can access with either `vendor/bin/psalm-refactor` or `vendor/bin/psalm --refactor`, followed by appropriate commands.
2019-06-20 01:49:42 +02:00
## Moving all classes from one namespace to another
```
vendor/bin/psalm-refactor --move "Ns1\*" --into "Some\Other\Namespace"
```
This moves all classes in `Ns1` (e.g. `Ns1\Foo`, `Ns1\Baz`) into the specified namespace. Files are moved as necessary.
2019-06-09 06:54:13 +02:00
## Moving classes between namespaces
2019-06-09 23:45:41 +02:00
```
vendor/bin/psalm-refactor --move "Ns1\Foo" --into "Ns2"
```
2019-06-20 01:49:42 +02:00
This tells Psalm to move class `Ns1\Foo` into the namespace `Ns2`, so any reference to `Ns1\Foo` becomes `Ns2\Foo`). Files are moved as necessary.
2019-06-09 06:54:13 +02:00
## Moving and renaming classes
2019-06-09 23:45:41 +02:00
```
vendor/bin/psalm-refactor --rename "Ns1\Foo" --to "Ns2\Bar\Baz"
```
2019-06-20 01:49:42 +02:00
This tells Psalm to move class `Ns1\Foo` into the namespace `Ns2\Bar` and rename it to `Baz`, so any reference to `Ns1\Foo` becomes `Ns2\Bar\Baz`). Files are moved as necessary.
2019-06-09 06:54:13 +02:00
## Moving methods between classes
2019-06-09 23:45:41 +02:00
```
vendor/bin/psalm-refactor --move "Ns1\Foo::bar" --into "Ns2\Baz"
```
This tells Psalm to move a method named `bar` inside `Ns1\Foo` into the class `Ns2\Baz`, so any reference to `Ns1\Foo::bar` becomes `Ns2\Baz::bar`). Psalm currently allows you to move static methods between aribitrary classes, and instance methods into child classes of that instance.
2019-06-09 06:54:13 +02:00
## Moving and renaming methods
2019-06-09 23:45:41 +02:00
```
vendor/bin/psalm-refactor --rename "Ns1\Foo::bar" --to "Ns2\Baz::bat"
```
This tells Psalm to move method `Ns1\Foo::bar` into the class `Ns2\Baz` and rename it to `bat`, so any reference to `Ns1\Foo::bar` becomes `Ns2\Baz::bat`).