Code Monkey home page Code Monkey logo

additional-php-cs-fixers's Introduction

This library adds some custom fixers for php-cs-fixer (v2).

Installation

Add this package to your composer.json:

{
    "require-dev": {
        "novius/additional-php-cs-fixers": "~1.0.0"
    },
}

Modify your .php_cs:

  • Include the composer autoload:
include 'vendor/autoload.php';
  • Register the custom fixers:
return PhpCsFixer\Config::create()
    //...
    ->registerCustomFixers(SebC\AdditionalPhpCsFixers\Helper::getCustomFixers())
  • Use the new rules as you wish:
$rules = [
    // ...
    'SebCAdditionalPhpCsFixers/disallow_unaliased_classes' => [
        'replace_namespaces' => [
            'Fuel\Core' => '',
            'Illuminate\Support\Facades' => '',
        ],
    ],
];

disallow_unaliased_classes rule:

This prevents any use of some specific namespace, and encourages to replace it with another.

This is mainly useful/designed to force the use of aliased classes in some frameworks like Laravel or FuelPHP.

As example, with the following rules configuration:

  • 'Fuel\Core' => '', will trigger an error everytime a class such as Fuel\Core\Config is directly called, and will suggest to replace it with Config
  • 'Illuminate\Support\Facades' => '', will prevent a call like Illuminate\Support\Facades\Validator and replace it with Validator
  • 'Some\Evil\Stuff' => 'OtherStuff', will replace Some\Evil\Stuff\Foo::myFunction() with OtherStuff\Foo::myFunction()

This also works with used namespaces.

TODO

Unit tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.