Skip to content

thled/namespacer

Repository files navigation

namespacer

Version MIT License Rust

namespacer is a command line tool to automatically fix wrong namespace declarations in PHP files according to PSR-4 and PSR-12.

Installation

Download binary

Archives of precompiled binaries for namespacer are available.

Build binary

  1. Clone this repository: $ git clone [email protected]:thled/namespacer.git
  2. Change to project directory: $ cd namespacer
  3. Build the app: $ cargo build --release
  4. Copy binary: $ cp target/release/namespacer TARGET

Usage

$ ./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.

Examples

  • $ ./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

Developing

Requirements

or

Linting

$ cargo clippy

Testing

$ cargo test

Watcher

$ cargo watch -cx test -i tests/data

Contribute

Please do contribute! Issues and pull requests are welcome.