Skip to content

Commit

Permalink
Add php-cs-fixer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bcremer committed Sep 15, 2016
1 parent 27507fe commit d6fae04
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
./Icon?
ehthumbs.db
Thumbs.db

# SASS/SCSS cache
.sass-cache/

Expand All @@ -33,6 +32,7 @@ Thumbs.db
/config_*.php

# Caches/Proxies
.php_cs.cache
/tests/Shopware/TempFiles/*
!/tests/Shopware/TempFiles/.gitkeep
/var/cache/*
Expand Down
16 changes: 16 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$finder = Symfony\CS\Finder::create()
->in(__DIR__.'/engine/Library/Enlight')
->in(__DIR__.'/engine/Shopware')
->in(__DIR__.'/tests')
;

return Symfony\CS\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
'-psr0', // tests are using a PSR-4 path that is not PSR-0 compatible
])
->finder($finder)
;
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ When coding and committing, please:
All contributions should follow the [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) and [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) coding
standards.

To check for CS issues:

composer cs-check

You can also fix reported errors automatically:

composer cs-fix

If you use `composer cs-fix` to fix issues, make certain you add and commit any files changed!

# Start hacking

Expand Down
10 changes: 4 additions & 6 deletions build/gitHooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*
* This pre-commit hooks will check for PHP errors (lint), and make sure the
* code is PSR-2 compliant.
*
* Dependecy: PHP-CS-Fixer (http://cs.sensiolabs.org/)
*/

class PreCommitChecks
Expand Down Expand Up @@ -48,7 +46,7 @@ class PreCommitChecks
echo "ERROR: Your commit does not comply with Shopware's coding standards." . PHP_EOL;
}
} else {
echo "ERROR: PHP-CS-Fixer is NOT installed. Please install globally (http://cs.sensiolabs.org/)." . PHP_EOL;
echo "ERROR: ./vendor/bin/php-cs-fixer is NOT installed. Please install composer with dev dependencies" . PHP_EOL;
$this->error = true;
}

Expand All @@ -74,7 +72,7 @@ class PreCommitChecks
{
$output = [];
$return = 0;
exec('command -v php-cs-fixer >/dev/null 2>&1', $output, $return);
exec('command -v ./vendor/bin/php-cs-fixer >/dev/null 2>&1', $output, $return);

return !(bool) $return;
}
Expand Down Expand Up @@ -108,9 +106,9 @@ class PreCommitChecks
foreach ($files as $file) {
$output = [];
$return = null;
exec("php-cs-fixer fix -v --dry-run --level=psr2 " . escapeshellarg($file), $output, $return);
exec("./vendor/bin/php-cs-fixer fix -v --config-file=.php_cs --no-ansi --dry-run " . escapeshellarg($file). ' 2>&1', $output, $return);
if ($return != 0) {
$misses[$file] = "php-cs-fixer fix -v --level=psr2 " . escapeshellarg($file);
$misses[$file] = "./vendor/bin/php-cs-fixer fix -v --config-file=.php_cs " . escapeshellarg($file);
$this->error = true;
$succeed = false;
}
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"behat/mink-goutte-driver": "~1.2",
"behat/mink-selenium2-driver": "~1.3",
"sensiolabs/behat-page-object-extension": "~2.0.0-rc1",
"symfony/dom-crawler": "~2.8"
"symfony/dom-crawler": "~2.8",
"friendsofphp/php-cs-fixer": "^1.12"
},
"include-path": [
"engine/Library/"
Expand Down Expand Up @@ -112,6 +113,8 @@
}
},
"scripts": {
"cs-check": "php-cs-fixer fix --dry-run -v",
"cs-fix": "php-cs-fixer fix -v",
"test": "phpunit -c tests/ --colors=always",
"test-unit": "phpunit -c tests/phpunit_unit.xml.dist --colors=always"
}
Expand Down
160 changes: 158 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions engine/Library/Enlight/Components/Session/Namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
* @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
* @license http://enlight.de/license New BSD License
*/
class Enlight_Components_Session_Namespace
extends Zend_Session_Namespace
implements Countable, IteratorAggregate, ArrayAccess
class Enlight_Components_Session_Namespace extends Zend_Session_Namespace implements Countable, IteratorAggregate, ArrayAccess
{
/**
* Whether an offset exists
Expand Down
4 changes: 1 addition & 3 deletions engine/Library/Enlight/Controller/Response/ResponseCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
* @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
* @license http://enlight.de/license New BSD License
*/
class Enlight_Controller_Response_ResponseCli
extends Zend_Controller_Response_Cli
implements Enlight_Controller_Response_Response
class Enlight_Controller_Response_ResponseCli extends Zend_Controller_Response_Cli implements Enlight_Controller_Response_Response
{
}
4 changes: 1 addition & 3 deletions engine/Library/Enlight/Controller/Response/ResponseHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
* @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
* @license http://enlight.de/license New BSD License
*/
class Enlight_Controller_Response_ResponseHttp
extends Zend_Controller_Response_Http
implements Enlight_Controller_Response_Response
class Enlight_Controller_Response_ResponseHttp extends Zend_Controller_Response_Http implements Enlight_Controller_Response_Response
{
/**
* @var array Contains all cookies which have been set over the "setCookie" function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
* @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
* @license http://enlight.de/license New BSD License
*/
class Enlight_Controller_Response_ResponseTestCase
extends Zend_Controller_Response_HttpTestCase
implements Enlight_Controller_Response_Response
class Enlight_Controller_Response_ResponseTestCase extends Zend_Controller_Response_HttpTestCase implements Enlight_Controller_Response_Response
{
/**
* @var array Contains all cookies, which have been set by the "setCookie" function.
Expand Down

0 comments on commit d6fae04

Please sign in to comment.