Browse Source

Run phpcs in builds

Andreas Braun 8 years ago
parent
commit
341546f853
4 changed files with 54 additions and 1 deletions
  1. 1 0
      .gitignore
  2. 6 0
      .travis.yml
  3. 2 1
      composer.json
  4. 45 0
      phpcs.xml.dist

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 composer.lock
+.phpcs-cache
 vendor/
 tests/scripts/

+ 6 - 0
.travis.yml

@@ -58,6 +58,12 @@ jobs:
             - "mongodb-upstart"
           packages: ['mongodb-org-server']
 
+    - stage: Code Quality
+      env: CODING_STANDARDS
+      php: 7.1
+      script:
+        - ./vendor/bin/phpcs
+
 cache:
   directories:
     - $HOME/.composer/cache

+ 2 - 1
composer.json

@@ -15,7 +15,8 @@
         "mongodb/mongodb": "^1.0.1"
     },
     "require-dev": {
-        "phpunit/phpunit": "^5.7 || ^6.0"
+        "phpunit/phpunit": "^5.7 || ^6.0",
+        "squizlabs/php_codesniffer": "^3.2"
     },
     "provide": {
         "ext-mongo": "1.6.14"

+ 45 - 0
phpcs.xml.dist

@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<ruleset>
+    <arg name="basepath" value="."/>
+    <arg name="extensions" value="php"/>
+    <arg name="parallel" value="80"/>
+    <arg name="cache" value=".phpcs-cache"/>
+    <arg name="colors" />
+
+    <!-- Ignore warnings and show progress of the run -->
+    <arg value="np"/>
+
+    <file>lib</file>
+    <file>tests</file>
+
+    <rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
+        <exclude-pattern>*/tests/*</exclude-pattern>
+    </rule>
+
+    <!-- Import PSR-2 coding standard (base) -->
+    <rule ref="PSR2">
+        <!-- Using \Doctrine\Sniffs\Spacing\ControlStructureSniff instead -->
+        <exclude name="PSR2.ControlStructures.ControlStructureSpacing"/>
+    </rule>
+
+    <!-- Import PSR-2 coding standard (base) -->
+    <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
+        <exclude-pattern>*/lib/Mongo/*</exclude-pattern>
+    </rule>
+
+    <!-- Disallow else if in favour elseif -->
+    <rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
+        <type>error</type>
+    </rule>
+
+    <!-- Force whitespace after a type cast -->
+    <rule ref="Generic.Formatting.SpaceAfterCast" />
+
+    <!-- Force whitespace before and after concatenation -->
+    <rule ref="Squiz.Strings.ConcatenationSpacing">
+        <properties>
+            <property name="spacing" value="1"/>
+            <property name="ignoreNewlines" value="true"/>
+        </properties>
+    </rule>
+</ruleset>