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

Tiens compte de la version de PHP pour certaines règles.

Showing with 51 additions and 32 deletions
+51 -32
...@@ -69,9 +69,46 @@ final class Config extends PhpCsFixerConfig ...@@ -69,9 +69,46 @@ final class Config extends PhpCsFixerConfig
*/ */
public function getRules() public function getRules()
{ {
$phpVersion = $this->findRequiredPHPVersion();
$risky = $this->getRiskyAllowed();
return array_replace( return array_replace(
$this->ruleSets(), $this->ruleSets($phpVersion, $risky),
[ $this->baseRules($phpVersion, $risky),
$this->ruleOverrides
);
}
/**
* @param float $phpVersion
* @param bool $risky
*
* @return array
*/
private function ruleSets($phpVersion, $risky)
{
return [
'@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,
];
}
/**
* @param float $phpVersion
* @param bool $risky
*
* @return array
*/
public function baseRules($phpVersion, $risky)
{
$rules = [
// Configuration && overrides // Configuration && overrides
'binary_operator_spaces' => ['align_double_arrow' => true], 'binary_operator_spaces' => ['align_double_arrow' => true],
'blank_line_after_opening_tag' => false, 'blank_line_after_opening_tag' => false,
...@@ -98,21 +135,24 @@ final class Config extends PhpCsFixerConfig ...@@ -98,21 +135,24 @@ final class Config extends PhpCsFixerConfig
'separate' => 'bottom', 'separate' => 'bottom',
'header' => $this->headerComment(), 'header' => $this->headerComment(),
], ],
], ];
$this->getRiskyAllowed() ? [
// Risky if ($risky) {
'is_null' => ['use_yoda_style' => false], $rules['is_null'] = ['use_yoda_style' => false];
'non_printable_character' => ['use_escape_sequences_in_strings' => true],
] : [], if ($phpVersion >= 7.0) {
$this->ruleOverrides $rules['non_printable_character'] = ['use_escape_sequences_in_strings' => true];
); }
}
return $rules;
} }
/** /**
* @param string $rule * @param string $rule
* @param mixed $setting * @param mixed $setting
*/ */
public function setRule(string $rule, $setting) public function setRule($rule, $setting)
{ {
$this->ruleOverrides[$rule] = $setting; $this->ruleOverrides[$rule] = $setting;
} }
...@@ -173,27 +213,6 @@ final class Config extends PhpCsFixerConfig ...@@ -173,27 +213,6 @@ final class Config extends PhpCsFixerConfig
); );
} }
/**
* @return bool[]
*/
private function ruleSets()
{
$phpVersion = $this->findRequiredPHPVersion();
$risky = $this->getRiskyAllowed();
return [
'@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,
];
}
/** /**
* @return float * @return float
*/ */
......
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