diff --git a/.php_cs b/.php_cs index 8fc254c1327d3c6b19b71343d916b52eea9e4aae..255ca27c2aba081cdcf985d2ccf29798ce02708b 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 bbcd1e4f612d8fedb7682d21701329ce62ff77b1..de58a7b46826e9eac905a6e6f73caa8ff314bf5b 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 d88426b0b65a31c4a38566b94b91fb79ef76d769..e445a9c5398ab693a1cdb31f0a019458174c751c 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; } }