Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d1711ba

Browse filesBrowse files
authored
Merge pull request #250 from magento-commerce/imported-fredden-magento-coding-standard-433
[Imported] Automatically remove useless comments
2 parents a9d34af + 252371e commit d1711ba
Copy full SHA for d1711ba
Expand file treeCollapse file tree

6 files changed

+396
-3
lines changed

‎Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php
+40-2Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,29 @@ public function process(File $phpcsFile, $stackPtr)
6363
return;
6464
}
6565

66+
$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
67+
6668
if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) {
67-
$phpcsFile->addWarning(
69+
$fix = $phpcsFile->addFixableWarning(
6870
sprintf(
6971
'%s description must contain meaningful information beyond what its name provides or be removed.',
7072
ucfirst($tokens[$stackPtr]['content'])
7173
),
7274
$stackPtr,
7375
'InvalidDescription'
7476
);
77+
78+
if ($fix) {
79+
for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) {
80+
$phpcsFile->fixer->replaceToken($i, '');
81+
}
82+
83+
if ($tokens[$commentStartPtr - 1]['code'] === T_WHITESPACE
84+
&& $tokens[$commentCloserPtr + 1]['code'] === T_WHITESPACE
85+
) {
86+
$phpcsFile->fixer->replaceToken($commentCloserPtr + 1, '');
87+
}
88+
}
7589
}
7690

7791
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
@@ -105,11 +119,35 @@ private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)
105119
}
106120

107121
if (in_array($tokens[$i]['content'], $this->forbiddenTags) === true) {
108-
$phpcsFile->addWarning(
122+
$fix = $phpcsFile->addFixableWarning(
109123
sprintf('Tag %s MUST NOT be used.', $tokens[$i]['content']),
110124
$i,
111125
'ForbiddenTags'
112126
);
127+
128+
if ($fix) {
129+
for ($j = $i - 1; $j > $commentStartPtr; $j--) {
130+
if (!in_array($tokens[$j]['code'], [T_DOC_COMMENT_STAR, T_DOC_COMMENT_WHITESPACE], true)) {
131+
break;
132+
}
133+
134+
if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
135+
break;
136+
}
137+
138+
$phpcsFile->fixer->replaceToken($j, '');
139+
}
140+
141+
$phpcsFile->fixer->replaceToken($i, '');
142+
143+
for ($j = $i + 1; $j < $commentCloserPtr; $j++) {
144+
$phpcsFile->fixer->replaceToken($j, '');
145+
146+
if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
147+
break;
148+
}
149+
}
150+
}
113151
}
114152
}
115153

‎Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc

Copy file name to clipboardExpand all lines: Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,10 @@ class AlsoDeprecatedButHandler
179179

180180
}
181181

182+
/**
183+
* @package this tag should not be used
184+
*/
185+
class OnlyUselessCommentContent
186+
{
187+
188+
}
+165Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
/**
4+
* Handler for PHP errors/warnings/notices that converts them to exceptions.
5+
*/
6+
class ErrorHandler
7+
{
8+
9+
}
10+
11+
class NotAnErrorHandler
12+
{
13+
14+
}
15+
16+
class FaultyHandler
17+
{
18+
19+
}
20+
21+
class SomeHandler
22+
{
23+
24+
}
25+
26+
class YetAnotherHandler
27+
{
28+
29+
}
30+
31+
class GreenHandler
32+
{
33+
34+
}
35+
36+
class EmptyHandler
37+
{
38+
39+
}
40+
41+
/**
42+
* Handler for PHP errors/warnings/notices that converts them to exceptions.
43+
*
44+
* @api is ok here
45+
* @deprecated can be used in this context
46+
* @see is ok here
47+
*/
48+
class ExampleHandler
49+
{
50+
51+
}
52+
53+
/**
54+
* @api
55+
* @since 100.0.2
56+
*/
57+
class ApiHandler
58+
{
59+
60+
}
61+
62+
/**
63+
* @api
64+
*/
65+
class AsyncApiHandler
66+
{
67+
68+
}
69+
70+
/**
71+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
72+
*/
73+
class GroupRepositoryHandler
74+
{
75+
76+
}
77+
78+
/**
79+
* @deprecated
80+
*/
81+
class DeprecatedHandler
82+
{
83+
84+
}
85+
86+
/**
87+
* @deprecated Should not be used
88+
*/
89+
class AncientHandler
90+
{
91+
92+
}
93+
94+
/**
95+
* @deprecated
96+
* @see
97+
*/
98+
class AgedHandler
99+
{
100+
101+
}
102+
103+
/**
104+
* @deprecated Should not be used
105+
* @see
106+
*/
107+
class ArhaicHandler
108+
{
109+
110+
}
111+
112+
/**
113+
* @deprecated Should not be used
114+
* @see Magento\Framework\NewHandler
115+
*/
116+
class OldHandler
117+
{
118+
119+
}
120+
121+
/**
122+
* @see Magento\Framework\NewHandler
123+
*/
124+
class SomethingHandler
125+
{
126+
127+
}
128+
129+
/**
130+
* @see
131+
*/
132+
class DoNotCareHandler
133+
{
134+
135+
}
136+
137+
/**
138+
* @deprecated
139+
* @see Magento\Framework\NewHandler
140+
*/
141+
class OldHandler
142+
{
143+
144+
}
145+
146+
/**
147+
* @deprecated This class will be removed in version 1.0.0 without replacement
148+
*/
149+
class DeprecatedButHandler
150+
{
151+
152+
}
153+
154+
/**
155+
* @deprecated It's also deprecated - This class will be removed in version 1.0.0 without replacement
156+
*/
157+
class AlsoDeprecatedButHandler
158+
{
159+
160+
}
161+
162+
class OnlyUselessCommentContent
163+
{
164+
165+
}

‎Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc

Copy file name to clipboardExpand all lines: Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ interface DoNotCareHandler
154154

155155
}
156156

157+
/**
158+
* @deprecated
159+
* @see Magento\Framework\NewHandler
160+
*/
161+
interface OldHandler
162+
{
163+
164+
}
165+
157166
/**
158167
* @deprecated This interface will be removed in version 1.0.0 without replacement
159168
*/
@@ -169,3 +178,11 @@ interface AlsoDeprecatedButHandler
169178
{
170179

171180
}
181+
182+
/**
183+
* @package this tag should not be used
184+
*/
185+
interface OnlyUselessCommentContent
186+
{
187+
188+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.