Kreta PHP CS Fixer Config
PHP linting tool using PHP CS Fixer for Kreta packages, (*1)
, (*2)
It's based on the ideas of refinery29/php-cs-fixer-config
and
prooph/php-cs-fixer-config
., (*3)
Installation
$ composer require --dev kreta/php-cs-fixer-config
Usage
Configuration
Create a configuration file .php_cs
in the root of your project:, (*4)
<?php
/*
* This file is part of the Kreta package.
*
* (c) BeƱat EspiƱa <benatespina@gmail.com>
* (c) Gorka Laucirica <gorka.lauzirika@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use Kreta\PhpCsFixerConfig\KretaConfig;
$config = new KretaConfig();
$config->getFinder()->in(__DIR__ . '/src');
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
$config->setCacheFile($cacheDir . '/.php_cs.cache');
return $config;
In case your project uses [PhpSpec][3] BDD test framework, also create a .phpspec_cs
file in the root of your project:, (*5)
<?php
/*
* This file is part of the Kreta package.
*
* (c) BeƱat EspiƱa <benatespina@gmail.com>
* (c) Gorka Laucirica <gorka.lauzirika@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use Kreta\PhpCsFixerConfig\KretaConfig;
$config = new KretaConfig(true);
$config->getFinder()
->in(__DIR__ . '/tests/Spec')
->name('*Spec.php');
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
$config->setCacheFile($cacheDir . '/.php_cs.cache');
return $config;
Git
Add .php_cs.cache
(this is the cache file created by php-cs-fixer
) to .gitignore
:, (*6)
/vendor
/.php_cs.cache
Composer
Add the following scripts in the composer.json
file:, (*7)
(...)
"scripts": {
(...)
"cs": [
"php-cs-fixer fix --config=.php_cs -v",
"php-cs-fixer fix --config=.phpspec_cs -v"
]
},
Travis
Update your .travis.yml
to cache the php_cs.cache
file:, (*8)
cache:
directories:
- $HOME/.php-cs-fixer
Then run php-cs-fixer
in the script
section:, (*9)
script:
- vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run
- vendor/bin/php-cs-fixer fix --config=.phpspec_cs --verbose --diff --dry-run
Fixing issues
Manually
If you need to fix issues locally and if you previously added the composer script, just run:, (*10)
$ composer run-script cs
otherwise you can run:, (*11)
$ vendor/bin/php-cs-fixer fix -v
$ vendor/bin/php-cs-fixer fix -v --config=.phpspec_cs
Credits
Kreta is created by:
>
@benatespina - benatespina@gmail.com
@gorkalaucirica - gorka.lauzirika@gmail.com, (*12)
Licensing Options
, (*13)