浏览代码

PHP CS Fixer install

Sullivan SENECHAL 10 年之前
父节点
当前提交
b0b75b6bc2
共有 6 个文件被更改,包括 45 次插入2 次删除
  1. 1 0
      .gitignore
  2. 20 0
      .php_cs
  3. 5 1
      .travis.yml
  4. 11 0
      CONTRIBUTING.md
  5. 6 0
      Makefile
  6. 2 1
      composer.json

+ 1 - 0
.gitignore

@@ -7,6 +7,7 @@ coverage
 composer.lock
 composer.lock
 /vendor
 /vendor
 composer.phar
 composer.phar
+.php_cs.cache
 
 
 # clean up some non bower ready package
 # clean up some non bower ready package
 Resources/public/vendor/admin-lte/bootstrap
 Resources/public/vendor/admin-lte/bootstrap

+ 20 - 0
.php_cs

@@ -0,0 +1,20 @@
+<?php
+
+$finder = Symfony\CS\Finder\DefaultFinder::create()
+    ->in(array(__DIR__))
+    ->exclude(array('Tests/Fixtures'))
+;
+
+return Symfony\CS\Config\Config::create()
+    ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
+    ->fixers(array(
+        '-unalign_double_arrow',
+        '-unalign_equals',
+        'align_double_arrow',
+        'newline_after_open_tag',
+        'ordered_use',
+        'long_array_syntax',
+    ))
+    ->setUsingCache(true)
+    ->finder($finder)
+;

+ 5 - 1
.travis.yml

@@ -23,6 +23,8 @@ env:
 matrix:
 matrix:
   fast_finish: true
   fast_finish: true
   include:
   include:
+    - php: 5.6
+      env: CS_FIXER=run
     - php: 5.3
     - php: 5.3
       env: COMPOSER_FLAGS="--prefer-lowest"
       env: COMPOSER_FLAGS="--prefer-lowest"
     - php: 5.6
     - php: 5.6
@@ -51,7 +53,9 @@ before_script:
   - export PATH=$HOME/.local/bin:$PATH
   - export PATH=$HOME/.local/bin:$PATH
   - pip install -r Resources/doc/requirements.txt --user `whoami`
   - pip install -r Resources/doc/requirements.txt --user `whoami`
 
 
-script: make test
+script:
+ - if [ "$CS_FIXER" = "run" ]; then make cs_dry_run ; fi;
+ - make test
 
 
 notifications:
 notifications:
   webhooks: https://sonata-project.org/bundles/admin/master/travis
   webhooks: https://sonata-project.org/bundles/admin/master/travis

+ 11 - 0
CONTRIBUTING.md

@@ -27,6 +27,17 @@ desperately need to see some commits get merged on the older branches (`2.0`,
 are no longer supported and your changes will probably not get merged in more
 are no longer supported and your changes will probably not get merged in more
 recent branches.
 recent branches.
 
 
+### Matching coding standards
+
+Before each commit, be sure to match sonata coding standards by running the following command for fix:
+
+```bash
+make cs
+```
+
+And then, add fixed file to your commit before push.
+
+Be sure to add only **your modified files**. If another files are fixed by cs tools, just revert it before commit.
 
 
 ### Sending a Pull Request
 ### Sending a Pull Request
 
 

+ 6 - 0
Makefile

@@ -1,3 +1,9 @@
+cs:
+	./vendor/bin/php-cs-fixer fix --verbose
+
+cs_dry_run:
+	./vendor/bin/php-cs-fixer fix --verbose --dry-run
+
 test:
 test:
 	phpunit
 	phpunit
 	cd Resources/doc && sphinx-build -W -b html -d _build/doctrees . _build/html
 	cd Resources/doc && sphinx-build -W -b html -d _build/doctrees . _build/html

+ 2 - 1
composer.json

@@ -45,7 +45,8 @@
         "sensio/generator-bundle": "~2.3",
         "sensio/generator-bundle": "~2.3",
         "symfony/yaml": "~2.3",
         "symfony/yaml": "~2.3",
         "sonata-project/intl-bundle": "~2.1",
         "sonata-project/intl-bundle": "~2.1",
-        "symfony/phpunit-bridge": "~2.7|~3.0"
+        "symfony/phpunit-bridge": "~2.7|~3.0",
+        "fabpot/php-cs-fixer": "~0.5|~1.0"
     },
     },
     "suggest": {
     "suggest": {
         "jms/translation-bundle": "Extract message keys from Admins",
         "jms/translation-bundle": "Extract message keys from Admins",