Skip to content

Commit 6f94d87

Browse files
committed
AC-1314: Added copyright verification for graphqls files
1 parent 2c9a24a commit 6f94d87

9 files changed

+245
-7
lines changed

Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento2Framework\Sniffs\Header;
99

10-
use Magento2\Sniffs\Less\TokenizerSymbolsInterface;
1110
use PHP_CodeSniffer\Files\File;
1211
use PHP_CodeSniffer\Sniffs\Sniff;
1312

@@ -23,7 +22,7 @@ class CopyrightAnotherExtensionsFilesSniff implements Sniff
2322
*
2423
* @var array
2524
*/
26-
public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP'];
25+
public $supportedTokenizers = ['CSS', 'PHP', 'JS'];
2726

2827
/**
2928
* @inheritDoc
@@ -46,9 +45,10 @@ public function process(File $phpcsFile, $stackPtr)
4645
}
4746

4847
$fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
49-
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText);
5048

51-
if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
49+
if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false
50+
|| preg_match(self::COPYRIGHT_ADOBE, $fileText)
51+
) {
5252
return;
5353
}
5454

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
namespace Magento2Framework\Sniffs\Header;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
class CopyrightGraphQLSniff implements Sniff
14+
{
15+
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
16+
17+
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
18+
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
19+
20+
private const FILE_EXTENSION = 'graphqls';
21+
22+
/**
23+
* @var string[]
24+
*/
25+
public $supportedTokenizers = ['GRAPHQL'];
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
public function register()
31+
{
32+
return [T_OPEN_TAG];
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
public function process(File $phpcsFile, $stackPtr)
39+
{
40+
if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) {
41+
return;
42+
}
43+
44+
// @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
45+
$content = file_get_contents($phpcsFile->getFilename());
46+
47+
if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || preg_match(self::COPYRIGHT_ADOBE, $content)) {
48+
return;
49+
}
50+
51+
$phpcsFile->addWarningOnLine(
52+
'Copyright is missing or has wrong format',
53+
null,
54+
self::WARNING_CODE
55+
);
56+
}
57+
}

Magento2Framework/Sniffs/Header/LicenseSniff.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento2Framework\Sniffs\Header;
99

10-
use Magento2\Sniffs\Less\TokenizerSymbolsInterface;
1110
use PHP_CodeSniffer\Files\File;
1211
use PHP_CodeSniffer\Sniffs\Sniff;
1312

@@ -18,7 +17,7 @@ class LicenseSniff implements Sniff
1817
*
1918
* @var array
2019
*/
21-
public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP'];
20+
public $supportedTokenizers = ['CSS', 'PHP'];
2221

2322
private const WARNING_CODE = 'FoundLegacyTextInCopyright';
2423

@@ -49,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr)
4948
if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) {
5049
$content = $phpcsFile->getTokensAsString($stackPtr, 1);
5150
}
52-
if ($content != null) {
51+
if ($content !== null) {
5352
$this->checkLicense($content, $stackPtr, $phpcsFile);
5453
}
5554
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
enum PriceAdjustmentCodesEnum {
5+
WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label")
6+
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")
7+
}
8+
9+
type ProductPrice {
10+
fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax")
11+
}
12+
13+
type CartItemPrices {
14+
fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax")
15+
}
16+
17+
type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") {
18+
amount: Money @doc(description: "Amount of the FPT as a money object.")
19+
label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.")
20+
}
21+
22+
type StoreConfig {
23+
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")
24+
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")
25+
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")
26+
}
27+
28+
enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") {
29+
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'")
30+
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'")
31+
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'")
32+
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'")
33+
FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query")
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2020 Adobe
2+
# See COPYING.txt for license details.
3+
4+
enum PriceAdjustmentCodesEnum {
5+
WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label")
6+
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")
7+
}
8+
9+
type ProductPrice {
10+
fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax")
11+
}
12+
13+
type CartItemPrices {
14+
fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax")
15+
}
16+
17+
type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") {
18+
amount: Money @doc(description: "Amount of the FPT as a money object.")
19+
label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.")
20+
}
21+
22+
type StoreConfig {
23+
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")
24+
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")
25+
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")
26+
}
27+
28+
enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") {
29+
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'")
30+
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'")
31+
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'")
32+
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'")
33+
FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query")
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2020 Magento
2+
# See COPYING.txt for license details.
3+
4+
enum PriceAdjustmentCodesEnum {
5+
WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label")
6+
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")
7+
}
8+
9+
type ProductPrice {
10+
fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax")
11+
}
12+
13+
type CartItemPrices {
14+
fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax")
15+
}
16+
17+
type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") {
18+
amount: Money @doc(description: "Amount of the FPT as a money object.")
19+
label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.")
20+
}
21+
22+
type StoreConfig {
23+
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")
24+
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")
25+
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")
26+
}
27+
28+
enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") {
29+
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'")
30+
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'")
31+
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'")
32+
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'")
33+
FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query")
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
enum PriceAdjustmentCodesEnum {
2+
WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label")
3+
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")
4+
}
5+
6+
type ProductPrice {
7+
fixed_product_taxes: [FixedProductTax] @doc(description: "The multiple FPTs that can be applied to a product price.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\FixedProductTax")
8+
}
9+
10+
type CartItemPrices {
11+
fixed_product_taxes: [FixedProductTax] @doc(description: "Applied FPT to the cart item.") @resolver(class: "Magento\\WeeeGraphQl\\Model\\Resolver\\Quote\\FixedProductTax")
12+
}
13+
14+
type FixedProductTax @doc(description: "A single FPT that can be applied to a product price.") {
15+
amount: Money @doc(description: "Amount of the FPT as a money object.")
16+
label: String @doc(description: "The label assigned to the FPT to be displayed on the frontend.")
17+
}
18+
19+
type StoreConfig {
20+
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")
21+
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")
22+
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")
23+
}
24+
25+
enum FixedProductTaxDisplaySettings @doc(description: "This enumeration display settings for the fixed product tax") {
26+
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'")
27+
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'")
28+
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'")
29+
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'")
30+
FPT_DISABLED @doc(description: "The FPT feature is not enabled. You can omit ProductPrice.fixed_product_taxes from your query")
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2Framework\Tests\Header;
7+
8+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
9+
10+
class CopyrightGraphQLUnitTest extends AbstractSniffUnitTest
11+
{
12+
/**
13+
* @inheritdoc
14+
*/
15+
public function getErrorList(): array
16+
{
17+
return [];
18+
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function getWarningList($testFile = ''): array
24+
{
25+
if ($testFile === 'CopyrightGraphQLUnitTest.1.inc' || $testFile === 'CopyrightGraphQLUnitTest.2.inc') {
26+
return [];
27+
}
28+
29+
if ($testFile === 'CopyrightGraphQLUnitTest.3.inc' || $testFile === 'CopyrightGraphQLUnitTest.4.inc') {
30+
return [
31+
1 => 1
32+
];
33+
}
34+
35+
return [];
36+
}
37+
}

Magento2Framework/ruleset.xml

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0"?>
22
<ruleset name="Magento2Framework">
33
<description>Magento Coding Standard sniffs applicable for the framework testing only</description>
4+
5+
<arg name="extensions" value="php,phtml,graphqls/GRAPHQL,less/CSS,html/CSS,css/CSS,xml,js/JS"/>
6+
47
<rule ref="Magento2Framework.Header.License">
58
<severity>5</severity>
69
<type>warning</type>
@@ -17,4 +20,13 @@
1720
<include-pattern>*\.php$</include-pattern>
1821
<include-pattern>*\.phtml$</include-pattern>
1922
</rule>
23+
<rule ref="Magento2Framework.Header.CopyrightGraphQL">
24+
<severity>5</severity>
25+
<type>warning</type>
26+
<include-pattern>*\.graphqls$</include-pattern>
27+
</rule>
28+
29+
<rule ref="Internal.NoCodeFound">
30+
<severity>0</severity>
31+
</rule>
2032
</ruleset>

0 commit comments

Comments
 (0)