From b433739e2ca907e2f41ae538eac700b481f5290c Mon Sep 17 00:00:00 2001
From: Perreal Guillaume <guillaume.perreal@irstea.fr>
Date: Fri, 19 Apr 2019 11:48:14 +0200
Subject: [PATCH] =?UTF-8?q?Ajoute=20les=20(jeux=20de)=20r=C3=A8gles=20'ris?=
 =?UTF-8?q?ky'=20quand=20ils=20sont=20autoris=C3=A9s.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .php_cs        |  5 ++++-
 README.md      |  6 ++++--
 src/Config.php | 37 +++++++++++++++++--------------------
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/.php_cs b/.php_cs
index 8fc254c..255ca27 100644
--- a/.php_cs
+++ b/.php_cs
@@ -1,11 +1,14 @@
 <?php
 
 $finder = PhpCsFixer\Finder::create()
+    ->exclude('vendor')
     ->files()
     ->name('*.php')
-    ->in('src');
+    ->name('.php_cs')
+    ->in('.');
 
 return Irstea\CS\Config::create()
+    ->setRiskyAllowed(true)
     ->setIndent('    ')
     ->setLineEnding("\n")
     ->setFinder($finder);
diff --git a/README.md b/README.md
index bbcd1e4..de58a7b 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,7 @@ $finder = PhpCsFixer\Finder::create()
     ->in('.');
 
 return Irstea\CS\Config::create()
+    ->setRiskyAllowed(true) // recommandé pour les nouveaux projets, à tester avec de vieux projets.
     ->setIndent('    ')
     ->setLineEnding("\n")
     ->setFinder($finder);
@@ -32,7 +33,9 @@ return Irstea\CS\Config::create()
 
 Pour plus de détails, cf. https://cs.symfony.com/#usage
 
-Un modèle d'en-tête (cf. règle `header_comment`) peut être défini dans un fichier `.docheader`.  Les tags `%package%` et `%yearRange%` sont remplacés automatiquement à partir des informations du dépôt git et de `composer.json`.
+#### En-tête de fichiers
+
+Un modèle d'en-tête (cf. règle `header_comment`) peut être défini dans un fichier `.docheader`. Les tags `%package%` et `%yearRange%` sont remplacés automatiquement à partir des informations du dépôt git et de `composer.json`.
 
 Exemple :
 
@@ -44,7 +47,6 @@ For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.
 ```
 
-
 ### Usage
 
 ```shell
diff --git a/src/Config.php b/src/Config.php
index d88426b..e445a9c 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -41,15 +41,6 @@ final class Config extends PhpCsFixerConfig
      */
     private $docHeaderfile = '.docheader';
 
-    /**
-     * Config constructor.
-     */
-    public function __construct()
-    {
-        parent::__construct();
-        $this->setRiskyAllowed(true);
-    }
-
     /**
      * Set cacheFile.
      *
@@ -84,10 +75,6 @@ final class Config extends PhpCsFixerConfig
                 'concat_space'                              => ['spacing' => 'one'],
                 'method_argument_space'                     => ['ensure_fully_multiline' => true],
 
-                // Risky
-                'is_null'                                   => ['use_yoda_style' => false],
-                'non_printable_character'                   => ['use_escape_sequences_in_strings' => true],
-
                 // Safe
                 'align_multiline_comment'                   => true,
                 'array_syntax'                              => ['syntax' => 'short'],
@@ -108,7 +95,12 @@ final class Config extends PhpCsFixerConfig
                     'separate'    => 'bottom',
                     'header'      => $this->headerComment(),
                 ],
-            ]
+            ],
+            $this->getRiskyAllowed() ? [
+                // Risky
+                'is_null'                                   => ['use_yoda_style' => false],
+                'non_printable_character'                   => ['use_escape_sequences_in_strings' => true],
+            ] : []
         );
     }
 
@@ -166,13 +158,18 @@ final class Config extends PhpCsFixerConfig
     private function ruleSets()
     {
         $phpVersion = $this->findRequiredPHPVersion();
+        $risky = $this->getRiskyAllowed();
 
         return [
-            '@PSR2'           => true,
-            '@Symfony'        => true,
-            '@PHP56Migration' => $phpVersion >= 5.6,
-            '@PHP70Migration' => $phpVersion >= 7.0,
-            '@PHP71Migration' => $phpVersion >= 7.1,
+            '@PSR2'                 => true,
+            '@Symfony'              => true,
+            '@Symfony:risky'        => $risky,
+            '@PHP56Migration'       => $phpVersion >= 5.6,
+            '@PHP56Migration:risky' => $risky && $phpVersion >= 5.6,
+            '@PHP70Migration'       => $phpVersion >= 7.0,
+            '@PHP70Migration:risky' => $risky && $phpVersion >= 7.0,
+            '@PHP71Migration'       => $phpVersion >= 7.1,
+            '@PHP71Migration:risky' => $risky && $phpVersion >= 7.1,
         ];
     }
 
@@ -208,7 +205,7 @@ final class Config extends PhpCsFixerConfig
 
         if (file_exists('composer.json')) {
             $data = json_decode(file_get_contents('composer.json'), true);
-            if (is_array($data)) {
+            if (\is_array($data)) {
                 $this->composerConfig = $data;
             }
         }
-- 
GitLab