Giter Club home page Giter Club logo

lib-php-cs-fixer-config's Introduction

lib-php-cs-fixer-config

Library helps to fix PHP code to conform Paysera PHP style guide.

Installation

Prerequisite

  • Add Paysera\\PhpCsFixerConfig\\Composer\\PhpCsFixerConfigProvider::copyPhpCs script to post-install-cmd and post-update-cmd or other scripts - just make sure this script is executed on composer install.

Install and check

  • composer require --dev paysera/lib-php-cs-fixer-config.
  • Make sure php-cs-fixer.php file is in project directory.

No need to install php-cs-fixer itself as this library comes with binary version of the fixer. This avoids requiring its dependencies inside your project, which could clash with existing ones.

To avoid duplication with php-cs-fixer library, it's named paysera-php-cs-fixer.

php-cs-fixer.php files
  • php-cs-fixer.php - all Paysera recommended fixers.
  • php-cs-fixer-risky.php - all risky fixers except recommendations (comment warnings).
  • php-cs-fixer-safe.php - all non risky fixers.

Migration mode

For new projects you can just use all the rules as usual.

For existing projects we recommend turning on the migration mode:

  1. Add call to enableMigrationMode([]) to PayseraConventionsConfig instance in your php-cs-fixer.php file.
  2. Run {your-bin-dir}/php-cs-fixer - it will give error with initial rule configuration to pass into that method. Just copy-and-paste it to your php-cs-fixer.php file.
  3. Enable one of the rules, apply fixes in the project, review and test them.
  4. Repeat with each new rule.

This allows to control which rules are enabled in the project thus letting manually tune the fixes already applied in the repository and forced for the new code. Also, your commits will be more focused as each of them will include only changes from a single fixer.

All rules are to be configured to allow easily spotting new rules in case they would be added (or removed) into the core.

Running fixer with tests

For comments or suggestions for developers you should use default php-cs-fixer.php file with all the rules.

For automatic checks there might be some false-positives so php-cs-fixer-risky.php should be used in such cases.

You can look at .travis.yml file in this repository for integration with travis on each pull request of your repository (this will run the checks only for changed files).

Usage

Run in project directory by command: {your-bin-dir}/php-cs-fixer fix /path/to/code --verbose --dry-run --diff

Use --config=.php-cs-fixer.php flag for custom configuration.

If /path/to/code is not defined php-cs-fixer will run files from default src directory excluding Test folders.

--verbose - show the applied rules. When using the txt format it will also display progress notifications.

A combination of --dry-run and --diff will display a summary of proposed fixes, leaving your files unchanged.

--format option for the output format. Supported formats are txt (default one), json, xml and junit.

More information: PHP CS Fixer

lib-php-cs-fixer-config's People

Contributors

artem-yakymchuk-paysera avatar borilyordanov avatar boyanpaysera avatar mariusbalcytis avatar msprunskas avatar vbartusevicius avatar viktorkulahin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lib-php-cs-fixer-config's Issues

issue with anonymous classes

can't use anonymous classes:

<?php

declare(strict_types=1);

namespace Acme;

use stdClass;

class Example
{
    public function magicMethod(): void
    {
        $class = new class() extends stdClass {
        };

        $class->something = 0;
    }
}

gets an error: "PhpBasic convention 1.3: Only one class/interface can be declared per file"
It's mostly used in tests

Constants with visibility

Fails with the following code:

<?php

class MyClass
{
    private const SOMETHING = 'initial value';
}

Functions with root namespace

Fails with the following code:

<?php

namespace A;

function test()
{
    return \trim('');
}

This provides use trim; which is only to be used with classes.

few duplicates

Hi, interesting package ;)
I gave it a short look, and I found few duplicates. Just raising a concern here, maybe you don't need to have them in the end ;)

Paysera PHP CS Fixer
Paysera/php_basic_code_style_class_constructors new_with_braces
Paysera/php_basic_code_style_comparison_order yoda_style
Paysera/php_basic_feature_strict_comparison_operators strict_comparison
Paysera/php_basic_feature_function_is_null is_null
Paysera/php_basic_feature_function_count no_alias_functions

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.