From 6a3f52f57df5c6227944e17d8342fd43b5153398 Mon Sep 17 00:00:00 2001 From: Sinisa Nedeljkovic Date: Sat, 4 Apr 2020 22:27:13 +0200 Subject: [PATCH 1/3] #162 Modified @deprecated validator to consider it valid if comment is absent but @see tag is set --- .../Helpers/Commenting/PHPDocFormattingValidator.php | 9 +++++++-- .../ClassAndInterfacePHPDocFormattingUnitTest.1.inc | 9 +++++++++ .../Commenting/ConstantsPHPDocFormattingUnitTest.1.inc | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index 9b462e36..74ff72ab 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -122,13 +122,18 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) return true; } + $seeTagRequired = false; if ($tokens[$deprecatedPtr + 2]['code'] !== T_DOC_COMMENT_STRING) { - return false; + $seeTagRequired = true; } $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { - return true; + if ($seeTagRequired) { + return false; + } else { + return true; + } } if ($tokens[$seePtr + 2]['code'] !== T_DOC_COMMENT_STRING) { return false; diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc index 14ba369a..e5895e32 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc @@ -153,3 +153,12 @@ class DoNotCareHandler { } + +/** + * @deprecated + * @see Magento\Framework\NewHandler + */ +class OldHandler +{ + +} diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc index 05dfdb52..6e0b16f0 100644 --- a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc @@ -38,6 +38,12 @@ class Profiler */ const COMPUTER = 'Deep Thought'; + /** + * @deprecated + * @see \ComputationalMatrix\Mars + */ + const KEYBOARD = 'Ergonomic'; + /** * @see */ From c6bc189ebf7dbc063e52df3408678c363afd94d4 Mon Sep 17 00:00:00 2001 From: Sinisa Nedeljkovic Date: Tue, 28 Apr 2020 21:56:19 +0200 Subject: [PATCH 2/3] #162 Reduced code around IF condition on seeTagRequired variable --- Magento2/Helpers/Commenting/PHPDocFormattingValidator.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index 74ff72ab..a656051c 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -129,11 +129,7 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { - if ($seeTagRequired) { - return false; - } else { - return true; - } + return !$seeTagRequired; } if ($tokens[$seePtr + 2]['code'] !== T_DOC_COMMENT_STRING) { return false; From 4bd41131fbb5771c9abf2a28199ff253b56d1622 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 2 Sep 2020 15:46:15 -0500 Subject: [PATCH 3/3] magento/magento-coding-standard#162: @deprecated without @see tag false positive - simplified logic --- Magento2/Helpers/Commenting/PHPDocFormattingValidator.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index a656051c..fb98db7c 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -126,16 +126,11 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) if ($tokens[$deprecatedPtr + 2]['code'] !== T_DOC_COMMENT_STRING) { $seeTagRequired = true; } - $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { return !$seeTagRequired; } - if ($tokens[$seePtr + 2]['code'] !== T_DOC_COMMENT_STRING) { - return false; - } - - return true; + return $tokens[$seePtr + 2]['code'] === T_DOC_COMMENT_STRING; } /**