2017 © Pedro Peláez
 

library php-cs-fixer-styleci-bridge

Auto configure PHP-CS-Fixer from StyleCI config file

image

sllh/php-cs-fixer-styleci-bridge

Auto configure PHP-CS-Fixer from StyleCI config file

  • Monday, December 25, 2017
  • by Soullivaneuh
  • Repository
  • 2 Watchers
  • 39 Stars
  • 78,827 Installations
  • PHP
  • 162 Dependents
  • 0 Suggesters
  • 8 Forks
  • 9 Open issues
  • 25 Versions
  • 5 % Grown

The README.md

PHP-CS-Fixer StyleCI bridge

:warning: This package is not maintained anymore. :warning:, (*1)

PHP-CS-Fixer v2 came with a brand new configuration structure but StyleCI decided to keep the old way., (*2)

Because of that, it's now very hard to maintain this bridge and it's still not compatible with PHP-CS-Fixer v2., (*3)

This is also why I decided to abandon this package and write FlintCI, my own Code Review service for multiple fixers and linters without any required configuration bridge., (*4)

You can try it here (flintci.io), or keep using StyleCI without this bridge., (*5)

Auto configure PHP-CS-Fixer from StyleCI config file., (*6)

This library permits to generate php-cs-fixer configuration directly from your .styleci.yml config file., (*7)

With that, you will avoid the pain of both config files maintenance., (*8)

Latest Stable Version Latest Unstable Version License Dependency Status Reference Status, (*9)

Total Downloads Monthly Downloads Daily Downloads, (*10)

Build Status Scrutinizer Code Quality Code Climate Coverage Status SensioLabsInsight, (*11)

Who is using this?

You can see which projects are using this package on the dedicated Packagist page., (*12)

Installation

Include this library on your dev dependencies:, (*13)

composer require --dev sllh/php-cs-fixer-styleci-bridge

Usage

You can use this bridge with several manners., (*14)

Basic usage

Put the following config on your .php_cs file:, (*15)

<?php

// Needed to get styleci-bridge loaded
require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create();

With this configuration, the configuration bridge will just parse your .styleci.yml file., (*16)

Sample working file:, (*17)

preset: symfony

enabled:
  - align_double_arrow
  - newline_after_open_tag
  - ordered_use
  - long_array_syntax

disabled:
  - unalign_double_arrow
  - unalign_equals

Directories options

You can change default repository of your .styleci.yml file and directories for the CS Finder directly on ConfigBridge::create method or constructor., (*18)

<?php

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create(__DIR__.'/config', [__DIR__, __DIR__.'../lib']);

Customize the configuration class

ConfigBridge::create returns a Symfony\CS\Config\Config that you can customize as you want., (*19)

<?php

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create()
    ->setUsingCache(true)       // Enable the cache
;

Using the bridge

You can also using bridge method, part by part., (*20)

<?php

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;
use Symfony\CS\Config\Config;

$bridge = new ConfigBridge();

return Config::create()
    ->finder($bridge->getFinder())
    ->fixers(['dummy', 'foo', '-bar'])
    ->setUsingCache(true)
;

Manually enable or disable fixers

To enable or disable some fixers manually on the .php_cs file, you will have to use merge system to keep fixers defined by the bridge:, (*21)

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;

$config = ConfigBridge::create();

return $config
    ->setUsingCache(true)
    ->fixers(array_merge($config->getFixers(), ['-psr0', 'custom', 'foo', '-bar']))
;

Header comment

Unfortunately, header comment option is not available on StyleCI config file., (*22)

You will have to copy it from StyleCI web interface and set it manually., (*23)

The config bridge will automatically detect the fixer and add it on CS configuration., (*24)

PHP-CS-Fixer 1.x

<?php

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;
use Symfony\CS\Fixer\Contrib\HeaderCommentFixer;

$header = <<<EOF
This file is part of the dummy package.

(c) John Doe <john@doe.com>

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

HeaderCommentFixer::setHeader($header);

return ConfigBridge::create();

PHP-CS-Fixer 2.x

<?php

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;

$header = <<<EOF
This file is part of the dummy package.

(c) John Doe <john@doe.com>

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

$config = ConfigBridge::create();

return $config
    ->setRules(array_merge($config->getRules(), array(
        'header_comment' => array('header' => $header)
    )))
;

Both versions

You can handle both versions easily with some magic method_exists tricks:, (*25)

<?php

require __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

use SLLH\StyleCIBridge\ConfigBridge;
use Symfony\CS\Fixer\Contrib\HeaderCommentFixer;

$header = <<<EOF
This file is part of the dummy package.

(c) John Doe <john@doe.com>

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

// PHP-CS-Fixer 1.x
if (method_exists('Symfony\CS\Fixer\Contrib\HeaderCommentFixer', 'getHeader')) {
    HeaderCommentFixer::setHeader($header);
}

$config = ConfigBridge::create();

// PHP-CS-Fixer 2.x
if (method_exists($config, 'setRules')) {
    $config->setRules(array_merge($config->getRules(), array(
        'header_comment' => array('header' => $header)
    )));
}

return $config;

Troubleshooting

Conflict with code or vendor library

In some edge cases, the bridge code may conflict with your code or your included vendor., (*26)

This kind of issue was discovered in puli/cli#21 (comment) and fixed since v1.3.3 in #47., (*27)

Before that, you had to require the vendor autoload like this:, (*28)

require __DIR__.'/vendor/autoload.php';

This is not the secured way. Make sure to require our custom loader instead:, (*29)

require __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

The Versions

25/12 2017
12/01 2017
17/04 2016

dev-travis-sf-2.3

dev-travis-sf-2.3

Auto configure PHP-CS-Fixer from StyleCI config file

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel psr configuration symfony psr-4 psr-2 psr-1 php-cs-fixer styleci

30/09 2015

dev-cs-fixer-1.x-drop

dev-cs-fixer-1.x-drop

Auto configure PHP-CS-Fixer from StyleCI config file

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel psr configuration symfony psr-4 psr-2 psr-1 php-cs-fixer styleci

28/09 2015

v1.2.1

1.2.1.0

Auto configure PHP-CS-Fixer from StyleCI config file

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel psr configuration symfony psr-4 psr-2 psr-1 php-cs-fixer styleci

25/09 2015

v1.2.0

1.2.0.0

Auto configure PHP-CS-Fixer from StyleCI config file

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel psr configuration symfony psr-4 psr-2 psr-1 php-cs-fixer styleci

24/09 2015

v1.1.0

1.1.0.0

Auto configure PHP-CS-Fixer from StyleCI config file

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel configuration symfony psr-2 psr-1 php-cs-fixer styleci