Skip to content

Commit

Permalink
Merge branch 'PatchRanger-PatchRanger-php-cs-fixer' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhartless committed Sep 30, 2016
2 parents 2a682d8 + 8f65fbd commit f76affa
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Features that are determined not to fit within the direction of the Mautic Core

### Coding Standards

Mautic tries to follow [Symfony's coding standards](http://symfony.com/doc/current/contributing/code/standards.html) and thus we ask the same of any code submitted through pull requests.
Mautic follows [Symfony's coding standards](http://symfony.com/doc/current/contributing/code/standards.html) by implementing pre-commit git hook running [php-cs-fixer](https://github.com/friendsofphp/php-cs-fixer), which is installed and updated with `composer install`/`composer update`.

In addition to Symfony's coding standards, please appropriately indent code using 4 spaces rather than a tab. If using PhpStorm, a code style settings file can be found [here](https://gist.github.com/alanhartless/f3ad051108351a3fcffd). Simply add it to the project's .idea folder then through PhpStorm's preferences, browse to Editor -> Code Style -> PHP and select "Symfony" as the Scheme.
All code styling is handled automatically by the aforementioned git hook. In case if you setup git hook correctly (which is true if you ever run `composer install`/`composer update` before creating a pull request), you can format your code as you like - it will be converted to Mautic code style automatically.

### Pull Request Description Format

Expand Down
9 changes: 9 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'align_double_arrow',
'align_equals',
'ordered_use',
'short_array_syntax',
]);
27 changes: 27 additions & 0 deletions build/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

ROOT=$(git rev-parse --show-toplevel)

echo "php-cs-fixer pre commit hook start"

PHP_CS_FIXER="bin/php-cs-fixer"
HAS_PHP_CS_FIXER=false

if [ -x $PHP_CS_FIXER ]; then
HAS_PHP_CS_FIXER=true
fi

if $HAS_PHP_CS_FIXER; then
git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do
$PHP_CS_FIXER fix --config-file=$ROOT/.php_cs --verbose "$line";
git add "$line";
done
else
echo ""
echo "Please install php-cs-fixer, e.g.:"
echo ""
echo " composer require --dev friendsofphp/php-cs-fixer"
echo ""
fi

echo "php-cs-fixer pre commit hook finish"
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"sensio/generator-bundle": "~3.0",
"babdev/transifex": "~1.0",
"webfactory/exceptions-bundle": "~4.3",
"phpunit/phpunit": "4.5"
"phpunit/phpunit": "4.5",
"friendsofphp/php-cs-fixer": "^1.12"
},
"repositories": [
{
Expand All @@ -120,11 +121,13 @@
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache"
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"cp ./build/hooks/pre-commit ./.git/hooks/pre-commit"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache"
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"cp ./build/hooks/pre-commit ./.git/hooks/pre-commit"
]
},
"config": {
Expand Down
62 changes: 60 additions & 2 deletions composer.lock

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

0 comments on commit f76affa

Please sign in to comment.