Skip to content

Commit

Permalink
Merge pull request ronanguilloux#38 from Soullivaneuh/style-ci
Browse files Browse the repository at this point in the history
StyleCI integration
  • Loading branch information
soullivaneuh committed Sep 18, 2015
2 parents 6d57d1d + adf2fbe commit 2ed6053
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
51 changes: 37 additions & 14 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in([__DIR__])
;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Yaml\Yaml;
use Symfony\CS\Config\Config;
use Symfony\CS\Finder\DefaultFinder;
use Symfony\CS\FixerInterface;

// Harmonize php-cs-fixer config with StyleCI
$styleCIConfig = Yaml::parse(file_get_contents(__DIR__.'/.styleci.yml'));

$fixers = array_merge(
isset($styleCIConfig['enabled']) ? $styleCIConfig['enabled'] : [],
isset($styleCIConfig['disabled']) ? array_map(function ($disabledFixer) {
return '-'.$disabledFixer;
}, $styleCIConfig['disabled']) : []
);

$levels = [
'psr1' => FixerInterface::PSR1_LEVEL,
'psr2' => FixerInterface::PSR1_LEVEL,
'symfony' => FixerInterface::SYMFONY_LEVEL,
];
$level = isset($styleCIConfig['preset']) && isset($levels[$styleCIConfig['preset']])
? $levels[$styleCIConfig['preset']] : FixerInterface::SYMFONY_LEVEL;

$finder = DefaultFinder::create()->in([__DIR__]);
if (isset($styleCIConfig['finder']) && is_array($styleCIConfig['finder'])) {
$finderConfig = $styleCIConfig['finder'];
foreach ($finderConfig as $key => $values) {
$finderMethod = Container::camelize(str_replace('-', '_', $key));
foreach ($values as $value) {
$finder->$finderMethod($value);
}
}
}

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'-psr0',
'-unalign_double_arrow',
'-unalign_equals',
'align_double_arrow',
'newline_after_open_tag',
'ordered_use',
'short_array_syntax',
])
return Config::create()
->level($level)
->fixers($fixers)
->setUsingCache(true)
->finder($finder)
;
12 changes: 12 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
preset: symfony

enabled:
- align_double_arrow
- newline_after_open_tag
- ordered_use
- short_array_syntax

disabled:
- psr0
- unalign_double_arrow
- unalign_equals
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ env:
matrix:
fast_finish: true
include:
- php: 5.6
env: CS_FIXER=run
- php: 5.4
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 5.6
Expand Down Expand Up @@ -60,16 +58,14 @@ cache:
before_script:
- composer selfupdate
- composer config -g github-oauth.github.com $GITHUB_OAUTH_TOKEN
- composer global require phpunit/phpunit fabpot/php-cs-fixer --no-update
- composer global require phpunit/phpunit --no-update
- composer global update --prefer-dist --no-interaction
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- if [ "$SILEX_VERSION" != "" ]; then composer require "silex/silex:${SILEX_VERSION}" --no-update; fi;
- if [ "$ISOCODES_VERSION" != "" ]; then composer require "ronanguilloux/isocodes:${ISOCODES_VERSION}" --no-update; fi;
- composer update --prefer-dist --no-interaction $COMPOSER_FLAGS

script:
- if [ "$CS_FIXER" = "run" ]; then make cs_dry_run ; fi;
- make test
script: make test

after_script:
- php vendor/bin/coveralls -v
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cs:
php-cs-fixer fix --verbose

cs_dry_run:
php-cs-fixer fix --verbose --dry-run

test:
phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml

0 comments on commit 2ed6053

Please sign in to comment.