namespacer is a command line tool to automatically fix wrong namespace
declarations in PHP files
according to PSR-4 and PSR-12.
Archives of precompiled binaries for namespacer are available.
- Clone this repository:
$ git clone [email protected]:thled/namespacer.git
- Change to project directory:
$ cd namespacer
- Build the app:
$ cargo build --release
- Copy binary:
$ cp target/release/namespacer TARGET
$ ./namespacer FILE BASE_DIR [ VENDOR [ PREFIX ] ]
- FILE = relative path to the file
- BASE_DIR = path prefix of the relative path to the file
- VENDOR = top-level namespace name (default:
App
) - PREFIX = additional namespace (default: none)
$ ./namespacer --help
for further assistance.
$ ./namespacer src/Controller/Login.php src
=>namespace App\Controller;
$ ./namespacer src/Controller/Login.php src Acme
=>namespace Acme\Controller;
$ ./namespacer src/Controller/Login.php src Acme Foo
=>namespace Acme\Foo\Controller;
$ ./namespacer src/Controller/Login.php src Acme Foo\\Bar
=>namespace Acme\Foo\Bar\Controller;
$ ./namespacer tests/Unit/LoginTest.php tests App Tests
=>namespace App\Tests\Unit;
$ ./namespacer app/src/Controller/Login.php app/src
=>namespace App\Controller;
$ ./namespacer src/ src
or
$ cargo clippy
$ cargo test
$ cargo watch -cx test -i tests/data
Please do contribute! Issues and pull requests are welcome.