diff --git a/Magento2/Sniffs/Legacy/LicenseSniff.php b/Magento2/Sniffs/Legacy/LicenseSniff.php new file mode 100644 index 00000000..c6f8ba8a --- /dev/null +++ b/Magento2/Sniffs/Legacy/LicenseSniff.php @@ -0,0 +1,80 @@ +getTokens(); + $content = null; + + if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_STRING) { + $content = $tokens[$stackPtr]['content']; + } + if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) { + $content = $phpcsFile->getTokensAsString($stackPtr, 1); + } + if ($content != null) { + $this->checkLicense($content, $stackPtr, $phpcsFile); + } + } + + /** + * Check that the copyright license does not contain legacy text + * + * @param string $content + * @param int $stackPtr + * @param File $phpcsFile + */ + private function checkLicense(string $content, int $stackPtr, File $phpcsFile): void + { + $commentContent = $content; + if (stripos($commentContent, 'copyright') === false) { + return; + } + foreach (self::LEGACY_TEXTS as $legacyText) { + if (stripos($commentContent, $legacyText) !== false) { + $phpcsFile->addWarning( + sprintf("The copyright license contains legacy text: %s.", $legacyText), + $stackPtr, + self::WARNING_CODE + ); + } + } + } +} diff --git a/Magento2/Tests/Legacy/LicenseUnitTest.1.inc b/Magento2/Tests/Legacy/LicenseUnitTest.1.inc new file mode 100644 index 00000000..75f04eae --- /dev/null +++ b/Magento2/Tests/Legacy/LicenseUnitTest.1.inc @@ -0,0 +1,5 @@ + + + + + diff --git a/Magento2/Tests/Legacy/LicenseUnitTest.4.xml b/Magento2/Tests/Legacy/LicenseUnitTest.4.xml new file mode 100644 index 00000000..c8e81d11 --- /dev/null +++ b/Magento2/Tests/Legacy/LicenseUnitTest.4.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/Magento2/Tests/Legacy/LicenseUnitTest.5.less b/Magento2/Tests/Legacy/LicenseUnitTest.5.less new file mode 100644 index 00000000..1b21386f --- /dev/null +++ b/Magento2/Tests/Legacy/LicenseUnitTest.5.less @@ -0,0 +1,4 @@ +/** + * @copyright Copyright Irubin Consulting Inc + * See COPYING.txt for license details. + */ diff --git a/Magento2/Tests/Legacy/LicenseUnitTest.php b/Magento2/Tests/Legacy/LicenseUnitTest.php new file mode 100644 index 00000000..edcca88e --- /dev/null +++ b/Magento2/Tests/Legacy/LicenseUnitTest.php @@ -0,0 +1,49 @@ + 1, + ]; + } + + if ($testFile === 'LicenseUnitTest.4.xml') { + return [ + 4 => 1, + ]; + } + + if ($testFile === 'LicenseUnitTest.5.less') { + return [ + 2 => 1, + ]; + } + + return []; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 269efa3e..ffe71710 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -334,6 +334,10 @@ 8 warning + + 8 + warning +