From 849d027d6d8cf5fa1d7ad76ca81f9cca72dfde48 Mon Sep 17 00:00:00 2001 From: Kei Date: Tue, 6 Aug 2024 05:38:35 +0700 Subject: [PATCH] relaxplus: add `phpdoc_to_comment` --- src/RuleSet/Sets/RelaxPlus.php | 1 + .../Fixtures/Ruleset/realodixspec_actual.php | 7 +++++++ .../Ruleset/realodixspec_expected.php | 7 +++++++ tests/Fixtures/Ruleset/relax_actual.php | 15 +++++++++---- tests/Fixtures/Ruleset/relax_expected.php | 15 +++++++++---- tests/Fixtures/Ruleset/relaxplus_actual.php | 20 ++++++++++++++++++ tests/Fixtures/Ruleset/relaxplus_expected.php | 21 +++++++++++++++++++ 7 files changed, 78 insertions(+), 8 deletions(-) diff --git a/src/RuleSet/Sets/RelaxPlus.php b/src/RuleSet/Sets/RelaxPlus.php index a2574c7..78661ff 100644 --- a/src/RuleSet/Sets/RelaxPlus.php +++ b/src/RuleSet/Sets/RelaxPlus.php @@ -44,6 +44,7 @@ public function mainRules(): array // Cleanup 'phpdoc_no_alias_tag' => ['replacements' => ['type' => 'var', 'link' => 'see']], + 'phpdoc_to_comment' => ['ignored_tags' => ['var']], 'general_phpdoc_annotation_remove' => [ 'annotations' => [ // https://github.com/doctrine/coding-standard/blob/3e88327/lib/Doctrine/ruleset.xml#L227 diff --git a/tests/Fixtures/Ruleset/realodixspec_actual.php b/tests/Fixtures/Ruleset/realodixspec_actual.php index d6a641e..d952259 100644 --- a/tests/Fixtures/Ruleset/realodixspec_actual.php +++ b/tests/Fixtures/Ruleset/realodixspec_actual.php @@ -105,6 +105,13 @@ public function exampleMethod(null|string|boll $a = null): null|string|boll ->unique()->sort() ->toArray(); + $u = withCount([ + 'visits as unique_visit_count' => function (Builder $query) { + /** @var Builder<\App\Models\Visit> $query */ + $query->where('is_first_click', true); + }, + ]); + return null; } diff --git a/tests/Fixtures/Ruleset/realodixspec_expected.php b/tests/Fixtures/Ruleset/realodixspec_expected.php index a80412d..95b6c02 100644 --- a/tests/Fixtures/Ruleset/realodixspec_expected.php +++ b/tests/Fixtures/Ruleset/realodixspec_expected.php @@ -104,6 +104,13 @@ public function exampleMethod(string|boll|null $a = null): string|boll|null ->unique()->sort() ->toArray(); + $u = withCount([ + 'visits as unique_visit_count' => function (Builder $query) { + /** @var Builder<\App\Models\Visit> $query */ + $query->where('is_first_click', true); + }, + ]); + return null; } diff --git a/tests/Fixtures/Ruleset/relax_actual.php b/tests/Fixtures/Ruleset/relax_actual.php index 69981cf..1fc58ca 100644 --- a/tests/Fixtures/Ruleset/relax_actual.php +++ b/tests/Fixtures/Ruleset/relax_actual.php @@ -497,14 +497,21 @@ public function phpdoc__phpdoc_summary() {} public function phpdoc__phpdoc_to_comment() { /** This should be a comment */ - $foo = true; + foreach ([] as $key => $sqlite) { + $sqlite->open(''); + } // ignored_tags - // TODO: This should be a PHPDoc as the tag is on "ignored_tags" list - $bar = true; + /** @todo This should be a PHPDoc as the tag is on "ignored_tags" list */ + Url::withCount([ + 'visits as unique_visit_count' => function (Builder $query) { + /** @var Builder<\App\Models\Visit> $query */ + $query->where('is_first_click', true); + }, + ]); // allow_before_return_statement - /** @var class-string */ + /** \stdClass::class */ return \stdClass::class; } diff --git a/tests/Fixtures/Ruleset/relax_expected.php b/tests/Fixtures/Ruleset/relax_expected.php index 8eb1255..08fe7fa 100644 --- a/tests/Fixtures/Ruleset/relax_expected.php +++ b/tests/Fixtures/Ruleset/relax_expected.php @@ -490,14 +490,21 @@ public function phpdoc__phpdoc_summary() {} public function phpdoc__phpdoc_to_comment() { /** This should be a comment */ - $foo = true; + foreach ([] as $key => $sqlite) { + $sqlite->open(''); + } // ignored_tags - // TODO: This should be a PHPDoc as the tag is on "ignored_tags" list - $bar = true; + /** @todo This should be a PHPDoc as the tag is on "ignored_tags" list */ + Url::withCount([ + 'visits as unique_visit_count' => function (Builder $query) { + /** @var Builder<\App\Models\Visit> $query */ + $query->where('is_first_click', true); + }, + ]); // allow_before_return_statement - /** @var class-string */ + /** \stdClass::class */ return \stdClass::class; } diff --git a/tests/Fixtures/Ruleset/relaxplus_actual.php b/tests/Fixtures/Ruleset/relaxplus_actual.php index cf38880..7428852 100644 --- a/tests/Fixtures/Ruleset/relaxplus_actual.php +++ b/tests/Fixtures/Ruleset/relaxplus_actual.php @@ -37,6 +37,26 @@ public function phpdoc__phpdoc_no_alias_tag() /** @type string */ $foo = 'https://github.com/PHP-CS-Fixer/PHP-CS-Fixer'; } + public function phpdoc__phpdoc_to_comment() + { + /** This should be a comment */ + foreach ([] as $key => $sqlite) { + $sqlite->open(''); + } + + // ignored_tags + /** @todo This should be a PHPDoc as the tag is on "ignored_tags" list */ + Url::withCount([ + 'visits as unique_visit_count' => function (Builder $query) { + /** @var Builder<\App\Models\Visit> $query */ + $query->where('is_first_click', true); + }, + ]); + + // allow_before_return_statement + /** \stdClass::class */ + return \stdClass::class; + } public function string_notation__explicit_string_variable() { diff --git a/tests/Fixtures/Ruleset/relaxplus_expected.php b/tests/Fixtures/Ruleset/relaxplus_expected.php index c39f0c7..fc1edd7 100644 --- a/tests/Fixtures/Ruleset/relaxplus_expected.php +++ b/tests/Fixtures/Ruleset/relaxplus_expected.php @@ -39,6 +39,27 @@ public function phpdoc__phpdoc_no_alias_tag() $foo = 'https://github.com/PHP-CS-Fixer/PHP-CS-Fixer'; } + public function phpdoc__phpdoc_to_comment() + { + /* This should be a comment */ + foreach ([] as $key => $sqlite) { + $sqlite->open(''); + } + + // ignored_tags + /* @todo This should be a PHPDoc as the tag is on "ignored_tags" list */ + Url::withCount([ + 'visits as unique_visit_count' => function (Builder $query) { + /** @var Builder<\App\Models\Visit> $query */ + $query->where('is_first_click', true); + }, + ]); + + // allow_before_return_statement + /* \stdClass::class */ + return \stdClass::class; + } + public function string_notation__explicit_string_variable() { $name = 'foo';