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
$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);
......
......@@ -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
......
......@@ -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;
}
}
......
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