Skip to content

Commit

Permalink
Make all options snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Nov 9, 2019
1 parent f2928db commit 369a7b1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
18 changes: 10 additions & 8 deletions README.rst
Expand Up @@ -667,15 +667,16 @@ Choose from the list of available rules:

Configuration options:

- ``annotation-black-list`` (``array``): class level annotations tags that must be
- ``annotation_black_list`` (``array``): class level annotations tags that must be
omitted to fix the class, even if all of the white list ones are used
as well. (case insensitive); defaults to ``['@final', '@Entity',
'@ORM\\Entity']``
- ``annotation-white-list`` (``array``): class level annotations tags that must be
'@ORM\\Entity']``; DEPRECATED alias: ``annotation-black-list``
- ``annotation_white_list`` (``array``): class level annotations tags that must be
set in order to fix the class. (case insensitive); defaults to
``['@internal']``
- ``consider-absent-docblock-as-internal-class`` (``bool``): should classes
without any DocBlock be fixed to final?; defaults to ``false``
``['@internal']``; DEPRECATED alias: ``annotation-white-list``
- ``consider_absent_docblock_as_internal_class`` (``bool``): should classes
without any DocBlock be fixed to final?; defaults to ``false``; DEPRECATED
alias: ``consider-absent-docblock-as-internal-class``

* **final_public_method_for_abstract_class**

Expand Down Expand Up @@ -1300,8 +1301,9 @@ Choose from the list of available rules:
'property_public', 'property_protected', 'property_private',
'construct', 'destruct', 'magic', 'phpunit', 'method_public',
'method_protected', 'method_private']``
- ``sortAlgorithm`` (``'alpha'``, ``'none'``): how multiple occurrences of same type
statements should be sorted; defaults to ``'none'``
- ``sort_algorithm`` (``'alpha'``, ``'none'``): how multiple occurrences of same type
statements should be sorted; defaults to ``'none'``; DEPRECATED alias:
``sortAlgorithm``

* **ordered_imports** [@Symfony, @PhpCsFixer]

Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/ClassNotation/FinalClassFixer.php
Expand Up @@ -51,8 +51,8 @@ protected function createProxyFixers()
{
$fixer = new FinalInternalClassFixer();
$fixer->configure([
'annotation-white-list' => [],
'consider-absent-docblock-as-internal-class' => true,
'annotation_white_list' => [],
'consider_absent_docblock_as_internal_class' => true,
]);

return [$fixer];
Expand Down
28 changes: 19 additions & 9 deletions src/Fixer/ClassNotation/FinalInternalClassFixer.php
Expand Up @@ -16,6 +16,7 @@
use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
use PhpCsFixer\DocBlock\DocBlock;
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
use PhpCsFixer\FixerConfiguration\AliasedFixerOptionBuilder;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
use PhpCsFixer\FixerDefinition\CodeSample;
Expand All @@ -39,8 +40,8 @@ public function configure(array $configuration = null)
parent::configure($configuration);

$intersect = array_intersect_assoc(
$this->configuration['annotation-white-list'],
$this->configuration['annotation-black-list']
$this->configuration['annotation_white_list'],
$this->configuration['annotation_black_list']
);

if (\count($intersect)) {
Expand All @@ -60,7 +61,7 @@ public function getDefinition()
new CodeSample(
"<?php\n/** @CUSTOM */class A{}\n",
[
'annotation-white-list' => ['@Custom'],
'annotation_white_list' => ['@Custom'],
]
),
],
Expand Down Expand Up @@ -135,19 +136,28 @@ protected function createConfigurationDefinition()
};

return new FixerConfigurationResolver([
(new FixerOptionBuilder('annotation-white-list', 'Class level annotations tags that must be set in order to fix the class. (case insensitive)'))
(new AliasedFixerOptionBuilder(
new FixerOptionBuilder('annotation_white_list', 'Class level annotations tags that must be set in order to fix the class. (case insensitive)'),
'annotation-white-list'
))
->setAllowedTypes(['array'])
->setAllowedValues($annotationsAsserts)
->setDefault(['@internal'])
->setNormalizer($annotationsNormalizer)
->getOption(),
(new FixerOptionBuilder('annotation-black-list', 'Class level annotations tags that must be omitted to fix the class, even if all of the white list ones are used as well. (case insensitive)'))
(new AliasedFixerOptionBuilder(
new FixerOptionBuilder('annotation_black_list', 'Class level annotations tags that must be omitted to fix the class, even if all of the white list ones are used as well. (case insensitive)'),
'annotation-black-list'
))
->setAllowedTypes(['array'])
->setAllowedValues($annotationsAsserts)
->setDefault(['@final', '@Entity', '@ORM\Entity'])
->setNormalizer($annotationsNormalizer)
->getOption(),
(new FixerOptionBuilder('consider-absent-docblock-as-internal-class', 'Should classes without any DocBlock be fixed to final?'))
(new AliasedFixerOptionBuilder(
new FixerOptionBuilder('consider_absent_docblock_as_internal_class', 'Should classes without any DocBlock be fixed to final?'),
'consider-absent-docblock-as-internal-class'
))
->setAllowedTypes(['bool'])
->setDefault(false)
->getOption(),
Expand All @@ -168,7 +178,7 @@ private function isClassCandidate(Tokens $tokens, $index)
$docToken = $tokens[$tokens->getPrevNonWhitespace($index)];

if (!$docToken->isGivenKind(T_DOC_COMMENT)) {
return $this->configuration['consider-absent-docblock-as-internal-class'];
return $this->configuration['consider_absent_docblock_as_internal_class'];
}

$doc = new DocBlock($docToken->getContent());
Expand All @@ -177,7 +187,7 @@ private function isClassCandidate(Tokens $tokens, $index)
foreach ($doc->getAnnotations() as $annotation) {
Preg::match('/@\S+(?=\s|$)/', $annotation->getContent(), $matches);
$tag = strtolower(substr(array_shift($matches), 1));
foreach ($this->configuration['annotation-black-list'] as $tagStart => $true) {
foreach ($this->configuration['annotation_black_list'] as $tagStart => $true) {
if (0 === strpos($tag, $tagStart)) {
return false; // ignore class: class-level PHPDoc contains tag that has been black listed through configuration
}
Expand All @@ -186,7 +196,7 @@ private function isClassCandidate(Tokens $tokens, $index)
$tags[$tag] = true;
}

foreach ($this->configuration['annotation-white-list'] as $tag => $true) {
foreach ($this->configuration['annotation_white_list'] as $tag => $true) {
if (!isset($tags[$tag])) {
return false; // ignore class: class-level PHPDoc does not contain all tags that has been white listed through configuration
}
Expand Down
10 changes: 7 additions & 3 deletions src/Fixer/ClassNotation/OrderedClassElementsFixer.php
Expand Up @@ -14,6 +14,7 @@

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
use PhpCsFixer\FixerConfiguration\AliasedFixerOptionBuilder;
use PhpCsFixer\FixerConfiguration\AllowedValueSubset;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
Expand Down Expand Up @@ -202,7 +203,7 @@ public function A(){}
public function C(){}
}
',
['order' => ['method_public'], 'sortAlgorithm' => 'alpha']
['order' => ['method_public'], 'sort_algorithm' => 'alpha']
),
]
);
Expand Down Expand Up @@ -272,7 +273,10 @@ protected function createConfigurationDefinition()
'method_private',
])
->getOption(),
(new FixerOptionBuilder('sortAlgorithm', 'How multiple occurrences of same type statements should be sorted'))
(new AliasedFixerOptionBuilder(
new FixerOptionBuilder('sort_algorithm', 'How multiple occurrences of same type statements should be sorted'),
'sortAlgorithm'
))
->setAllowedValues($this->supportedSortAlgorithms)
->setDefault(self::SORT_NONE)
->getOption(),
Expand Down Expand Up @@ -469,7 +473,7 @@ private function sortElements(array $elements)

private function sortGroupElements(array $a, array $b)
{
$selectedSortAlgorithm = $this->configuration['sortAlgorithm'];
$selectedSortAlgorithm = $this->configuration['sort_algorithm'];

if (self::SORT_ALPHA === $selectedSortAlgorithm) {
return strcasecmp($a['name'], $b['name']);
Expand Down
8 changes: 0 additions & 8 deletions tests/AutoReview/FixerTest.php
Expand Up @@ -133,14 +133,6 @@ public function testFixerDefinitions(FixerInterface $fixer)
$options = $fixer->getConfigurationDefinition()->getOptions();

foreach ($options as $option) {
// @TODO 2.12 adjust fixers to use new casing and deprecate old one
if (\in_array($fixerName, [
'final_internal_class',
'ordered_class_elements',
], true)) {
static::markTestIncomplete(sprintf('Rule "%s" is not following new option casing yet, please help.', $fixerName));
}

static::assertRegExp('/^[a-z_]*$/', $option->getName(), sprintf('[%s] Option %s is not snake_case.', $fixerName, $option->getName()));
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php
Expand Up @@ -152,7 +152,7 @@ public function provideFixWithConfigCases()
"<?php\n/** @CUSTOM */final class A{}",
"<?php\n/** @CUSTOM */class A{}",
[
'annotation-white-list' => ['@Custom'],
'annotation_white_list' => ['@Custom'],
],
],
[
Expand Down Expand Up @@ -181,7 +181,7 @@ class A{}
class B{}
',
[
'annotation-white-list' => ['@Custom', '@abc'],
'annotation_white_list' => ['@Custom', '@abc'],
],
],
[
Expand Down Expand Up @@ -228,8 +228,8 @@ class B{}
class C{}
',
[
'annotation-white-list' => ['@Custom', '@internal'],
'annotation-black-list' => ['@not-fix'],
'annotation_white_list' => ['@Custom', '@internal'],
'annotation_black_list' => ['@not-fix'],
],
],
[
Expand All @@ -256,7 +256,7 @@ class A{}
class B{}
',
[
'annotation-black-list' => ['abc'],
'annotation_black_list' => ['abc'],
],
],
];
Expand Down Expand Up @@ -293,8 +293,8 @@ public function testConfigureSameAnnotationInBothLists()
);

$this->fixer->configure([
'annotation-white-list' => ['@internal123', 'a'],
'annotation-black-list' => ['@internal123', 'b'],
'annotation_white_list' => ['@internal123', 'a'],
'annotation_black_list' => ['@internal123', 'b'],
]);
}
}
8 changes: 4 additions & 4 deletions tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php
Expand Up @@ -408,7 +408,7 @@ class Foo
EOT
],
[
['sortAlgorithm' => 'alpha'],
['sort_algorithm' => 'alpha'],
<<<'EOT'
<?php
Expand Down Expand Up @@ -682,7 +682,7 @@ public function provideSortingConfigurationCases()
'method_public',
'method_private',
],
'sortAlgorithm' => 'alpha',
'sort_algorithm' => 'alpha',
],
<<<'EOT'
<?php
Expand Down Expand Up @@ -737,7 +737,7 @@ private function E(){}
'method_protected',
'method_private',
],
'sortAlgorithm' => 'alpha',
'sort_algorithm' => 'alpha',
],
<<<'EOT'
<?php
Expand Down Expand Up @@ -874,7 +874,7 @@ class Foo {
public ?int $foo;
}',
[
'sortAlgorithm' => 'alpha',
'sort_algorithm' => 'alpha',
],
];
}
Expand Down

0 comments on commit 369a7b1

Please sign in to comment.