diff --git a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php index bfc36afe..3bafbb1f 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php @@ -7,7 +7,6 @@ namespace Magento2Framework\Sniffs\Header; -use Magento2\Sniffs\Less\TokenizerSymbolsInterface; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; @@ -23,7 +22,7 @@ class CopyrightAnotherExtensionsFilesSniff implements Sniff * * @var array */ - public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP']; + public $supportedTokenizers = ['CSS', 'PHP', 'JS']; /** * @inheritDoc @@ -46,9 +45,10 @@ public function process(File $phpcsFile, $stackPtr) } $fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); - $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText); - if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { + if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false + || preg_match(self::COPYRIGHT_ADOBE, $fileText) + ) { return; } diff --git a/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php new file mode 100644 index 00000000..1e488e69 --- /dev/null +++ b/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php @@ -0,0 +1,57 @@ +findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) { + return; + } + + // @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)) { + return; + } + + $phpcsFile->addWarningOnLine( + 'Copyright is missing or has wrong format', + null, + self::WARNING_CODE + ); + } +} diff --git a/Magento2Framework/Sniffs/Header/LicenseSniff.php b/Magento2Framework/Sniffs/Header/LicenseSniff.php index 667b3b2b..cf7a5479 100644 --- a/Magento2Framework/Sniffs/Header/LicenseSniff.php +++ b/Magento2Framework/Sniffs/Header/LicenseSniff.php @@ -7,7 +7,6 @@ namespace Magento2Framework\Sniffs\Header; -use Magento2\Sniffs\Less\TokenizerSymbolsInterface; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; @@ -18,7 +17,7 @@ class LicenseSniff implements Sniff * * @var array */ - public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP']; + public $supportedTokenizers = ['CSS', 'PHP']; private const WARNING_CODE = 'FoundLegacyTextInCopyright'; @@ -49,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) { $content = $phpcsFile->getTokensAsString($stackPtr, 1); } - if ($content != null) { + if ($content !== null) { $this->checkLicense($content, $stackPtr, $phpcsFile); } } diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls new file mode 100644 index 00000000..6d212f25 --- /dev/null +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls @@ -0,0 +1,34 @@ +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +enum PriceAdjustmentCodesEnum { + WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label") + WEEE_TAX @deprecated(reason: "Use fixed_product_taxes. PriceAdjustmentCodesEnum is deprecated. Tax is included or excluded in price. Tax is not shown separtely in Catalog") +} + +type ProductPrice { + fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax") +} + +type CartItemPrices { + fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax") +} + +type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") { + amount: Money @doc(description: "Amount of the FPT as a money object.") + label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.") +} + +type StoreConfig { + product_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices On Product View Page' field. It indicates how FPT information is displayed on product pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + category_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Product Lists' field. It indicates how FPT information is displayed on category pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + sales_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Sales Modules' field. It indicates how FPT information is displayed on cart, checkout, and order pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") +} + +enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") { + INCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price includes the FPT amount without displaying the ProductPrice.fixed_product_taxes values. This value corresponds to 'Including FPT only'") + INCLUDE_FPT_WITH_DETAILS @doc(description: "The displayed price includes the FPT amount while displaying the values of ProductPrice.fixed_product_taxes separately. This value corresponds to 'Including FPT and FPT description'") + EXCLUDE_FPT_AND_INCLUDE_WITH_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values of ProductPrice.fixed_product_taxes and the price including the FPT are displayed separately. This value corresponds to 'Excluding FPT, Including FPT description and final price'") + EXCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values from ProductPrice.fixed_product_taxes are not displayed. This value corresponds to 'Excluding FPT'") + FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query") +} diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls new file mode 100644 index 00000000..786f22ca --- /dev/null +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls @@ -0,0 +1,34 @@ +# Copyright 2020 Adobe +# See COPYING.txt for license details. + +enum PriceAdjustmentCodesEnum { + WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label") + WEEE_TAX @deprecated(reason: "Use fixed_product_taxes. PriceAdjustmentCodesEnum is deprecated. Tax is included or excluded in price. Tax is not shown separtely in Catalog") +} + +type ProductPrice { + fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax") +} + +type CartItemPrices { + fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax") +} + +type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") { + amount: Money @doc(description: "Amount of the FPT as a money object.") + label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.") +} + +type StoreConfig { + product_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices On Product View Page' field. It indicates how FPT information is displayed on product pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + category_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Product Lists' field. It indicates how FPT information is displayed on category pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + sales_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Sales Modules' field. It indicates how FPT information is displayed on cart, checkout, and order pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") +} + +enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") { + INCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price includes the FPT amount without displaying the ProductPrice.fixed_product_taxes values. This value corresponds to 'Including FPT only'") + INCLUDE_FPT_WITH_DETAILS @doc(description: "The displayed price includes the FPT amount while displaying the values of ProductPrice.fixed_product_taxes separately. This value corresponds to 'Including FPT and FPT description'") + EXCLUDE_FPT_AND_INCLUDE_WITH_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values of ProductPrice.fixed_product_taxes and the price including the FPT are displayed separately. This value corresponds to 'Excluding FPT, Including FPT description and final price'") + EXCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values from ProductPrice.fixed_product_taxes are not displayed. This value corresponds to 'Excluding FPT'") + FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query") +} diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.3.graphqls b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.3.graphqls new file mode 100644 index 00000000..6706a8b2 --- /dev/null +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.3.graphqls @@ -0,0 +1,34 @@ +# Copyright 2020 Magento +# See COPYING.txt for license details. + +enum PriceAdjustmentCodesEnum { + WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label") + WEEE_TAX @deprecated(reason: "Use fixed_product_taxes. PriceAdjustmentCodesEnum is deprecated. Tax is included or excluded in price. Tax is not shown separtely in Catalog") +} + +type ProductPrice { + fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax") +} + +type CartItemPrices { + fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax") +} + +type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") { + amount: Money @doc(description: "Amount of the FPT as a money object.") + label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.") +} + +type StoreConfig { + product_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices On Product View Page' field. It indicates how FPT information is displayed on product pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + category_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Product Lists' field. It indicates how FPT information is displayed on category pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + sales_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Sales Modules' field. It indicates how FPT information is displayed on cart, checkout, and order pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") +} + +enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") { + INCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price includes the FPT amount without displaying the ProductPrice.fixed_product_taxes values. This value corresponds to 'Including FPT only'") + INCLUDE_FPT_WITH_DETAILS @doc(description: "The displayed price includes the FPT amount while displaying the values of ProductPrice.fixed_product_taxes separately. This value corresponds to 'Including FPT and FPT description'") + EXCLUDE_FPT_AND_INCLUDE_WITH_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values of ProductPrice.fixed_product_taxes and the price including the FPT are displayed separately. This value corresponds to 'Excluding FPT, Including FPT description and final price'") + EXCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values from ProductPrice.fixed_product_taxes are not displayed. This value corresponds to 'Excluding FPT'") + FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query") +} diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.4.graphqls b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.4.graphqls new file mode 100644 index 00000000..c685a931 --- /dev/null +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.4.graphqls @@ -0,0 +1,31 @@ +enum PriceAdjustmentCodesEnum { + WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label") + WEEE_TAX @deprecated(reason: "Use fixed_product_taxes. PriceAdjustmentCodesEnum is deprecated. Tax is included or excluded in price. Tax is not shown separtely in Catalog") +} + +type ProductPrice { + fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax") +} + +type CartItemPrices { + fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax") +} + +type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") { + amount: Money @doc(description: "Amount of the FPT as a money object.") + label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.") +} + +type StoreConfig { + product_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices On Product View Page' field. It indicates how FPT information is displayed on product pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + category_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Product Lists' field. It indicates how FPT information is displayed on category pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") + sales_fixed_product_tax_display_setting : FixedProductTaxDisplaySettings @doc(description: "Corresponds to the 'Display Prices In Sales Modules' field. It indicates how FPT information is displayed on cart, checkout, and order pages") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\StoreConfig") +} + +enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") { + INCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price includes the FPT amount without displaying the ProductPrice.fixed_product_taxes values. This value corresponds to 'Including FPT only'") + INCLUDE_FPT_WITH_DETAILS @doc(description: "The displayed price includes the FPT amount while displaying the values of ProductPrice.fixed_product_taxes separately. This value corresponds to 'Including FPT and FPT description'") + EXCLUDE_FPT_AND_INCLUDE_WITH_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values of ProductPrice.fixed_product_taxes and the price including the FPT are displayed separately. This value corresponds to 'Excluding FPT, Including FPT description and final price'") + EXCLUDE_FPT_WITHOUT_DETAILS @doc(description: "The displayed price does not include the FPT amount. The values from ProductPrice.fixed_product_taxes are not displayed. This value corresponds to 'Excluding FPT'") + FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query") +} diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php new file mode 100644 index 00000000..7cd23950 --- /dev/null +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php @@ -0,0 +1,37 @@ + 1 + ]; + } + + return []; + } +} diff --git a/Magento2Framework/ruleset.xml b/Magento2Framework/ruleset.xml index 434d10cc..80369df8 100644 --- a/Magento2Framework/ruleset.xml +++ b/Magento2Framework/ruleset.xml @@ -1,6 +1,9 @@ Magento Coding Standard sniffs applicable for the framework testing only + + + 5 warning @@ -17,4 +20,13 @@ *\.php$ *\.phtml$ + + 5 + warning + *\.graphqls$ + + + + 0 +