Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority test #6273

Merged
merged 1 commit into from Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Console/Output/ProcessOutput.php
Expand Up @@ -72,7 +72,7 @@ public function __construct(OutputInterface $output, EventDispatcherInterface $d
$this->eventDispatcher->addListener(FixerFileProcessedEvent::NAME, [$this, 'onFixerFileProcessed']);
$this->files = $nbFiles;

// max number of characters per line
// max number of characters per line
// - total length x 2 (e.g. " 1 / 123" => 6 digits and padding spaces)
// - 11 (extra spaces, parentheses and percentage characters, e.g. " x / x (100%)")
$this->symbolsPerLine = max(1, $width - \strlen((string) $this->files) * 2 - 11);
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/CastNotation/ModernizeTypesCastingFixer.php
Expand Up @@ -101,7 +101,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$countParamTokens = 0;

for ($paramContentIndex = $openParenthesis + 1; $paramContentIndex < $paramContentEnd; ++$paramContentIndex) {
//not a space, means some sensible token
// not a space, means some sensible token
if (!$tokens[$paramContentIndex]->isGivenKind(T_WHITESPACE)) {
++$countParamTokens;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Comment/SingleLineCommentStyleFixer.php
Expand Up @@ -105,7 +105,7 @@ public function getDefinition(): FixerDefinitionInterface
/**
* {@inheritdoc}
*
* Must run after HeaderCommentFixer, NoUselessReturnFixer.
* Must run after HeaderCommentFixer, NoUselessReturnFixer, PhpdocToCommentFixer.
*/
public function getPriority(): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocAlignFixer.php
Expand Up @@ -154,7 +154,7 @@ public function getDefinition(): FixerDefinitionInterface
/**
* {@inheritdoc}
*
* Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, CommentToPhpdocFixer, GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocIndentFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocScalarFixer, PhpdocScalarFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToCommentFixer, PhpdocToCommentFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesFixer, PhpdocTypesFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer.
* Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocScalarFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToCommentFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer.
*/
public function getPriority(): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocToCommentFixer.php
Expand Up @@ -49,7 +49,7 @@ public function isCandidate(Tokens $tokens): bool
/**
* {@inheritdoc}
*
* Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer.
* Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer, SingleLineCommentStyleFixer.
* Must run after CommentToPhpdocFixer.
*/
public function getPriority(): int
Expand Down
Expand Up @@ -39,7 +39,7 @@ public function getDefinition(): FixerDefinitionInterface
/**
* {@inheritdoc}
*
* Must run after CombineConsecutiveIssetsFixer, FunctionToConstantFixer, NoEmptyStatementFixer, SimplifiedIfReturnFixer, SingleImportPerStatementFixer.
* Must run after CombineConsecutiveIssetsFixer, FunctionToConstantFixer, NoEmptyStatementFixer, NoUnneededImportAliasFixer, SimplifiedIfReturnFixer, SingleImportPerStatementFixer.
*/
public function getPriority(): int
{
Expand Down
6 changes: 1 addition & 5 deletions src/RuleSet/Sets/SymfonyRiskySet.php
Expand Up @@ -23,7 +23,7 @@ final class SymfonyRiskySet extends AbstractRuleSetDescription
{
public function getRules(): array
{
$rules = [
return [
'@PHP56Migration:risky' => true,
'@PSR12:risky' => true,
'array_push' => true,
Expand Down Expand Up @@ -67,10 +67,6 @@ public function getRules(): array
'string_line_ending' => true,
'ternary_to_elvis_operator' => true,
];

ksort($rules);

return $rules;
}

public function getDescription(): string
Expand Down
32 changes: 25 additions & 7 deletions tests/AutoReview/FixerFactoryTest.php
Expand Up @@ -184,27 +184,44 @@ public function testFixersPriorityComment(): void
$fixers[$name] = ['reflection' => $reflection, 'short_classname' => $reflection->getShortName()];
}

$graph = array_merge_recursive(
$mergedGraph = array_merge_recursive(
self::getFixersPriorityGraph(),
self::getPhpDocFixersPriorityGraph()
);

foreach ($graph as $fixerName => $edges) {
$after = [];
// expend $graph

$graph = [];

foreach ($mergedGraph as $fixerName => $edges) {
if (!isset($graph[$fixerName]['before'])) {
$graph[$fixerName] = ['before' => []];
}

foreach ($graph as $candidateFixer => $candidateEdges) {
foreach ($mergedGraph as $candidateFixer => $candidateEdges) {
if (\in_array($fixerName, $candidateEdges, true)) {
$after[] = $candidateFixer;
$graph[$fixerName]['after'][$candidateFixer] = true;
}
}

foreach ($edges as $edge) {
if (!isset($graph[$edge]['after'])) {
$graph[$edge] = ['after' => []];
}

$graph[$edge]['after'][$fixerName] = true;
$graph[$fixerName]['before'][$edge] = true;
}
}

foreach ($graph as $fixerName => $edges) {
$expectedMessage = "/**\n * {@inheritdoc}\n *";

foreach (['before' => $edges, 'after' => $after] as $label => $others) {
foreach ($edges as $label => $others) {
if (\count($others) > 0) {
$shortClassNames = [];

foreach ($others as $other) {
foreach ($others as $other => $foo) {
$shortClassNames[$other] = $fixers[$other]['short_classname'];
}

Expand Down Expand Up @@ -675,6 +692,7 @@ private static function getFixersPriorityGraph(): array
'phpdoc_to_comment' => [
'no_empty_comment',
'phpdoc_no_useless_inheritdoc',
'single_line_comment_style',
],
'phpdoc_to_param_type' => [
'no_superfluous_phpdoc_tags',
Expand Down
Expand Up @@ -36,17 +36,17 @@ public function testFix(string $expected, ?string $input = null): void
public function provideFixCases(): array
{
return [
//old style array
// old style array
[
'<?php $x = array(1, "2",3);',
'<?php $x = array(1 , "2",3);',
],
//old style array with comments
// old style array with comments
[
'<?php $x = array /* comment */ (1, "2", 3);',
'<?php $x = array /* comment */ (1 , "2", 3);',
],
//old style array with comments
// old style array with comments
[
'<?php $x = array(1#
,#
Expand All @@ -56,7 +56,7 @@ public function provideFixCases(): array
"2" , 3);',
],

//short array
// short array
[
'<?php $x = [1, "2", 3,$y];',
'<?php $x = [1 , "2", 3 ,$y];',
Expand Down
Expand Up @@ -36,18 +36,18 @@ public function testFix(string $expected, ?string $input = null): void
public function provideFixCases(): array
{
return [
//old style array
// old style array
[
'<?php $x = array( 1 , "2", 3);',
'<?php $x = array( 1 ,"2",3);',
],
//old style array with comments
// old style array with comments
[
'<?php $x = array /* comment */ ( 1 , "2", 3);',
'<?php $x = array /* comment */ ( 1 , "2",3);',
],

//short array
// short array
[
'<?php $x = [ 1 , "2", 3 , $y];',
'<?php $x = [ 1 , "2",3 ,$y];',
Expand Down
@@ -0,0 +1,19 @@
--TEST--
Integration of fixers: phpdoc_to_comment,single_line_comment_style.
--RULESET--
{"phpdoc_to_comment": true, "single_line_comment_style": true}
--EXPECT--
<?php

$first = true;// needed because by default first docblock is never fixed.

// Test
echo 1;

--INPUT--
<?php

$first = true;// needed because by default first docblock is never fixed.

/** Test */
echo 1;