diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php
new file mode 100644
index 00000000..e3ed49b8
--- /dev/null
+++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php
@@ -0,0 +1,121 @@
+PHPDocFormattingValidator = new PHPDocFormattingValidator();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function register()
+ {
+ return [
+ T_CLASS,
+ T_INTERFACE
+ ];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function process(File $phpcsFile, $stackPtr)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ $namePtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1, null, false, null, true);
+
+ $commentStartPtr = $phpcsFile->findPrevious(
+ [
+ T_WHITESPACE,
+ T_DOC_COMMENT_STAR,
+ T_DOC_COMMENT_WHITESPACE,
+ T_DOC_COMMENT_TAG,
+ T_DOC_COMMENT_STRING,
+ T_DOC_COMMENT_CLOSE_TAG
+ ],
+ $stackPtr - 1,
+ null,
+ true,
+ null,
+ true
+ );
+
+ if ($tokens[$commentStartPtr]['code'] !== T_DOC_COMMENT_OPEN_TAG) {
+ return;
+ }
+
+ if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) {
+ $phpcsFile->addWarning(
+ sprintf(
+ '%s description should contain additional information beyond the name already supplies.',
+ ucfirst($tokens[$stackPtr]['content'])
+ ),
+ $stackPtr,
+ 'InvalidDescription'
+ );
+ }
+
+ $this->validateTags($phpcsFile, $commentStartPtr, $tokens);
+ }
+
+ /**
+ * Validates that forbidden tags are not used in comment
+ *
+ * @param File $phpcsFile
+ * @param int $commentStartPtr
+ * @param array $tokens
+ * @return bool
+ */
+ private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)
+ {
+ $commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
+
+ for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) {
+ if ($tokens[$i]['code'] !== T_DOC_COMMENT_TAG) {
+ continue;
+ }
+
+ if (in_array($tokens[$i]['content'], $this->forbiddenTags) === true) {
+ $phpcsFile->addWarning(
+ sprintf('Tag %s MUST NOT be used.', $tokens[$i]['content']),
+ $i,
+ 'ForbiddenTags'
+ );
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php
index df59c9ac..205dcdf9 100644
--- a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php
+++ b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php
@@ -13,6 +13,19 @@
*/
class ConstantsPHPDocFormattingSniff implements Sniff
{
+ /**
+ * @var PHPDocFormattingValidator
+ */
+ private $PHPDocFormattingValidator;
+
+ /**
+ * Helper initialisation
+ */
+ public function __construct()
+ {
+ $this->PHPDocFormattingValidator = new PHPDocFormattingValidator();
+ }
+
/**
* @inheritDoc
*/
@@ -45,42 +58,18 @@ public function process(File $phpcsFile, $stackPtr)
null,
true
);
- $constName = strtolower(trim($tokens[$constNamePtr]['content'], " '\""));
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, null, false, null, true);
if ($commentStartPtr === false) {
return;
}
- $commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
- for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) {
- $token = $tokens[$i];
-
- // Not an interesting string
- if ($token['code'] !== T_DOC_COMMENT_STRING) {
- continue;
- }
-
- // Comment is the same as constant name
- $docComment = trim(strtolower($token['content']), ',.');
- if ($docComment === $constName) {
- continue;
- }
-
- // Comment is exactly the same as constant name
- $docComment = str_replace(' ', '_', $docComment);
- if ($docComment === $constName) {
- continue;
- }
-
- // We have found at lease one meaningful line in comment description
- return;
+ if ($this->PHPDocFormattingValidator->providesMeaning($constNamePtr, $commentStartPtr, $tokens) !== true) {
+ $phpcsFile->addWarning(
+ 'Constants must have short description if they add information beyond what the constant name supplies.',
+ $stackPtr,
+ 'MissingConstantPHPDoc'
+ );
}
-
- $phpcsFile->addWarning(
- 'Constants must have short description if they add information beyond what the constant name supplies.',
- $stackPtr,
- 'MissingConstantPHPDoc'
- );
}
}
diff --git a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php b/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php
new file mode 100644
index 00000000..4112f675
--- /dev/null
+++ b/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php
@@ -0,0 +1,74 @@
+ 1,
+ 27 => 1,
+ 35 => 1,
+ 44 => 1,
+ 52 => 1,
+ 63 => 1,
+ 64 => 1,
+ 65 => 1,
+ ];
+ }
+}
diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php
index b3042b18..aa475c3d 100644
--- a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php
+++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ConstantsPHPDocFormattingUnitTest
- */
class ConstantsPHPDocFormattingUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Exceptions/DirectThrowUnitTest.php b/Magento2/Tests/Exceptions/DirectThrowUnitTest.php
index f276ad47..1730b8e0 100644
--- a/Magento2/Tests/Exceptions/DirectThrowUnitTest.php
+++ b/Magento2/Tests/Exceptions/DirectThrowUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class DirectThrowUnitTest
- */
class DirectThrowUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Exceptions/ThrowCatchUnitTest.php b/Magento2/Tests/Exceptions/ThrowCatchUnitTest.php
index f49eef0e..dd351e5e 100644
--- a/Magento2/Tests/Exceptions/ThrowCatchUnitTest.php
+++ b/Magento2/Tests/Exceptions/ThrowCatchUnitTest.php
@@ -8,9 +8,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ThrowCatchUnitTest
- */
class ThrowCatchUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Files/LineLengthUnitTest.php b/Magento2/Tests/Files/LineLengthUnitTest.php
index 486b2021..8bbf3da2 100644
--- a/Magento2/Tests/Files/LineLengthUnitTest.php
+++ b/Magento2/Tests/Files/LineLengthUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class LineLengthUnitTest
- */
class LineLengthUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php b/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php
index 30285182..e6521ae0 100644
--- a/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php
+++ b/Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class DiscouragedFunctionUnitTest
- */
class DiscouragedFunctionUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Legacy/MageEntityUnitTest.php b/Magento2/Tests/Legacy/MageEntityUnitTest.php
index 7d2358f7..7e44b074 100644
--- a/Magento2/Tests/Legacy/MageEntityUnitTest.php
+++ b/Magento2/Tests/Legacy/MageEntityUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class MageEntityUnitTest
- */
class MageEntityUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/NamingConvention/ReservedWordsUnitTest.php b/Magento2/Tests/NamingConvention/ReservedWordsUnitTest.php
index 03c50d17..e180dd58 100644
--- a/Magento2/Tests/NamingConvention/ReservedWordsUnitTest.php
+++ b/Magento2/Tests/NamingConvention/ReservedWordsUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ReservedWordsUnitTest
- */
class ReservedWordsUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/PHP/FinalImplementationUnitTest.php b/Magento2/Tests/PHP/FinalImplementationUnitTest.php
index 048031e6..61af60f8 100644
--- a/Magento2/Tests/PHP/FinalImplementationUnitTest.php
+++ b/Magento2/Tests/PHP/FinalImplementationUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class FinalImplementationUnitTest
- */
class FinalImplementationUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/PHP/GotoUnitTest.php b/Magento2/Tests/PHP/GotoUnitTest.php
index 112c0396..6d7a1c84 100644
--- a/Magento2/Tests/PHP/GotoUnitTest.php
+++ b/Magento2/Tests/PHP/GotoUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class GotoUnitTest
- */
class GotoUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/PHP/LiteralNamespacesUnitTest.php b/Magento2/Tests/PHP/LiteralNamespacesUnitTest.php
index 9a22dace..cd54df28 100644
--- a/Magento2/Tests/PHP/LiteralNamespacesUnitTest.php
+++ b/Magento2/Tests/PHP/LiteralNamespacesUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class LiteralNamespacesUnitTest
- */
class LiteralNamespacesUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php
index 0ab1eda7..b2074f0c 100644
--- a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php
+++ b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ShortEchoSyntaxUnitTest
- */
class ShortEchoSyntaxUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/PHP/VarUnitTest.php b/Magento2/Tests/PHP/VarUnitTest.php
index 7b082a86..359ce0f5 100644
--- a/Magento2/Tests/PHP/VarUnitTest.php
+++ b/Magento2/Tests/PHP/VarUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class VarUnitTest
- */
class VarUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/SQL/RawQueryUnitTest.php b/Magento2/Tests/SQL/RawQueryUnitTest.php
index 7981a178..aa99106d 100644
--- a/Magento2/Tests/SQL/RawQueryUnitTest.php
+++ b/Magento2/Tests/SQL/RawQueryUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class RawQueryUnitTest
- */
class RawQueryUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Security/IncludeFileUnitTest.php b/Magento2/Tests/Security/IncludeFileUnitTest.php
index 04b323d0..cb110475 100644
--- a/Magento2/Tests/Security/IncludeFileUnitTest.php
+++ b/Magento2/Tests/Security/IncludeFileUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class IncludeFileUnitTest
- */
class IncludeFileUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Security/InsecureFunctionUnitTest.php b/Magento2/Tests/Security/InsecureFunctionUnitTest.php
index 772831f0..1bbaf7ad 100644
--- a/Magento2/Tests/Security/InsecureFunctionUnitTest.php
+++ b/Magento2/Tests/Security/InsecureFunctionUnitTest.php
@@ -8,9 +8,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class InsecureFunctionUnitTest
- */
class InsecureFunctionUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Security/LanguageConstructUnitTest.php b/Magento2/Tests/Security/LanguageConstructUnitTest.php
index 155fa90e..0560ed33 100644
--- a/Magento2/Tests/Security/LanguageConstructUnitTest.php
+++ b/Magento2/Tests/Security/LanguageConstructUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class LanguageConstructUnitTest
- */
class LanguageConstructUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Security/SuperglobalUnitTest.php b/Magento2/Tests/Security/SuperglobalUnitTest.php
index 19376859..c8cfbf7e 100644
--- a/Magento2/Tests/Security/SuperglobalUnitTest.php
+++ b/Magento2/Tests/Security/SuperglobalUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class SuperglobalUnitTest
- */
class SuperglobalUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Security/XssTemplateUnitTest.php b/Magento2/Tests/Security/XssTemplateUnitTest.php
index ffe79ff3..0eab2af5 100644
--- a/Magento2/Tests/Security/XssTemplateUnitTest.php
+++ b/Magento2/Tests/Security/XssTemplateUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class XssTemplateUnitTest
- */
class XssTemplateUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Strings/ExecutableRegExUnitTest.php b/Magento2/Tests/Strings/ExecutableRegExUnitTest.php
index 0e8df097..e0deadbf 100644
--- a/Magento2/Tests/Strings/ExecutableRegExUnitTest.php
+++ b/Magento2/Tests/Strings/ExecutableRegExUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ExecutableRegExUnitTest
- */
class ExecutableRegExUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Strings/StringConcatUnitTest.php b/Magento2/Tests/Strings/StringConcatUnitTest.php
index 74aa1fed..50775da9 100644
--- a/Magento2/Tests/Strings/StringConcatUnitTest.php
+++ b/Magento2/Tests/Strings/StringConcatUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class StringConcatUnitTest
- */
class StringConcatUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Templates/ThisInTemplateUnitTest.php b/Magento2/Tests/Templates/ThisInTemplateUnitTest.php
index 1e47590e..590ae194 100644
--- a/Magento2/Tests/Templates/ThisInTemplateUnitTest.php
+++ b/Magento2/Tests/Templates/ThisInTemplateUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ThisInTemplateUnitTest
- */
class ThisInTemplateUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Translation/ConstantUsageUnitTest.php b/Magento2/Tests/Translation/ConstantUsageUnitTest.php
index 4f2062e8..8d6c883c 100644
--- a/Magento2/Tests/Translation/ConstantUsageUnitTest.php
+++ b/Magento2/Tests/Translation/ConstantUsageUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class ConstantUsageUnitTest
- */
class ConstantUsageUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/Tests/Whitespace/MultipleEmptyLinesUnitTest.php b/Magento2/Tests/Whitespace/MultipleEmptyLinesUnitTest.php
index d58f8836..7ee1e0c2 100644
--- a/Magento2/Tests/Whitespace/MultipleEmptyLinesUnitTest.php
+++ b/Magento2/Tests/Whitespace/MultipleEmptyLinesUnitTest.php
@@ -7,9 +7,6 @@
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
-/**
- * Class MultipleEmptyLinesUnitTest
- */
class MultipleEmptyLinesUnitTest extends AbstractSniffUnitTest
{
/**
diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml
index 98100eae..2ee867db 100644
--- a/Magento2/ruleset.xml
+++ b/Magento2/ruleset.xml
@@ -496,6 +496,10 @@
+
+ 5
+ warning
+
5
warning