Skip to content

Commit

Permalink
Merge pull request #150 from raphaelstolt/php-cs-fixer-improvement
Browse files Browse the repository at this point in the history
Enforce coding standards.
  • Loading branch information
jonathantorres committed Oct 5, 2016
2 parents 745ff89 + 91710a6 commit 299f9c7
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,6 @@

# composer
/vendor/

# PHP Coding Standards Fixer
.php_cs.cache
1 change: 1 addition & 0 deletions .php_cs
Expand Up @@ -6,6 +6,7 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setUsingCache(true)
->fixers(array(
'-psr0',
'short_array_syntax',
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -17,4 +17,5 @@ before_script:
- composer install -n

script:
- vendor/bin/php-cs-fixer fix --diff --verbose --dry-run
- composer test
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

#### v1.13.0 `2016-10-??`
- `Added`
- Coding standard checks based on the PHP Coding Standards Fixer are cached and validated via a Travis CI script. Done by [@raphaelstolt](https://github.com/raphaelstolt) and initiated by [@localheinz](https://github.com/localheinz).

#### v1.12.0 `2016-09-18`
- `Added`
- A generated `.gitmessage` template and a Composer script for it's configuration _can_ be used to improve the commit message quality and consistency. Done by [@raphaelstolt](https://github.com/raphaelstolt). See [#144](https://github.com/jonathantorres/construct/issues/144).
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -138,8 +138,7 @@ construct generate jonathantorres/logger -g
```

## Generate a PHP Coding Standards Fixer configuration?
The `--phpcs` option will generate a [PHP Coding Standards Fixer](http://cs.sensiolabs.org/) configuration
within the constructed project. The generated `.php_cs` configuration defaults to the `PSR-2` coding style guide.
The `--phpcs` option will generate a [PHP Coding Standards Fixer](http://cs.sensiolabs.org/) configuration within the constructed project and add a Travis CI script for validation during builds. The generated `.php_cs` configuration defaults to the `PSR-2` coding style guide.

```bash
construct generate jonathantorres/logger --phpcs
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/ConstructCommand.php
Expand Up @@ -216,12 +216,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<info>Project "' . $projectName . '" constructed.</info>');
}


/**
* Shows warnings and sets a new settings which overwrites
* invalid settings with default values.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
private function warnAndOverwriteInvalidSettingsWithDefaults($output)
Expand Down Expand Up @@ -251,7 +250,6 @@ private function warnAndOverwriteInvalidSettingsWithDefaults($output)
);
}


/**
* Determine if a configuration is applicable.
*
Expand Down
9 changes: 7 additions & 2 deletions src/Construct.php
Expand Up @@ -329,6 +329,7 @@ protected function phpcs()
$this->projectLower . '/' . '.php_cs'
);

$this->gitIgnores[] = '.php_cs.cache';
$this->exportIgnores[] = '.php_cs';
}

Expand All @@ -339,7 +340,12 @@ protected function phpcs()
*/
protected function travis()
{
$file = $this->file->get(__DIR__ . '/stubs/travis.stub');
if ($this->settings->withPhpcsConfiguration()) {
$file = $this->file->get(__DIR__ . '/stubs/travis.phpcs.stub');
} else {
$file = $this->file->get(__DIR__ . '/stubs/travis.stub');
}

$travisHelper = new Travis();
$phpVersionsToRunOnTravis = $travisHelper->phpVersionsToRun(
$travisHelper->phpVersionsToTest($this->settings->getPhpVersion())
Expand Down Expand Up @@ -542,7 +548,6 @@ protected function gitmessage()
$this->exportIgnores[] = '.gitmessage';
}


/**
* Do an initial composer install and require the set development packages
* in the constructed project.
Expand Down
3 changes: 2 additions & 1 deletion src/stubs/phpcs.stub
Expand Up @@ -6,4 +6,5 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array('-psr0'))
->finder($finder);
->finder($finder)
->setUsingCache(true);
13 changes: 13 additions & 0 deletions src/stubs/travis.phpcs.stub
@@ -0,0 +1,13 @@
language: php

php:
{phpVersions}

before_script:
- if [[ $TRAVIS_PHP_VERSION != hhvm && $TRAVIS_PHP_VERSION != nightly ]]; then phpenv config-rm xdebug.ini; fi
- travis_retry composer self-update
- travis_retry composer install --no-interaction

script:
- vendor/bin/php-cs-fixer fix --diff --verbose --dry-run
- composer test
1 change: 1 addition & 0 deletions tests/ConstructTest.php
Expand Up @@ -332,6 +332,7 @@ public function testProjectGenerationWithCodingStandardsFixer()

$this->assertSame($this->getStub('with-phpcs/phpcs'), $this->getFile('.php_cs'));
$this->assertSame($this->getStub('with-phpcs/gitattributes'), $this->getFile('.gitattributes'));
$this->assertSame($this->getStub('with-phpcs/travis'), $this->getFile('.travis.yml'));
$this->assertSame(
$this->getStub('with-phpcs/CONTRIBUTING'),
$this->getFile('CONTRIBUTING.md')
Expand Down
3 changes: 2 additions & 1 deletion tests/stubs/with-phpcs/phpcs.stub
Expand Up @@ -6,4 +6,5 @@ $finder = Symfony\CS\Finder\DefaultFinder::create()
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array('-psr0'))
->finder($finder);
->finder($finder)
->setUsingCache(true);
16 changes: 16 additions & 0 deletions tests/stubs/with-phpcs/travis.stub
@@ -0,0 +1,16 @@
language: php

php:
- hhvm
- nightly
- 5.6
- 7.0

before_script:
- if [[ $TRAVIS_PHP_VERSION != hhvm && $TRAVIS_PHP_VERSION != nightly ]]; then phpenv config-rm xdebug.ini; fi
- travis_retry composer self-update
- travis_retry composer install --no-interaction

script:
- vendor/bin/php-cs-fixer fix --diff --verbose --dry-run
- composer test

0 comments on commit 299f9c7

Please sign in to comment.