Skip to content

Commit

Permalink
Fix related to feedback from PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 10, 2019
1 parent f38014b commit fcdce90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.rst
Expand Up @@ -423,7 +423,8 @@ Choose from the list of available rules:

* **constant_case** [@PSR2, @Symfony, @PhpCsFixer]

The PHP constants ``true``, ``false``, and ``null`` MUST be in lower case.
The PHP constants ``true``, ``false``, and ``null`` MUST be written using the
correct casing.

Configuration options:

Expand Down
14 changes: 9 additions & 5 deletions src/Fixer/Casing/ConstantCaseFixer.php
Expand Up @@ -23,9 +23,9 @@
use PhpCsFixer\Tokenizer\Tokens;

/**
* Fixer for rules defined in PSR2 ¶2.5.
* Fixer for constants case.
*
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
* @author Pol Dellaiera <pol.dellaiera@protonmail.com>
*/
final class ConstantCaseFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
{
Expand All @@ -44,11 +44,15 @@ public function configure(array $configuration = null)
parent::configure($configuration);

if ('lower' === $this->configuration['case']) {
$this->fixFunction = 'strtolower';
$this->fixFunction = static function ($token) {
return strtolower($token);
};
}

if ('upper' === $this->configuration['case']) {
$this->fixFunction = 'strtoupper';
$this->fixFunction = static function ($token) {
return strtoupper($token);
};
}
}

Expand All @@ -58,7 +62,7 @@ public function configure(array $configuration = null)
public function getDefinition()
{
return new FixerDefinition(
'The PHP constants `true`, `false`, and `null` MUST be in lower case.',
'The PHP constants `true`, `false`, and `null` MUST be written using the correct casing.',
[new CodeSample("<?php\n\$a = FALSE;\n\$b = True;\n\$c = nuLL;\n")]
);
}
Expand Down

0 comments on commit fcdce90

Please sign in to comment.