Skip to content

Commit e8156dd

Browse files
author
Nico Stapelbroek
committed
Upgrade php-cs-fixer config to a version 2 compatible format
1 parent c19e8c9 commit e8156dd

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ coverage/*
55
notes.md
66
tests/fixtures/cassette*
77
/.php_cs.cache
8+
/.php_cs

.php_cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

.php_cs.dist

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
if (class_exists('\\PhpCsFixer\\Config')) {
4+
$cacheFile = getenv('TRAVIS') ? getenv('HOME') . '/.php_cs.cache' : __DIR__ . '/.php_cs.cache';
5+
$config = PhpCsFixer\Config::create()
6+
->setRules(array(
7+
'@PSR2' => true,
8+
'single_blank_line_before_namespace' => true,
9+
'concat_space' => array('spacing' => 'one'),
10+
'single_quote' => true,
11+
'braces' => true,
12+
))
13+
->setFinder(
14+
PhpCsFixer\Finder::create()
15+
->exclude('vendor')
16+
->exclude('docs')
17+
->in(__DIR__)
18+
)
19+
->setCacheFile($cacheFile)
20+
->setUsingCache(true)
21+
->setRiskyAllowed(true);
22+
23+
return $config;
24+
} else {
25+
$config = Symfony\CS\Config\Config::create()
26+
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
27+
->fixers(
28+
array(
29+
'single_blank_line_before_namespace',
30+
'concat_with_spaces',
31+
'single_quote',
32+
'braces',
33+
)
34+
)
35+
->finder(
36+
Symfony\CS\Finder::create()
37+
->exclude('vendor')
38+
->exclude('docs')
39+
->in(__DIR__)
40+
)
41+
->setUsingCache(true);
42+
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
43+
$config->setDir($cacheDir);
44+
return $config;
45+
}
46+

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ install:
4040
- composer update --prefer-source -o $COMPOSER_FLAGS
4141
- PHPUNIT_BIN=$(pwd)/vendor/bin/phpunit
4242
- PHPCS_FIXER_BIN=$(pwd)/vendor/bin/php-cs-fixer
43+
- $PHPCS_FIXER_BIN --version | grep -q "2.*.*" && PHPCS_FIXER_CONFIG_FLAG="--config=.php_cs.dist" || PHPCS_FIXER_CONFIG_FLAG="--config-file=.php_cs.dist"
4344
- cd ${TEST_DIR}
4445
- composer update --prefer-source -o $COMPOSER_FLAGS
4546

4647
script:
4748
- $PHPUNIT_BIN --coverage-clover=coverage.clover
48-
- test $TEST_DIR = "." && $PHPCS_FIXER_BIN fix --config-file=.php_cs --dry-run --diff $TRAVIS_BUILD_DIR || echo "Continue without php-cs-fixer"
49+
- test $TEST_DIR = "." && $PHPCS_FIXER_BIN fix $PHPCS_FIXER_CONFIG_FLAG --dry-run --diff $TRAVIS_BUILD_DIR || echo "Continue without php-cs-fixer"
4950

5051
after_success:
5152
- wget https://scrutinizer-ci.com/ocular.phar

0 commit comments

Comments
 (0)