Commit b433739e authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajoute les (jeux de) règles 'risky' quand ils sont autorisés.

Showing with 25 additions and 23 deletions
+25 -23
<?php <?php
$finder = PhpCsFixer\Finder::create() $finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->files() ->files()
->name('*.php') ->name('*.php')
->in('src'); ->name('.php_cs')
->in('.');
return Irstea\CS\Config::create() return Irstea\CS\Config::create()
->setRiskyAllowed(true)
->setIndent(' ') ->setIndent(' ')
->setLineEnding("\n") ->setLineEnding("\n")
->setFinder($finder); ->setFinder($finder);
......
...@@ -25,6 +25,7 @@ $finder = PhpCsFixer\Finder::create() ...@@ -25,6 +25,7 @@ $finder = PhpCsFixer\Finder::create()
->in('.'); ->in('.');
return Irstea\CS\Config::create() return Irstea\CS\Config::create()
->setRiskyAllowed(true) // recommandé pour les nouveaux projets, à tester avec de vieux projets.
->setIndent(' ') ->setIndent(' ')
->setLineEnding("\n") ->setLineEnding("\n")
->setFinder($finder); ->setFinder($finder);
...@@ -32,7 +33,9 @@ return Irstea\CS\Config::create() ...@@ -32,7 +33,9 @@ return Irstea\CS\Config::create()
Pour plus de détails, cf. https://cs.symfony.com/#usage 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 : Exemple :
...@@ -44,7 +47,6 @@ For the full copyright and license information, please view the LICENSE ...@@ -44,7 +47,6 @@ For the full copyright and license information, please view the LICENSE
file that was distributed with this source code. file that was distributed with this source code.
``` ```
### Usage ### Usage
```shell ```shell
......
...@@ -41,15 +41,6 @@ final class Config extends PhpCsFixerConfig ...@@ -41,15 +41,6 @@ final class Config extends PhpCsFixerConfig
*/ */
private $docHeaderfile = '.docheader'; private $docHeaderfile = '.docheader';
/**
* Config constructor.
*/
public function __construct()
{
parent::__construct();
$this->setRiskyAllowed(true);
}
/** /**
* Set cacheFile. * Set cacheFile.
* *
...@@ -84,10 +75,6 @@ final class Config extends PhpCsFixerConfig ...@@ -84,10 +75,6 @@ final class Config extends PhpCsFixerConfig
'concat_space' => ['spacing' => 'one'], 'concat_space' => ['spacing' => 'one'],
'method_argument_space' => ['ensure_fully_multiline' => true], 'method_argument_space' => ['ensure_fully_multiline' => true],
// Risky
'is_null' => ['use_yoda_style' => false],
'non_printable_character' => ['use_escape_sequences_in_strings' => true],
// Safe // Safe
'align_multiline_comment' => true, 'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'], 'array_syntax' => ['syntax' => 'short'],
...@@ -108,7 +95,12 @@ final class Config extends PhpCsFixerConfig ...@@ -108,7 +95,12 @@ final class Config extends PhpCsFixerConfig
'separate' => 'bottom', 'separate' => 'bottom',
'header' => $this->headerComment(), '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 ...@@ -166,13 +158,18 @@ final class Config extends PhpCsFixerConfig
private function ruleSets() private function ruleSets()
{ {
$phpVersion = $this->findRequiredPHPVersion(); $phpVersion = $this->findRequiredPHPVersion();
$risky = $this->getRiskyAllowed();
return [ return [
'@PSR2' => true, '@PSR2' => true,
'@Symfony' => true, '@Symfony' => true,
'@PHP56Migration' => $phpVersion >= 5.6, '@Symfony:risky' => $risky,
'@PHP70Migration' => $phpVersion >= 7.0, '@PHP56Migration' => $phpVersion >= 5.6,
'@PHP71Migration' => $phpVersion >= 7.1, '@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 ...@@ -208,7 +205,7 @@ final class Config extends PhpCsFixerConfig
if (file_exists('composer.json')) { if (file_exists('composer.json')) {
$data = json_decode(file_get_contents('composer.json'), true); $data = json_decode(file_get_contents('composer.json'), true);
if (is_array($data)) { if (\is_array($data)) {
$this->composerConfig = $data; $this->composerConfig = $data;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment