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 300f8ddc..c80111c5 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", "webonyx/graphql-php": "^15.0", diff --git a/composer.lock b/composer.lock index 96395de9..43e60b65 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": "05d8d7651a86d5880335013ba0dce696", + "content-hash": "e2b70ce9c22c7b443187cd24724bcf7d", "packages": [ { "name": "dealerdirect/phpcodesniffer-composer-installer",