From 388a93852ec575f396f22a89c8e36b2667965f09 Mon Sep 17 00:00:00 2001 From: jayrangnani-gl <142883278+jayrangnani-gl@users.noreply.github.com> Date: Fri, 16 Aug 2024 19:05:35 +0530 Subject: [PATCH 1/5] AC-9098:Ability to use Adobe copyright for Adobe Commerce source code for Magento Open Source (CE)-Validation --- .../CopyrightAnotherExtensionsFilesSniff.php | 25 +++++--------- .../Sniffs/Header/CopyrightGraphQLSniff.php | 21 ++++-------- .../Sniffs/Header/CopyrightSniff.php | 30 +++++++---------- .../Sniffs/Header/CopyrightValidation.php | 33 +++++++++++++++++++ ...pyrightAnotherExtensionsFilesUnitTest.4.js | 4 +-- .../CopyrightGraphQLUnitTest.1.graphqls | 4 +-- .../CopyrightGraphQLUnitTest.2.graphqls | 2 +- .../Tests/Header/CopyrightGraphQLUnitTest.php | 18 +++++----- .../Tests/Header/CopyrightUnitTest.4.inc | 4 +-- .../Tests/Header/CopyrightUnitTest.php | 3 +- 10 files changed, 79 insertions(+), 65 deletions(-) create mode 100644 Magento2Framework/Sniffs/Header/CopyrightValidation.php diff --git a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php index 3310e667..bd4a1133 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php @@ -12,12 +12,9 @@ class CopyrightAnotherExtensionsFilesSniff implements Sniff { + use CopyrightValidation; private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat'; - private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.'; - private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/'; - private const COPYRIGHT_ADOBE_TEXT = 'ADOBE CONFIDENTIAL'; - /** * Defines the tokenizers that this sniff is using. * @@ -45,19 +42,15 @@ public function process(File $phpcsFile, $stackPtr) return; } - $fileText = $phpcsFile->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 has wrong format', + 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..e093d892 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php @@ -12,12 +12,9 @@ class CopyrightGraphQLSniff implements Sniff { + use CopyrightValidation; private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat'; - private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.'; - private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/'; - private const COPYRIGHT_ADOBE_TEXT = 'ADOBE CONFIDENTIAL'; - private const FILE_EXTENSION = 'graphqls'; /** @@ -45,16 +42,12 @@ public function process(File $phpcsFile, $stackPtr) // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged $content = file_get_contents($phpcsFile->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 has wrong format', + 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..151c01de 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 has wrong format', + 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..78ed5a26 --- /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/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js b/Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js index b47bf9d5..1027c04d 100644 --- a/Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js +++ b/Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js @@ -1,6 +1,6 @@ /** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. + * Copyright 2021 Adobe + * All Rights Reserved. */ define([ diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls index 6d212f25..29462f8c 100644 --- a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls @@ -1,5 +1,5 @@ -# Copyright © Magento, Inc. All rights reserved. -# See COPYING.txt for license details. +# Copyright 2021 Adobe +# All Rights Reserved. enum PriceAdjustmentCodesEnum { WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label") diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls index 786f22ca..42e7b595 100644 --- a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls @@ -1,5 +1,5 @@ # Copyright 2020 Adobe -# See COPYING.txt for license details. +# All Rights Reserved. enum PriceAdjustmentCodesEnum { WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label") diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php index 7323bd96..58fc7346 100644 --- a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php @@ -9,28 +9,28 @@ class CopyrightGraphQLUnitTest extends AbstractGraphQLSniffUnitTestCase { - /** - * @inheritdoc - */ + /** + * @inheritdoc + */ public function getErrorList(): array { return []; } - /** - * @inheritdoc - */ + /** + * @inheritdoc + */ public function getWarningList($testFile = ''): array { if ($testFile === 'CopyrightGraphQLUnitTest.1.graphqls' || - $testFile === 'CopyrightGraphQLUnitTest.2.graphqls') { + $testFile === 'CopyrightGraphQLUnitTest.2.graphqls') { return []; } if ($testFile === 'CopyrightGraphQLUnitTest.3.graphqls' || - $testFile === 'CopyrightGraphQLUnitTest.4.graphqls') { + $testFile === 'CopyrightGraphQLUnitTest.4.graphqls') { return [ - null => 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, ]; } From 98d3f1950ccab582611ddae7ea892349af082648 Mon Sep 17 00:00:00 2001 From: jayrangnani-gl <142883278+jayrangnani-gl@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:00:18 +0530 Subject: [PATCH 2/5] AC-9098:Ability to use Adobe copyright for Adobe Commerce source code for Magento Open Source (CE)-Validatio --- Magento2/Helpers/Assert.php | 4 ++-- Magento2/Helpers/Commenting/PHPDocFormattingValidator.php | 4 ++-- Magento2/Helpers/Tokenizer/AbstractTokenizer.php | 4 ++-- Magento2/Helpers/Tokenizer/Parameter.php | 4 ++-- Magento2/Helpers/Tokenizer/Variable.php | 5 ++--- Magento2/Sniffs/Annotation/AnnotationFormatValidator.php | 4 ++-- .../Sniffs/Annotation/MethodAnnotationStructureSniff.php | 4 ++-- Magento2/Sniffs/Annotation/MethodArgumentsSniff.php | 4 ++-- Magento2/Sniffs/Classes/AbstractApiSniff.php | 4 ++-- Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php | 4 ++-- Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php | 4 ++-- .../Commenting/ClassAndInterfacePHPDocFormattingSniff.php | 4 ++-- .../Commenting/ClassPropertyPHPDocFormattingSniff.php | 4 ++-- .../Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php | 4 ++-- Magento2/Sniffs/Exceptions/DirectThrowSniff.php | 4 ++-- Magento2/Sniffs/Exceptions/ThrowCatchSniff.php | 5 ++--- .../Sniffs/Exceptions/TryProcessSystemResourcesSniff.php | 4 ++-- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php | 4 ++-- .../Functions/FunctionsDeprecatedWithoutArgumentSniff.php | 4 ++-- Magento2/Sniffs/Functions/StaticFunctionSniff.php | 4 ++-- Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php | 4 ++-- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 5 ++--- Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php | 5 ++--- Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php | 4 ++-- Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php | 4 ++-- Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php | 4 ++-- Magento2/Sniffs/Html/HtmlBindingSniff.php | 5 ++--- Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php | 4 ++-- Magento2/Sniffs/Html/HtmlCollapsibleAttributeSniff.php | 5 ++--- Magento2/Sniffs/Html/HtmlDirectiveSniff.php | 5 ++--- Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php | 5 ++--- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 4 ++-- .../Legacy/ClassReferencesInConfigurationFilesSniff.php | 4 ++-- Magento2/Sniffs/Legacy/DiConfigSniff.php | 5 ++--- Magento2/Sniffs/Legacy/EmailTemplateSniff.php | 5 ++--- Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php | 5 ++--- Magento2/Sniffs/Legacy/InstallUpgradeSniff.php | 4 ++-- Magento2/Sniffs/Legacy/LayoutSniff.php | 4 ++-- Magento2/Sniffs/Legacy/MageEntitySniff.php | 4 ++-- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 5 ++--- Magento2/Sniffs/Legacy/ObsoleteAclSniff.php | 4 ++-- Magento2/Sniffs/Legacy/ObsoleteConfigNodesSniff.php | 5 ++--- Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php | 4 ++-- Magento2/Sniffs/Legacy/ObsoleteMenuSniff.php | 4 ++-- Magento2/Sniffs/Legacy/ObsoleteSystemConfigurationSniff.php | 5 ++--- Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php | 4 ++-- Magento2/Sniffs/Legacy/RestrictedCodeSniff.php | 4 ++-- Magento2/Sniffs/Legacy/TableNameSniff.php | 4 ++-- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 5 ++--- Magento2/Sniffs/Legacy/_files/restricted_classes.php | 4 ++-- Magento2/Sniffs/Less/AvoidIdSniff.php | 4 ++-- Magento2/Sniffs/Less/BracesFormattingSniff.php | 4 ++-- Magento2/Sniffs/Less/ClassNamingSniff.php | 4 ++-- Magento2/Sniffs/Less/ColonSpacingSniff.php | 4 ++-- Magento2/Sniffs/Less/ColourDefinitionSniff.php | 4 ++-- Magento2/Sniffs/Less/CombinatorIndentationSniff.php | 4 ++-- Magento2/Sniffs/Less/CommentLevelsSniff.php | 4 ++-- Magento2/Sniffs/Less/ImportantPropertySniff.php | 4 ++-- Magento2/Sniffs/Less/IndentationSniff.php | 4 ++-- Magento2/Sniffs/Less/PropertiesLineBreakSniff.php | 4 ++-- Magento2/Sniffs/Less/PropertiesSortingSniff.php | 4 ++-- Magento2/Sniffs/Less/QuotesSniff.php | 4 ++-- Magento2/Sniffs/Less/SelectorDelimiterSniff.php | 4 ++-- Magento2/Sniffs/Less/SemicolonSpacingSniff.php | 4 ++-- Magento2/Sniffs/Less/TokenizerSymbolsInterface.php | 4 ++-- Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php | 4 ++-- Magento2/Sniffs/Less/TypeSelectorsSniff.php | 4 ++-- Magento2/Sniffs/Less/VariablesSniff.php | 4 ++-- Magento2/Sniffs/Less/ZeroUnitsSniff.php | 4 ++-- Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php | 4 ++-- .../Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php | 4 ++-- Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php | 4 ++-- Magento2/Sniffs/NamingConvention/ReservedWordsSniff.php | 4 ++-- Magento2/Sniffs/PHP/ArrayAutovivificationSniff.php | 4 ++-- .../Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php | 4 ++-- Magento2/Sniffs/PHP/FinalImplementationSniff.php | 4 ++-- Magento2/Sniffs/PHP/GotoSniff.php | 4 ++-- Magento2/Sniffs/PHP/LiteralNamespacesSniff.php | 4 ++-- Magento2/Sniffs/PHP/ReturnValueCheckSniff.php | 4 ++-- Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php | 4 ++-- Magento2/Sniffs/PHP/VarSniff.php | 4 ++-- Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php | 4 ++-- Magento2/Sniffs/SQL/RawQuerySniff.php | 4 ++-- Magento2/Sniffs/Security/IncludeFileSniff.php | 4 ++-- Magento2/Sniffs/Security/InsecureFunctionSniff.php | 4 ++-- Magento2/Sniffs/Security/LanguageConstructSniff.php | 4 ++-- Magento2/Sniffs/Security/SuperglobalSniff.php | 4 ++-- Magento2/Sniffs/Security/XssTemplateSniff.php | 4 ++-- Magento2/Sniffs/Strings/ExecutableRegExSniff.php | 4 ++-- Magento2/Sniffs/Strings/StringConcatSniff.php | 4 ++-- Magento2/Sniffs/Templates/ThisInTemplateSniff.php | 4 ++-- Magento2/Sniffs/Translation/ConstantUsageSniff.php | 4 ++-- Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php | 4 ++-- .../Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php | 6 +++--- Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php | 6 +++--- Magento2Framework/Sniffs/Header/CopyrightSniff.php | 2 +- Magento2Framework/Sniffs/Header/LicenseSniff.php | 4 ++-- 97 files changed, 195 insertions(+), 210 deletions(-) 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 @@ isCopyrightYearValid($content) === false) { $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', + 'Copyright is missing or Copyright content/year is not valid', null, self::WARNING_CODE ); diff --git a/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php index e093d892..22e8615f 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php @@ -1,7 +1,7 @@ isCopyrightYearValid($content) === false) { $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', + 'Copyright is missing or Copyright content/year is not valid', null, self::WARNING_CODE ); diff --git a/Magento2Framework/Sniffs/Header/CopyrightSniff.php b/Magento2Framework/Sniffs/Header/CopyrightSniff.php index 151c01de..eef4d578 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightSniff.php @@ -49,7 +49,7 @@ public function process(File $phpcsFile, $stackPtr) if ($this->isCopyrightYearValid($content) === false) { $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', + 'Copyright is missing or Copyright content/year is not valid', null, self::WARNING_CODE ); 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 @@ Date: Wed, 21 Aug 2024 16:45:43 +0530 Subject: [PATCH 3/5] AC-9098:Ability to use Adobe copyright for Adobe Commerce source code for Magento Open Source (CE)-Validation --- Magento2Framework/Sniffs/Header/CopyrightValidation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2Framework/Sniffs/Header/CopyrightValidation.php b/Magento2Framework/Sniffs/Header/CopyrightValidation.php index 78ed5a26..589e26aa 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightValidation.php +++ b/Magento2Framework/Sniffs/Header/CopyrightValidation.php @@ -11,7 +11,7 @@ trait CopyrightValidation { /** - * Check is copyright year valid or not + * Check if copyright content/year valid or not * * @param string $content * @return bool From 345382c88a7d621c016dc59dd928d1526ee94a9e Mon Sep 17 00:00:00 2001 From: jayrangnani-gl <142883278+jayrangnani-gl@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:42:28 +0530 Subject: [PATCH 4/5] AC-9098:Ability to use Adobe copyright for Adobe Commerce source code Magento Open Source (CE)-version Changed --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 00938f811fbb3a1878b73173243f28ec01a192d8 Mon Sep 17 00:00:00 2001 From: jayrangnani-gl <142883278+jayrangnani-gl@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:47:05 +0530 Subject: [PATCH 5/5] AC-9098:Ability to use Adobe copyright for Adobe Commerce source code Magento Open Source (CE)-version Changed --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",