tarekdj/nsfix

PHP_CodeSniffer custom sniff that finds a set of namespaces and replace it by new ones.

Maintainers

Details

github.com/tarekdj/nsfix

Source

Issues

Installs: 303

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

v1.0.2 2020-12-28 15:59 UTC

This package is not auto-updated.

Last update: 2024-11-12 10:44:42 UTC


README

This is a phpcs sniff that finds a set of namespaces and replace it by new ones.

Installation

composer require tarekdj/nsfix --dev 

Usage

Create a ruleset file with the following content (Don't forget to set old and new namespaces)

<?xml version="1.0"?>
<ruleset name="ReplaceNamespaces">
    <rule ref="./vendor/tarekdj/nsfix/Sniffs/Namespaces/DisallowOldNamesapceSniff.php">
        <properties>
            <property name="nameSpacesMapping" type="array">
                <element key="OLD_NAMESPACE" value="NEW_NAMESPACE"/>
                <element key="ANOTHER_OLD_NAMESPACE" value="ANOTHER_NEW_NAMESPACE"/>
            </property>
        </properties>
    </rule>
</ruleset>

Run phpcs

./vendor/bin/phpcs --standard=PATH/TO/RULESET.xml PATH/TO/SRC 

Run phpcbf

./vendor/bin/phpcbf --standard=PATH/TO/RULESET.xml PATH/TO/SRC 

Result example

--- a/test/file.php
+++ b/test/file.php
@@ -1,14 +1,14 @@
 <?php
-namespace Tarekdj;
+namespace NsfixTest;
 
-use Tarekdj\Dummy;
-use Tarekdj\Fake;
+use NsfixTest\Dummy;
+use NsfixTest\Fake;
 
-$test = new \Tarekdj\DummyClass()
+$test = new \NsfixTest\DummyClass()
 
-class MyClass extends \Tarekdj\MyDummyClass implements \Tarekdj\DummyInterface
+class MyClass extends \NsfixTest\MyDummyClass implements \NsfixTest\DummyInterface
 {
-    public function __construct(\Tarekdj\Fake $fake)
+    public function __construct(\NsfixTest\Fake $fake)
     {
 
     }