From 69f6727a92ead56d8fe3baebaccc08ce52d20a39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Tue, 1 Aug 2017 15:31:54 +0200
Subject: [PATCH] Configuration gitlab, phpcs, phpmd et php-cs-fixer.

---
 .gitignore     |  4 ++-
 .gitlab-ci.yml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 .php_cs.dist   |  1 +
 phpcs.xml.dist | 23 ++++++++++++++++++
 phpmd.xml      | 38 ++++++++++++++++-------------
 5 files changed, 114 insertions(+), 18 deletions(-)
 create mode 100644 .gitlab-ci.yml
 create mode 120000 .php_cs.dist
 create mode 100644 phpcs.xml.dist

diff --git a/.gitignore b/.gitignore
index 5aeaa1a3..ec72cb6c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@
 /components/
 /composer.lock
 /apigen
-/nbproject/private/
\ No newline at end of file
+/nbproject
+/.php_cs.cache
+/.idea
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..6534a7bb
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,66 @@
+
+cache:
+  key: "$CI_COMMIT_REF_NAME-$CI_JOB_NAME"
+  paths:
+    - $HOME/.composer/cache
+    - vendor/
+
+variables:
+  COMPOSER_NO_INTERACTION: "1"
+  COMPOSER_ALLOW_SUPERUSER: "1"
+  S6_TARGET: none
+  DEBIAN_FRONTEND: noninteractive
+
+phpunit:
+  stage: test
+  tags: [docker]
+  image: isdevtools.irstea.fr/poleis/php-apache2:stretch-7.1
+  before_script:
+    - phpenmod pdo_sqlite curl
+    - composer update --prefer-dist --no-progress --ansi --no-suggest --prefer-stable
+  script:
+    - vendor/bin/phpunit
+
+.static-analysis: &static-analysis
+  stage: test
+  tags: [docker]
+  image: isdevtools.irstea.fr/poleis/php-analysis:7.1
+
+phploc:
+  <<: *static-analysis
+  script:
+    - phploc --exclude=vendor .
+
+lint:
+  <<: *static-analysis
+  script:
+    - parallel-lint  -j $(nproc) --exclude vendor .
+
+phpcs:
+  <<: *static-analysis
+  script:
+    - phpcs --colors --parallel=$(nproc) .
+  allow_failure: true
+
+phpcpd:
+  <<: *static-analysis
+  script:
+    - phpcpd --exclude=vendor --fuzzy .
+
+phpmd:
+  <<: *static-analysis
+  script:
+    - phpmd . text ./phpmd.xml --suffixes=php
+  allow_failure: true
+
+satis:
+    stage: deploy
+    tags: [shell]
+    image: alpine
+    variables:
+        GIT_STRATEGY: none
+    before_script:
+        - apk update && apk add curl
+    script:
+        - curl -sS "https://isdevtools.irstea.fr/satis/trigger.php?package=irstea/$CI_PROJECT_NAME"
+
diff --git a/.php_cs.dist b/.php_cs.dist
new file mode 120000
index 00000000..6794dc55
--- /dev/null
+++ b/.php_cs.dist
@@ -0,0 +1 @@
+/home/guillaume.perreal/.config/devtools/php/.php_cs.dist
\ No newline at end of file
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 00000000..ded85440
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<ruleset name="Irstea" namespace="Irstea\Standard">
+
+    <description>Coding standard of Irstea, pôle informatique scientifique</description>
+
+    <file>src</file>
+
+    <arg name="encoding" value="utf-8"/>
+    <arg value="sp"/>
+
+    <rule ref="PSR2"/>
+
+    <rule ref="Generic.Files.LineLength">
+        <properties>
+            <property name="lineLimit" value="140"/>
+        </properties>
+    </rule>
+
+    <exclude-pattern>vendor/</exclude-pattern>
+    <exclude-pattern>node_modules/</exclude-pattern>
+    <exclude-pattern>cache/</exclude-pattern>
+
+</ruleset>
diff --git a/phpmd.xml b/phpmd.xml
index bd97d4f3..a7731302 100755
--- a/phpmd.xml
+++ b/phpmd.xml
@@ -1,30 +1,34 @@
 <?xml version="1.0"?>
-<ruleset name="SYGADE PHPMD rule set"
+<ruleset name="Irstea PHPMD ruleset"
          xmlns="http://pmd.sf.net/ruleset/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
-         xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd">
+         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd">
 
-    <rule ref="rulesets/codesize.xml/ExcessiveMethodLength" />
-    <rule ref="rulesets/codesize.xml/ExcessiveClassLength" />
-    <rule ref="rulesets/codesize.xml/ExcessiveParameterList" />
+    <description>Irstea ruleset</description>
 
-    <rule ref="rulesets/controversial.xml" />
-    <rule ref="rulesets/unusedcode.xml" />
+    <rule ref="rulesets/unusedcode.xml"/>
+    <rule ref="rulesets/codesize.xml"/>
+    <rule ref="rulesets/design.xml"/>
+    <rule ref="rulesets/controversial.xml"/>
 
-    <rule ref="rulesets/design.xml/ExitExpression" />
-    <rule ref="rulesets/design.xml/EvalExpression" />
-    <rule ref="rulesets/design.xml/GotoStatement" />
+    <rule ref="rulesets/cleancode.xml/StaticAccess">
+        <properties>
+            <property name="exceptions" value="\DateTime,\DateTimeZone,\Doctrine\DBAL\Types\ConversionException"/>
+        </properties>
+    </rule>
+
+    <rule ref="rulesets/naming.xml">
+        <exclude name="ShortVariable"/>
+    </rule>
 
     <rule ref="rulesets/naming.xml/ShortVariable">
         <properties>
-            <property name="exceptions" value="id,em" />
+            <property name="exceptions" value="em,tz,i,j,id,x,y,dn,fh,ex"/>
         </properties>
     </rule>
-    <rule ref="rulesets/naming.xml/LongVariable" />
-    <rule ref="rulesets/naming.xml/ShortMethodName" />
-    <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
-    <rule ref="rulesets/naming.xml/ConstantNamingConventions" />
-    <rule ref="rulesets/naming.xml/BooleanGetMethodName" />
+
+    <exclude-pattern>vendor/</exclude-pattern>
+    <exclude-pattern>node_modules/</exclude-pattern>
+    <exclude-pattern>.*/cache/</exclude-pattern>
 
 </ruleset>
-- 
GitLab