diff --git a/Magento2/Helpers/Assert.php b/Magento2/Helpers/Assert.php index 9b3eb0dc..54bb3995 100644 --- a/Magento2/Helpers/Assert.php +++ b/Magento2/Helpers/Assert.php @@ -1,7 +1,7 @@ getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged + $content = file_get_contents($phpcsFile->getFilename()); - if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false - || preg_match(self::COPYRIGHT_ADOBE, $fileText) - || strpos($fileText, self::COPYRIGHT_ADOBE_TEXT) !== false - ) { - return; + if ($this->isCopyrightYearValid($content) === false) { + $phpcsFile->addWarningOnLine( + 'Copyright is missing or Copyright content/year is not valid', + null, + self::WARNING_CODE + ); } - - $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', - null, - self::WARNING_CODE - ); } } diff --git a/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php index 5eae2b5e..22e8615f 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php @@ -1,7 +1,7 @@ getFilename()); - if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false - || preg_match(self::COPYRIGHT_ADOBE, $content) - || strpos($content, self::COPYRIGHT_ADOBE_TEXT) !== false) { - return; + if ($this->isCopyrightYearValid($content) === false) { + $phpcsFile->addWarningOnLine( + 'Copyright is missing or Copyright content/year is not valid', + null, + self::WARNING_CODE + ); } - - $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', - null, - self::WARNING_CODE - ); } } diff --git a/Magento2Framework/Sniffs/Header/CopyrightSniff.php b/Magento2Framework/Sniffs/Header/CopyrightSniff.php index e23aaba4..eef4d578 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightSniff.php @@ -1,7 +1,7 @@ getTokens()[$positionComment]['content']; - $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content); + // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged + $content = file_get_contents($phpcsFile->getFilename()); - if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || - $adobeCopyrightFound || - strpos($content, self::COPYRIGHT_ADOBE_TEXT) !== false) { - return; + if ($this->isCopyrightYearValid($content) === false) { + $phpcsFile->addWarningOnLine( + 'Copyright is missing or Copyright content/year is not valid', + null, + self::WARNING_CODE + ); } - - $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', - $phpcsFile->getTokens()[$positionComment]['line'], - self::WARNING_CODE - ); } } diff --git a/Magento2Framework/Sniffs/Header/CopyrightValidation.php b/Magento2Framework/Sniffs/Header/CopyrightValidation.php new file mode 100644 index 00000000..589e26aa --- /dev/null +++ b/Magento2Framework/Sniffs/Header/CopyrightValidation.php @@ -0,0 +1,33 @@ += 2010 && $year <= date("Y")) { + return true; + } else { + return false; + } + } else { + return false; + } + } +} diff --git a/Magento2Framework/Sniffs/Header/LicenseSniff.php b/Magento2Framework/Sniffs/Header/LicenseSniff.php index cf7a5479..f5562421 100644 --- a/Magento2Framework/Sniffs/Header/LicenseSniff.php +++ b/Magento2Framework/Sniffs/Header/LicenseSniff.php @@ -1,7 +1,7 @@ 1 + null => 1 ]; } diff --git a/Magento2Framework/Tests/Header/CopyrightUnitTest.4.inc b/Magento2Framework/Tests/Header/CopyrightUnitTest.4.inc index 1cadcad0..e785253e 100644 --- a/Magento2Framework/Tests/Header/CopyrightUnitTest.4.inc +++ b/Magento2Framework/Tests/Header/CopyrightUnitTest.4.inc @@ -1,7 +1,7 @@ 1, ]; } + if ($testFile === 'CopyrightUnitTest.2.inc' || $testFile === 'CopyrightUnitTest.3.inc') { return [ - 3 => 1, + null => 1, ]; } diff --git a/composer.json b/composer.json index b37ca83b..06a8014e 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "34", + "version": "35", "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2 || ^1.0", diff --git a/composer.lock b/composer.lock index d1497e33..4402a5f8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "75815481661a1c5a6ede736bc0f2a855", + "content-hash": "0f6477265976a1f84675a73a2cd24f99", "packages": [ { "name": "dealerdirect/phpcodesniffer-composer-installer",