From e58e013f4b768d5ab6b5a3535b2e5363c3cd330a Mon Sep 17 00:00:00 2001
From: Bertrand Gauthier <bertrand.gauthier@unicaen.fr>
Date: Wed, 6 Mar 2019 17:08:31 +0100
Subject: [PATCH] Artefacts de test de phan/phan et squizlabs/php_codesniffer.

---
 .phan/config.php        | 127 ++++++++++++++++++++++++++++++++++++++++
 bin/.gitignore          |   1 +
 bin/check-compat.md     |  52 ++++++++++++++++
 bin/check-compat.sh     |  33 +++++++++++
 bin/docker-build-app.sh |  32 ++++++++++
 bin/phpcs.sh            |  35 +++++++++++
 ruleset.xml             |   8 +++
 7 files changed, 288 insertions(+)
 create mode 100644 .phan/config.php
 create mode 100644 bin/.gitignore
 create mode 100644 bin/check-compat.md
 create mode 100755 bin/check-compat.sh
 create mode 100755 bin/docker-build-app.sh
 create mode 100755 bin/phpcs.sh
 create mode 100644 ruleset.xml

diff --git a/.phan/config.php b/.phan/config.php
new file mode 100644
index 0000000..906c5df
--- /dev/null
+++ b/.phan/config.php
@@ -0,0 +1,127 @@
+<?php
+
+/**
+ * This configuration will be read and overlaid on top of the
+ * default configuration. Command line arguments will be applied
+ * after this file is read.
+ */
+return [
+    // Supported values: `'5.6'`, `'7.0'`, `'7.1'`, `'7.2'`, `'7.3'`, `null`.
+    // If this is set to `null`,
+    // then Phan assumes the PHP version which is closest to the minor version
+    // of the php executable used to execute Phan.
+    //
+    // Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
+    // (See `backward_compatibility_checks` for additional options)
+    // TODO: Set this.
+    'target_php_version' => null,
+
+    // Backwards Compatibility Checking. This is very slow
+    // and expensive, but you should consider running
+    // it before upgrading your version of PHP from 5.x to 7.0,
+    // due to the backward compatibility breaks of parsing in PHP 7.0
+    'backward_compatibility_checks' => false,
+
+    // Added in 0.10.0. Set this to false to emit
+    // PhanUndeclaredFunction issues for internal functions
+    // that Phan has signatures for,
+    // but aren't available in the codebase or the
+    // internal functions used to run phan
+    'ignore_undeclared_functions_with_known_signatures' => false,
+
+    // If empty, no filter against issues types will be applied.
+    // If this white-list is non-empty, only issues within the list
+    // will be emitted by Phan.
+    'whitelist_issue_types' => [
+        'PhanCompatiblePHP7',  // This only checks for **syntax** where the parsing may have changed. This check is enabled by `backward_compatibility_checks`
+        'PhanDeprecatedFunctionInternal',  // Warns about a few functions deprecated in 7.0 and later.
+        'PhanUndeclaredFunction',  // Check for removed functions such as split() that were deprecated in php 5.x and removed in php 7.0.
+
+//        'PhanDeprecatedClass'                            => 'PhanDeprecatedClass',
+//        'PhanDeprecatedFunction'                         => 'PhanDeprecatedFunction',
+//        'PhanDeprecatedInterface'                        => 'PhanDeprecatedInterface',
+//        'PhanDeprecatedTrait'                            => 'PhanDeprecatedTrait',
+        'PhanParamSignatureMismatch'                     => 'PhanParamSignatureMismatch',
+//        'PhanParamSignatureRealMismatchHasParamType'     => 'PhanParamSignatureRealMismatchHasParamType',
+//        'PhanParamSignatureRealMismatchParamType'        => 'PhanParamSignatureRealMismatchParamType',
+//        'PhanParamSignatureRealMismatchTooFewParameters' => 'PhanParamSignatureRealMismatchTooFewParameters',
+        'PhanParamTooFew'                                => 'PhanParamTooFew',
+//        'PhanParamTooMany'                               => 'PhanParamTooMany',
+//        'PhanParamTooManyInternal'                       => 'PhanParamTooManyInternal',
+//        'PhanSyntaxError'                                => 'PhanSyntaxError',
+//        'PhanTypeMismatchArgument'                       => 'PhanTypeMismatchArgument',
+//        'PhanTypeMismatchArgumentInternal'               => 'PhanTypeMismatchArgumentInternal',
+//        'PhanTypeMismatchDeclaredParam'                  => 'PhanTypeMismatchDeclaredParam',
+//        'PhanTypeMismatchDeclaredParamNullable'          => 'PhanTypeMismatchDeclaredParamNullable',
+//        'PhanTypeMismatchDefault'                        => 'PhanTypeMismatchDefault',
+//        'PhanTypeMismatchForeach'                        => 'PhanTypeMismatchForeach',
+//        'PhanTypeMismatchProperty'                       => 'PhanTypeMismatchProperty',
+//        'PhanTypeMismatchReturn'                         => 'PhanTypeMismatchReturn',
+//        'PhanTypeMissingReturn'                          => 'PhanTypeMissingReturn',
+//        'PhanUndeclaredClassInstanceof'                  => 'PhanUndeclaredClassInstanceof',
+//        'PhanUnreferencedUseNormal'                      => 'PhanUnreferencedUseNormal',
+        'PhanContinueTargetingSwitch'                   =>'PhanContinueTargetingSwitch', // This detects code causing a warning in PHP 7.3.
+    ],
+
+    // A list of directories that should be parsed for class and
+    // method information. After excluding the directories
+    // defined in exclude_analysis_directory_list, the remaining
+    // files will be statically analyzed for errors.
+    //
+    // Thus, both first-party and third-party code being used by
+    // your application should be included in this list.
+    'directory_list' => [
+        'module',
+        'vendor',
+        'vendor/unicaen',
+        'vendor/zf-commons',
+    ],
+
+    // A directory list that defines files that will be excluded
+    // from static analysis, but whose class and method
+    // information should be included.
+    //
+    // Generally, you'll want to include the directories for
+    // third-party code (such as "vendor/") in this list.
+    //
+    // n.b.: If you'd like to parse but not analyze 3rd
+    //       party code, directories containing that code
+    //       should be added to both the `directory_list`
+    //       and `exclude_analysis_directory_list` arrays.
+    'exclude_analysis_directory_list' => [
+        'vendor/bin',
+        'vendor/composer',
+        'vendor/container-interop',
+        'vendor/dealerdirect',
+        'vendor/doctrine',
+        'vendor/easybook',
+        'vendor/felixfbecker',
+        'vendor/jasig',
+        'vendor/microsoft',
+        'vendor/mpdf',
+        'vendor/myclabs',
+        'vendor/netresearch',
+        'vendor/paragonie',
+        'vendor/phan',
+        'vendor/phpcompatibility',
+        'vendor/phpdocumentor',
+        'vendor/phpspec',
+        'vendor/phpunit',
+        'vendor/psr',
+        'vendor/ramsey',
+        'vendor/sabre',
+        'vendor/sebastian',
+        'vendor/setasign',
+        'vendor/slevomat',
+        'vendor/squizlabs',
+        'vendor/symfony',
+        'vendor/true',
+//        'vendor/unicaen',
+        'vendor/webmozart',
+        'vendor/zendframework',
+//        'vendor/zf-commons',
+
+        'vendor/unicaen/code/code/template',
+        'vendor/unicaen/bjy-authorize/tests',
+    ],
+];
diff --git a/bin/.gitignore b/bin/.gitignore
new file mode 100644
index 0000000..a9a1bd3
--- /dev/null
+++ b/bin/.gitignore
@@ -0,0 +1 @@
+reports/
diff --git a/bin/check-compat.md b/bin/check-compat.md
new file mode 100644
index 0000000..a40d746
--- /dev/null
+++ b/bin/check-compat.md
@@ -0,0 +1,52 @@
+# check-compat
+
+Tester la compatibilité des bibliothèques `unicaen/*` avec une version précise de PHP.
+
+## PHP 7.0
+
+```bash
+docker run \
+--rm \
+-v ${PWD}:/app \
+--workdir /app \
+unicaen-dev-php7.0-apache \
+./bin/check-compat.sh 7.0
+
+```
+
+## PHP 7.1
+
+```bash
+docker run \
+--rm \
+-v ${PWD}:/app \
+--workdir /app \
+unicaen-dev-php7.0-apache \
+./bin/check-compat.sh 7.1
+
+```
+
+## PHP 7.2
+
+```bash
+docker run \
+--rm \
+-v ${PWD}:/app \
+--workdir /app \
+unicaen-dev-php7.0-apache \
+./bin/check-compat.sh 7.2
+
+```
+
+## PHP 7.3
+
+```bash
+docker run \
+--rm \
+-v ${PWD}:/app \
+--workdir /app \
+unicaen-dev-php7.0-apache \
+./bin/check-compat.sh 7.3
+
+```
+
diff --git a/bin/check-compat.sh b/bin/check-compat.sh
new file mode 100755
index 0000000..9381672
--- /dev/null
+++ b/bin/check-compat.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+[[ -z $1 ]] && echo "Veuillez spécifier les versions de PHP désirées (ex: 7.1 7.2 7.3)." && exit 1
+
+DIR=$(cd `dirname $0` && pwd)
+DIRNAME=$(basename ${DIR})
+
+cd ${DIR}/..
+
+versions=$1
+
+phpcs="./vendor/bin/phpcs"
+libdir="./vendor/unicaen"
+outdir="./${DIRNAME}/reports"
+
+mkdir -p ${outdir} #&& rm -rf ${outdir}/*
+
+for path in ${libdir}/*
+do
+    dirname=$(basename -- "$path")
+    for ver in "$1"
+    do
+        reportpath="${outdir}/compat-unicaen-${dirname}-${ver}.txt"
+        echo "Processing '${path}' against PHP version ${ver}"
+        echo "=> reporting into '${reportpath}'"
+        ${phpcs} \
+            -p \
+            --standard=PHPCompatibility \
+            --runtime-set testVersion ${ver} \
+            --report-full=${reportpath} \
+            ${path}
+    done
+done
diff --git a/bin/docker-build-app.sh b/bin/docker-build-app.sh
new file mode 100755
index 0000000..d9d9457
--- /dev/null
+++ b/bin/docker-build-app.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+DIR=$(cd `dirname $0` && pwd)
+
+cd ${DIR}/..
+
+docker build --rm -t skeleton-app-7.0 -f Dockerfile-7.0 .
+docker rm -f skeleton-app-7.0-container
+docker run --rm -d -p 8070:80 -p 8470:443 -v ${PWD}/.phan:/app/.phan --name skeleton-app-7.0-container skeleton-app-7.0
+docker exec skeleton-app-7.0-container composer update --no-suggest --optimize-autoloader
+
+docker build --rm -t skeleton-app-7.1 -f Dockerfile-7.1 .
+docker rm -f skeleton-app-7.1-container
+docker run --rm -d -p 8071:80 -p 8471:443 -v ${PWD}/.phan:/app/.phan --name skeleton-app-7.1-container skeleton-app-7.1
+docker exec skeleton-app-7.1-container composer update --no-suggest --optimize-autoloader
+
+docker build --rm -t skeleton-app-7.2 -f Dockerfile-7.2 .
+docker rm -f skeleton-app-7.2-container
+docker run --rm -d -p 8072:80 -p 8472:443 -v ${PWD}/.phan:/app/.phan --name skeleton-app-7.2-container skeleton-app-7.2
+docker exec skeleton-app-7.2-container composer update --no-suggest --optimize-autoloader
+
+docker build --rm -t skeleton-app-7.3 -f Dockerfile-7.3 .
+docker rm -f skeleton-app-7.3-container
+docker run --rm -d -p 8073:80 -p 8473:443 -v ${PWD}/.phan:/app/.phan --name skeleton-app-7.3-container skeleton-app-7.3
+docker exec skeleton-app-7.3-container composer update --no-suggest --optimize-autoloader
+
+
+
+# v=7.0 ; docker exec skeleton-app-$v-container vendor/bin/phan --target-php-version $v > /tmp/phan-$v.log
+# v=7.1 ; docker exec skeleton-app-$v-container vendor/bin/phan --target-php-version $v > /tmp/phan-$v.log
+# v=7.2 ; docker exec skeleton-app-$v-container vendor/bin/phan --target-php-version $v > /tmp/phan-$v.log
+# v=7.3 ; docker exec skeleton-app-$v-container vendor/bin/phan --target-php-version $v > /tmp/phan-$v.log
diff --git a/bin/phpcs.sh b/bin/phpcs.sh
new file mode 100755
index 0000000..e172955
--- /dev/null
+++ b/bin/phpcs.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+[[ -z $1 ]] && echo "Veuillez spécifier la version de PHP désirée (ex: 7.1)." && exit 1
+
+DIR=$(cd `dirname $0` && pwd)
+DIRNAME=$(basename ${DIR})
+
+cd ${DIR}/..
+
+version=$1
+
+# conversion de la version spécifiée au format PHP_VERSION_ID, ex: "7.2" devien "70200"
+a=(${version//./ })
+PHP_VERSION_ID=$((a[0]*10000+a[1]*100+a[2]))
+
+phpcs="./vendor/bin/phpcs"
+libdir="./vendor/unicaen"
+outdir="./${DIRNAME}/reports"
+
+mkdir -p ${outdir} #&& rm -rf ${outdir}/*
+
+for path in ${libdir}/*
+do
+    dirname=$(basename -- "$path")
+    reportpath="${outdir}/phpcs-unicaen-${dirname}-${version}.txt"
+    echo "Processing '${path}' against PHP version ${version} (PHP_VERSION_ID=${PHP_VERSION_ID})"
+    echo "=> reporting into '${reportpath}'"
+    ${phpcs} \
+        -p \
+         --standard=ruleset.xml \
+        --runtime-set php_version ${PHP_VERSION_ID} \
+        --report-full=${reportpath} \
+        ${path}
+done
+
diff --git a/ruleset.xml b/ruleset.xml
new file mode 100644
index 0000000..77f9654
--- /dev/null
+++ b/ruleset.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<ruleset name="unicaen-skeleton-application">
+    <!-- relative path from PHPCS source location -->
+    <config name="installed_paths" value="vendor/slevomat/coding-standard"/>
+
+    <!-- specific sniffs to include -->
+    <rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/DeclareStrictTypesSniff.php" />
+</ruleset>
-- 
GitLab