15 | _getTestFunction();
21 | $block->getTestFunction();
22 | $_something = $this->something();
23 | $block->_getTest();
24 | $block = _testing();
25 | ?>
26 | _getTestAnotherFunction();
28 | ?>
29 |
30 | helper();
38 | ?>
39 |
41 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/_files/PhtmlTemplateUnitTest/view/frontend/templates/PhtmlTemplateUnitTest.2.phtml:
--------------------------------------------------------------------------------
1 |
7 |
9 |
11 |
15 | _getTestFunction();
21 | $block->getTestFunction();
22 | $_something = $this->something();
23 | $block->_getTest();
24 | $block = _testing();
25 | ?>
26 | _getTestAnotherFunction();
28 | ?>
29 |
30 | helper();
38 | ?>
39 |
41 |
--------------------------------------------------------------------------------
/Magento2/Tests/Security/IncludeFileUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
19 | 4 => 1,
20 | 6 => 1,
21 | 7 => 1,
22 | 9 => 1,
23 | 10 => 1,
24 | 12 => 1,
25 | 13 => 1,
26 | 15 => 1,
27 | 17 => 1,
28 | 23 => 1,
29 | 24 => 1,
30 | 28 => 1,
31 | 34 => 1,
32 | ];
33 | }
34 |
35 | /**
36 | * @inheritdoc
37 | */
38 | public function getWarningList()
39 | {
40 | return [];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Magento2/Tests/Templates/ObjectManagerUnitTest.1.phtml.inc:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
25 |
26 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/PHP/GotoSniff.php:
--------------------------------------------------------------------------------
1 | addError($this->errorMessage, $stackPtr, $this->errorCode);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/PHP/FinalImplementationSniff.php:
--------------------------------------------------------------------------------
1 | addError(
30 | // phpcs:ignore Generic.Files.LineLength
31 | 'Final keyword is prohibited in Magento. It decreases extensibility and is not compatible with plugins and proxies.',
32 | $stackPtr,
33 | 'FoundFinal'
34 | );
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Magento2/Rector/Tests/ReplaceNewDateTimeNull/ReplaceNewDateTimeNullTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($fileInfo);
22 | }
23 |
24 | /**
25 | * @return Iterator
26 | */
27 | public function provideData(): Iterator
28 | {
29 | return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
30 | }
31 |
32 | public function provideConfigFilePath(): string
33 | {
34 | return __DIR__ . '/config/configured_rule.php';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Magento2/Rector/Tests/ReplacePregSplitNullLimit/ReplacePregSplitNullLimitTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($fileInfo);
22 | }
23 |
24 | /**
25 | * @return Iterator
26 | */
27 | public function provideData(): Iterator
28 | {
29 | return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
30 | }
31 |
32 | public function provideConfigFilePath(): string
33 | {
34 | return __DIR__ . '/config/configured_rule.php';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Magento2/Tests/Security/InsecureFunctionUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
20 | 5 => 1,
21 | 7 => 1,
22 | 9 => 1,
23 | 11 => 1,
24 | 13 => 1,
25 | 15 => 1,
26 | 17 => 1,
27 | 19 => 1,
28 | 21 => 1,
29 | 23 => 1,
30 | 25 => 1,
31 | 27 => 1,
32 | 29 => 1,
33 | 31 => 1,
34 | ];
35 | }
36 |
37 | /**
38 | * @inheritdoc
39 | */
40 | public function getWarningList()
41 | {
42 | return [];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Magento2/Tests/Translation/ConstantUsageUnitTest.inc:
--------------------------------------------------------------------------------
1 | 1,
19 | 15 => 1,
20 | 17 => 1,
21 | 19 => 1,
22 | 30 => 1,
23 | 35 => 1,
24 | 41 => 1,
25 | 47 => 1,
26 | 52 => 1,
27 | 55 => 1,
28 | 64 => 1,
29 | 68 => 1,
30 | 72 => 2,
31 | 74 => 1,
32 | 85 => 1,
33 | 89 => 1
34 | ];
35 | }
36 |
37 | /**
38 | * @inheritdoc
39 | */
40 | public function getWarningList()
41 | {
42 | return [];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/WidgetXMLUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
20 | 12 => 1,
21 | 14 => 1,
22 | ];
23 | }
24 | if ($testFile === 'WidgetXMLUnitTest.2.xml') {
25 | return [
26 | 9 => 1,
27 | 17 => 1,
28 | 24 => 1,
29 | ];
30 | }
31 | return [];
32 | }
33 |
34 | /**
35 | * @inheritdoc
36 | */
37 | public function getWarningList($testFile = '')
38 | {
39 | return [];
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/PHP/VarSniff.php:
--------------------------------------------------------------------------------
1 | addWarning($this->warningMessage, $stackPtr, $this->warningCode);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Rector/Tests/AddArrayAccessInterfaceReturnTypes/AddArrayAccessInterfaceReturnTypesTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($fileInfo);
22 | }
23 |
24 | /**
25 | * @return Iterator
26 | */
27 | public function provideData(): Iterator
28 | {
29 | return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
30 | }
31 |
32 | public function provideConfigFilePath(): string
33 | {
34 | return __DIR__ . '/config/configured_rule.php';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Magento2/Tests/Security/XssTemplateUnitTest.php:
--------------------------------------------------------------------------------
1 | 2,
27 | 4 => 1,
28 | 5 => 1,
29 | 6 => 1,
30 | 7 => 1,
31 | 8 => 1,
32 | 9 => 1,
33 | 10 => 1,
34 | 13 => 1,
35 | 14 => 1,
36 | 16 => 1,
37 | 17 => 1,
38 | 18 => 1,
39 | 19 => 1,
40 | 20 => 1,
41 | 21 => 1,
42 | 25 => 2,
43 | ];
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
28 | 27 => 1,
29 | 35 => 1,
30 | 44 => 1,
31 | 52 => 1,
32 | 63 => 1,
33 | 64 => 1,
34 | 65 => 1,
35 | 66 => 1,
36 | 101 => 1,
37 | 109 => 1,
38 | 118 => 1,
39 | 127 => 1,
40 | 183 => 1,
41 | ];
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.inc:
--------------------------------------------------------------------------------
1 | 1,
20 | 12 => 1,
21 | 13 => 1,
22 | 14 => 1,
23 | 27 => 1,
24 | 28 => 1,
25 | 29 => 1,
26 | 30 => 1,
27 | 51 => 1,
28 | 52 => 1,
29 | 53 => 1,
30 | 54 => 1,
31 | 55 => 1,
32 | 56 => 1,
33 | 57 => 1,
34 | ];
35 | }
36 |
37 | /**
38 | * @inheritDoc
39 | */
40 | protected function getWarningList()
41 | {
42 | return [];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Magento2/Tests/Less/AvoidIdUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
17 | 7 => 1,
18 | 8 => 1,
19 | 9 => 1,
20 | 10 => 1,
21 | 11 => 1,
22 | 12 => 1,
23 | 13 => 1,
24 | 14 => 1,
25 | 15 => 1,
26 | 16 => 1,
27 | 17 => 1,
28 | 18 => 1,
29 | 19 => 1,
30 | 20 => 1,
31 | 21 => 1,
32 | 22 => 1,
33 | 26 => 1,
34 | 27 => 1,
35 | 28 => 1
36 | ];
37 | }
38 |
39 | /**
40 | * @inheritdoc
41 | */
42 | public function getWarningList()
43 | {
44 | return [];
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Magento2/Rector/Tests/ReplaceMbStrposNullLimit/ReplaceMbStrposNullLimitTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($fileInfo);
22 | }
23 |
24 | /**
25 | * @return Iterator
26 | */
27 | public function provideData(): Iterator
28 | {
29 | return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
30 | }
31 |
32 | /**
33 | * @return string
34 | */
35 | public function provideConfigFilePath(): string
36 | {
37 | return __DIR__ . '/config/configured_rule.php';
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.inc.fixed:
--------------------------------------------------------------------------------
1 | 1,
27 | 18 => 1,
28 | 23 => 1,
29 | 30 => 1,
30 | 34 => 1,
31 | 42 => 1,
32 | 49 => 1,
33 | 56 => 1,
34 | 63 => 1,
35 | 68 => 1,
36 | 75 => 1,
37 | 125 => 1,
38 | 150 => 1,
39 | 156 => 1,
40 | 163 => 1,
41 | 170 => 1
42 | ];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php:
--------------------------------------------------------------------------------
1 | 1
34 | ];
35 | }
36 |
37 | return [];
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Magento2/Tests/Eslint/AbstractEslintTestCase.php:
--------------------------------------------------------------------------------
1 | assertStringContainsString($message, implode(' ', $output));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
31 | 9 => 1,
32 | 14 => 1,
33 | 19 => 1,
34 | 25 => 1,
35 | 31 => 1,
36 | 38 => 1,
37 | 43 => 1,
38 | 48 => 1,
39 | 53 => 1,
40 | 59 => 1,
41 | 65 => 1
42 | ];
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php:
--------------------------------------------------------------------------------
1 | extensions = array_merge(
27 | $config->extensions,
28 | [
29 | 'graphqls' => 'GRAPHQL'
30 | ]
31 | );
32 |
33 | //and write back to a global that is used in base class
34 | $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/EscapeMethodsOnBlockClassUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
23 | 21 => 1,
24 | 22 => 1,
25 | 23 => 1,
26 | 25 => 1,
27 | 26 => 1,
28 | 27 => 1,
29 | 31 => 1,
30 | 40 => 1,
31 | 45 => 1,
32 | 47 => 1,
33 | 50 => 1,
34 | 57 => 1,
35 | 58 => 1,
36 | 59 => 1,
37 | 61 => 1,
38 | 64 => 1,
39 | 66 => 1,
40 | 68 => 1,
41 | 70 => 1,
42 | 72 => 1,
43 | ];
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Tests/Eslint/MiscDeprecatedFunctionsTest.php:
--------------------------------------------------------------------------------
1 | assertFileContainsError(
20 | 'MiscDeprecatedFunctionsTest.js',
21 | [
22 | 'jQuery.isFunction() is deprecated. In most cases, it can be replaced by [typeof x === "function"]',
23 | 'jQuery.type() is deprecated. Replace with an appropriate type check like [typeof x === "function"]',
24 | 'jQuery.isArray() is deprecated. Use the native Array.isArray method instead',
25 | 'jQuery.parseJSON() is deprecated. To parse JSON strings, use the native JSON.parse method instead'
26 | ]
27 | );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/TableNameUnitTest.inc:
--------------------------------------------------------------------------------
1 | _resource->getTableName('/catalog_category_product');
4 |
5 | $collection->joinField(
6 | 'inventory_in_stock',
7 | '/cataloginventory_stock_item',
8 | 'is_in_stock',
9 | 'product_id=entity_id',
10 | '(' . join(') OR (', $cond) . ')'
11 | );
12 |
13 | $collection->getFkName(
14 | 'inventory_in_stock',
15 | $collection,
16 | '/is_in_stock'
17 | );
18 |
19 | $select = $connection->select()->from(
20 | ['main_table' => 'magento/sample_table']
21 | );
22 |
23 | $select = $connection->select()->from(
24 | ['main_table_name' => 'magento/sample_table']
25 | );
26 |
27 | $select = $connection->select()->from(
28 | ['main_table' => 'magento_sample_table']
29 | );
30 |
31 | $fooBar=array(0=>array(125,0,875,750),'33' =>array(85,0,194,716), 10 => 100);
32 |
33 | class Collection extends \Magento\Sales\Model\ResourceModel\Report\Order\Collection
34 | {
35 | /**
36 | * Aggregated Data Table
37 | *
38 | * @var string
39 | */
40 | protected $_aggregationTable = 'magento/sales_order_aggregated_updated';
41 | }
42 |
--------------------------------------------------------------------------------
/Magento2/Tests/PHP/ReturnValueCheckUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
22 | 8 => 1,
23 | 12 => 1,
24 | 16 => 1,
25 | 20 => 1,
26 | 24 => 1,
27 | 32 => 1,
28 | 40 => 1,
29 | 44 => 1,
30 | 72 => 1,
31 | 76 => 1,
32 | 80 => 2,
33 | 85 => 1,
34 | 87 => 1,
35 | 98 => 1,
36 | 102 => 1,
37 | 106 => 1,
38 | 110 => 1,
39 | ];
40 | }
41 |
42 | /**
43 | * @inheritdoc
44 | */
45 | public function getWarningList()
46 | {
47 | return [];
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Magento2Framework/Tests/Header/CopyrightUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
32 | ];
33 | }
34 |
35 | if ($testFile === 'CopyrightUnitTest.2.inc' || $testFile === 'CopyrightUnitTest.3.inc') {
36 | return [
37 | null => 1,
38 | ];
39 | }
40 |
41 | return [];
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/ModuleXMLUnitTest.php:
--------------------------------------------------------------------------------
1 | 2,
28 | ];
29 | }
30 | if ($testFile === 'ModuleXMLUnitTest.2.xml') {
31 | return [
32 | 9 => 2,
33 | ];
34 | }
35 | if ($testFile === 'ModuleXMLUnitTest.3.xml') {
36 | return [];
37 | }
38 | if ($testFile === 'ModuleXMLUnitTest.4.xml') {
39 | return [
40 | 9 => 2,
41 | ];
42 | }
43 | return [];
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls:
--------------------------------------------------------------------------------
1 | enum Foo {
2 | # Valid values
3 | VALID_SCREAMING_SNAKE_CASE_VALUE
4 | VALID_SCREAMING_SNAKE_CASE_VALUE_WITH_1_NUMBER
5 | VALID_SCREAMING_SNAKE_CASE_VALUE_WITH_12345_NUMBERS
6 | VALID_SCREAMING_SNAKE_CASE_VALUE_ENDING_WITH_NUMBER_5
7 | VALIDUPPERCASEVALUE
8 | VALID_SCREMING_CASE_VALUE_WITH_DIRECTIVE @doc(description: "This is a valid enum value with a directive")
9 | VALID_SCREMING_CASE_VALUE_WITH_TWO_DIRECTIVES @doc(
10 | description: "This is a valid enum value with a directive"
11 | ) @unparametrizedDirective
12 |
13 | # Invalid values
14 | 1_INVALID_SCREAMING_SNAKE_CASE_VALUE_STARTING_WITH_NUMBER
15 | invalidCamelCaseValue
16 | InvalidCamelCaseCapsValue
17 | invalidlowercasevalue
18 | invalidCamelCaseValueWithDirective @doc(description: "This is an invalid enum value with a directive")
19 | invalidCamelCaseValueWithTwoDirectives @doc(
20 | description: "This is an invalid enum value with a directive"
21 | ) @unparametrizedDirective
22 | }
23 |
24 | # Ignored although it triggers a T_CLASS token
25 | type Bar {
26 | some_field: String
27 | }
--------------------------------------------------------------------------------
/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
22 | 48 => 1
23 | ];
24 | }
25 | if ($filename === 'AutogeneratedClassNotInConstructorUnitTest.2.php.inc') {
26 | return [
27 | 22 => 1,
28 | 28 => 1,
29 | 33 => 1,
30 | 37 => 1
31 | ];
32 | }
33 | return [];
34 | }
35 |
36 | /**
37 | * @inheritdoc
38 | */
39 | public function getWarningList($filename = '')
40 | {
41 | return [];
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Less/QuotesSniff.php:
--------------------------------------------------------------------------------
1 | getTokens();
41 |
42 | if (false !== strpos($tokens[$stackPtr]['content'], '"')) {
43 | $phpcsFile->addError('Use single quotes', $stackPtr, 'DoubleQuotes');
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Magento2/Tests/Classes/DiscouragedDependenciesUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
25 | 37 => 1,
26 | 44 => 1
27 | ];
28 | } elseif ($testFile === 'DiscouragedDependenciesUnitTest.2.inc') {
29 | return [
30 | 17 => 1,
31 | 37 => 1,
32 | 44 => 1
33 | ];
34 | }
35 |
36 | return [];
37 | }
38 |
39 | /**
40 | * @inheritdoc
41 | */
42 | public function getWarningList()
43 | {
44 | return [];
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/LayoutUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
20 | 22 => 1,
21 | 145 => 1,
22 | 148 => 1,
23 | ];
24 | }
25 | if ($testFile === 'LayoutUnitTest.2.xml') {
26 | return [
27 | 11 => 1,
28 | 28 => 1,
29 | ];
30 | }
31 | if ($testFile === 'LayoutUnitTest.3.xml') {
32 | return [
33 | 15 => 1,
34 | 18 => 1,
35 | ];
36 | }
37 | return [];
38 | }
39 |
40 | /**
41 | * @inheritdoc
42 | */
43 | public function getWarningList($testFile = '')
44 | {
45 | return [];
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Magento2/Tests/Less/CommentLevelsUnitTest.less:
--------------------------------------------------------------------------------
1 | // /**
2 | // * Copyright © Magento, Inc. All rights reserved.
3 | // * See COPYING.txt for license details.
4 | // */
5 |
6 | //
7 | // First level comment
8 | // _____________________________________________
9 |
10 | .first-level {
11 | background-color: green;
12 | }
13 |
14 | //
15 | // Incorrect First level comment
16 | // _____________________________________________
17 | .incorrect-first-level {
18 | background-color: red;
19 | }
20 |
21 | //
22 | // Second level comment
23 | // ---------------------------------------------
24 |
25 | .second-level {
26 | background-color: green;
27 | }
28 |
29 | //
30 | // Incorrect Second level comment
31 | // ---------------------------------------------
32 |
33 | .incorrect-second-level {
34 | background-color: red;
35 | }
36 |
37 | // third level comment
38 | .third-level-nav {
39 | // New line comment, considered third level too
40 | background-color: green; // ToDo UI: todo inline comment
41 | color: white; // inline comment
42 | }
43 |
44 | //Incorrect third level comment
45 | .incorrect-third-level {
46 | // Incorrect new line comment
47 | color: red; // incorrect inline comment
48 | }
49 |
--------------------------------------------------------------------------------
/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.graphqls:
--------------------------------------------------------------------------------
1 | type FooType {
2 | # Valid snake case field names
3 | valid_snake_case_field: String
4 | validlowercasefield: String
5 | valid_snake_case_field_ending_with_number_5: String
6 | valid_snake_case_field_with_ending_numbers_12345: String
7 | valid_snake_case_field_5_with_number5_inline: String
8 |
9 | # Incorrect use of snake case
10 | INVALIDUPPERCASEFIELD: String
11 | INVALID_SCREAMING_SNAKE_CASE_FIELD: String
12 | Invalid_Upper_Snake_Case_Field: String
13 | invalid_mixed_case_FIELD: String
14 | InvalidCameCaseFieldName: String
15 | }
16 |
17 | interface FooInterface {
18 | # Valid snake case field names
19 | valid_snake_case_field: String
20 | validlowercasefield: String
21 | valid_snake_case_field_ending_with_number_5: String
22 | valid_snake_case_field_with_ending_numbers_12345: String
23 | valid_snake_case_field_5_with_number5_inline: String
24 |
25 | # Incorrect use of snake case
26 | INVALIDUPPERCASEFIELD: String
27 | INVALID_SCREAMING_SNAKE_CASE_FIELD: String
28 | Invalid_Upper_Snake_Case_Field: String
29 | invalid_mixed_case_FIELD: String
30 | InvalidCameCaseFieldName: String
31 | }
32 |
--------------------------------------------------------------------------------
/Magento2Framework/Tests/Header/LicenseUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
32 | ];
33 | }
34 |
35 | if ($testFile === 'LicenseUnitTest.4.xml') {
36 | return [
37 | 4 => 1,
38 | ];
39 | }
40 |
41 | if ($testFile === 'LicenseUnitTest.5.less') {
42 | return [
43 | 2 => 1,
44 | ];
45 | }
46 |
47 | return [];
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.graphqls:
--------------------------------------------------------------------------------
1 | # Valid names
2 | query validCamelCaseQuery {}
3 | mutation validCamelCaseMutation {}
4 |
5 | # Incorrect use of camel cyse
6 | query InvalidCamelCaseQuery {}
7 | query invalid_Camel_Case_Query_With_Underscores {}
8 | mutation InvalidCamelCaseMutation {}
9 | mutation invalid_Camel_Case_Mutation_With_Underscores {}
10 |
11 | # All lower case
12 | query validlowercasequery {}
13 | mutation validlowercasemutation {}
14 |
15 | # All upper case
16 | query INVALIDUPPERCASEQUERY {}
17 | mutation INVALIDUPPERCASEMUTATION {}
18 |
19 | # Mix camel case with uppercase
20 | query validCamelCaseQueryWithUPPERCASE {}
21 | mutation validCamelCaseMutationWithUPPERCASE {}
22 |
23 | # Usage of numeric characters
24 | query validCamelCaseQueryWith1Number {}
25 | query validCamelCaseQueryWith12345Numbers {}
26 | query validCamelCaseQueryEndingWithNumber4 {}
27 | query 5invalidCamelCaseQueryStartingWithNumber {}
28 | mutation validCamelCaseMutationWith1Number {}
29 | mutation validCamelCaseMutationWith12345Numbers {}
30 | mutation validCamelCaseMutationEndingWithNumber4 {}
31 | mutation 5invalidCamelCaseMutationStartingWithNumber {}
32 |
33 | # Empty names (valid by definition of GraphQL)
34 | query {}
35 | mutation {}
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/_files/RestrictedCodeUnitTest/Magento/Framework/Model/ResourceModel/Iterator.php:
--------------------------------------------------------------------------------
1 | 'value',
4 | 1 => 'value2',
5 | ];
6 |
7 | $options = [];
8 |
9 | foreach ([] as $collection) {
10 | foreach ($configurationSources as $source) {
11 | $options = array_merge($options, $source);
12 | }
13 | }
14 |
15 | $options = [];
16 | $itemCount = count($configurationSources);
17 | for ($i = 0; $i <= $itemCount; $i++) {
18 | $source = $options[$itemCount];
19 | $options = array_merge($options, $source);
20 | }
21 |
22 | class SelectBuilder
23 | {
24 | private $columns = [];
25 |
26 | public function getColumns()
27 | {
28 | return $this->columns;
29 | }
30 |
31 | public function setColumns(array $columns)
32 | {
33 | $this->columns = $columns;
34 | }
35 | }
36 |
37 | $selectBuilder = new SelectBuilder();
38 |
39 | foreach ([] as $collection) {
40 | foreach ($configurationSources as $source) {
41 | $selectBuilder->setColumns(array_merge($selectBuilder->getColumns(), $source));
42 | }
43 | }
44 |
45 | foreach ([] as $item)
46 | // inline foreach
47 | $a = array_merge([], []);
48 |
49 | foreach ([] as $item)
50 | // array_merge after inline foreach
51 | $a = array_merge([], []);
52 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php:
--------------------------------------------------------------------------------
1 | snake_case.
12 | */
13 | class ValidFieldNameSniff extends AbstractGraphQLSniff
14 | {
15 | /**
16 | * @inheritDoc
17 | */
18 | public function register()
19 | {
20 | return [T_VARIABLE];
21 | }
22 |
23 | /**
24 | * @inheritDoc
25 | */
26 | public function process(File $phpcsFile, $stackPtr)
27 | {
28 | $tokens = $phpcsFile->getTokens();
29 | $name = $tokens[$stackPtr]['content'];
30 |
31 | if (!$this->isSnakeCase($name)) {
32 | $type = 'Field';
33 | $error = '%s name "%s" is not in snake_case format';
34 | $data = [
35 | $type,
36 | $name,
37 | ];
38 | $phpcsFile->addError($error, $stackPtr, 'NotSnakeCase', $data);
39 | $phpcsFile->recordMetric($stackPtr, 'SnakeCase field name', 'no');
40 | } else {
41 | $phpcsFile->recordMetric($stackPtr, 'SnakeCase field name', 'yes');
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Magento2/Tests/Classes/DiscouragedDependenciesUnitTest.1.inc:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
27 | Test
28 |
29 | >
32 | = $block->escapeHtml($element->getLegend()) ?>
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc:
--------------------------------------------------------------------------------
1 | model = ObjectManager::getInstance()->get(ModelFactory::class);
23 | }
24 |
25 | protected function setUp(): void
26 | {
27 | ObjectManager::getInstance()
28 | ->get(EavSetupFactory::class);
29 | $objectManager = ObjectManager::getInstance();
30 |
31 | /** @var EavSetup $eavSetup */
32 | $this->eavSetup = $objectManager
33 | ->get(EavSetupFactory::class)
34 | ->create(['setup' => $this->setup]);
35 |
36 | ObjectManager::getInstance()
37 | ->get(\Full\Class\NameFactory::class);
38 | }
39 |
40 | private function foo(): void
41 | {
42 | ObjectManager::getInstance() ;
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/Magento2Framework/ruleset.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Magento Coding Standard sniffs applicable for the framework testing only
4 |
5 |
6 |
7 |
8 |
9 |
10 | 5
11 | warning
12 |
13 |
14 | 5
15 | warning
16 | *\.php$
17 | *\.phtml$
18 |
19 |
20 | 5
21 | warning
22 | *\.php$
23 | *\.phtml$
24 | */PHPCSUtils/*
25 |
26 |
27 | 5
28 | warning
29 | *\.graphqls$
30 |
31 |
32 |
33 | 0
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Less/CombinatorIndentationSniff.php:
--------------------------------------------------------------------------------
1 | getTokens();
41 |
42 | $prevPtr = $stackPtr - 1;
43 | $nextPtr = $stackPtr + 1;
44 |
45 | if (($tokens[$prevPtr]['code'] !== T_WHITESPACE) || ($tokens[$nextPtr]['code'] !== T_WHITESPACE)) {
46 | $phpcsFile->addError('Spaces should be before and after combinators', $stackPtr, 'NoSpaces');
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/ClassReferencesInConfigurationFilesUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
20 | 40 => 1,
21 | ];
22 | }
23 | if ($testFile === 'ClassReferencesInConfigurationFilesUnitTest.2.xml') {
24 | return [
25 | 22 => 1,
26 | 42 => 1,
27 | ];
28 | }
29 | if ($testFile === 'ClassReferencesInConfigurationFilesUnitTest.3.xml') {
30 | return [
31 | 10 => 1,
32 | ];
33 | }
34 | if ($testFile === 'ClassReferencesInConfigurationFilesUnitTest.4.xml') {
35 | return [
36 | 10 => 1,
37 | ];
38 | }
39 | return [];
40 | }
41 |
42 | /**
43 | * @inheritdoc
44 | */
45 | public function getWarningList($testFile = '')
46 | {
47 | return [];
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/eslint/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * ESLint Plugin for jQuery Deprecation Rules
3 | * This module aggregates individual jQuery-related rules into a single .
4 | */
5 | import jqueryNoAndSelf from './rules/jquery-no-andSelf.js';
6 | import jqueryNoBindUnbind from './rules/jquery-no-bind-unbind.js';
7 | import jqueryNoDelegateUndelegate from './rules/jquery-no-delegate-undelegate.js';
8 | import jqueryNoDeprecatedExpr from './rules/jquery-no-deprecated-expr.js';
9 | import jqueryNoEventShorthand from './rules/jquery-no-event-shorthand.js';
10 | import jqueryNoInputEventShorthand from './rules/jquery-no-input-event-shorthand.js';
11 | import jqueryNoMiscDeprecatedFunctions from './rules/jquery-no-misc-deprecated-functions.js';
12 | import jqueryNoSize from './rules/jquery-no-size.js';
13 | import jqueryNoTrim from './rules/jquery-no-trim.js';
14 |
15 | export default {
16 | rules: {
17 | 'jquery-no-andSelf': jqueryNoAndSelf,
18 | 'jquery-no-bind-unbind': jqueryNoBindUnbind,
19 | 'jquery-no-delegate-undelegate': jqueryNoDelegateUndelegate,
20 | 'jquery-no-deprecated-expr': jqueryNoDeprecatedExpr,
21 | 'jquery-no-event-shorthand': jqueryNoEventShorthand,
22 | 'jquery-no-input-event-shorthand': jqueryNoInputEventShorthand,
23 | 'jquery-no-misc-deprecated-functions': jqueryNoMiscDeprecatedFunctions,
24 | 'jquery-no-size': jqueryNoSize,
25 | 'jquery-no-trim': jqueryNoTrim
26 | }
27 | };
28 |
--------------------------------------------------------------------------------
/rector.php:
--------------------------------------------------------------------------------
1 | phpVersion(PhpVersion::PHP_80);
18 | $rectorConfig->phpVersion(PhpVersion::PHP_81);
19 |
20 | // register a single rule
21 | $rectorConfig->singleton(FinalPrivateToPrivateVisibilityRector::class);
22 | $rectorConfig->singleton(OptionalParametersAfterRequiredRector::class);
23 | $rectorConfig->singleton(SetStateToStaticRector::class);
24 | $rectorConfig->singleton(StringableForToStringRector::class);
25 | $rectorConfig->singleton(Php81ResourceReturnToObjectRector::class);
26 | $rectorConfig->singleton(ReplacePregSplitNullLimit::class);
27 | $rectorConfig->singleton(ReplaceMbStrposNullLimit::class);
28 | $rectorConfig->singleton(ReplaceNewDateTimeNull::class);
29 | };
30 |
--------------------------------------------------------------------------------
/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.2.inc:
--------------------------------------------------------------------------------
1 | 0');
7 |
8 | /** */
9 | define('NUMBER_ONE', 1);
10 |
11 | /**
12 | * @deprecated
13 | */
14 | define('A', 65);
15 |
16 | /**
17 | * @deprecated It is a lie
18 | */
19 | define('THERE IS', 'cake');
20 |
21 | /**
22 | * @deprecated
23 | * @see
24 | */
25 | define('C', 67);
26 |
27 | /**
28 | * @deprecated No reference specified
29 | * @see
30 | */
31 | define('D', 68);
32 |
33 | class Profiler
34 | {
35 | /**
36 | * Nesting separator.
37 | */
38 | const NESTING_SEPARATOR = '->';
39 |
40 | /**
41 | *
42 | */
43 | const NUMBER_TWO = 2;
44 |
45 | /**
46 | * @deprecated
47 | */
48 | const a = 97;
49 |
50 | /**
51 | * @deprecated Why not
52 | */
53 | const YES = false;
54 |
55 | /**
56 | * @deprecated
57 | * @see
58 | */
59 | const c = 99;
60 |
61 | /**
62 | * @deprecated No reference specified
63 | * @see
64 | */
65 | const d = 100;
66 |
67 | /**
68 | * @deprecated This constant will be removed in version 1.0.0 without replacement
69 | */
70 | const KEYWORD_PHRASE = false;
71 |
72 | /**
73 | * @deprecated It's awesome - This constant will be removed in version 1.0.0 without replacement
74 | */
75 | const WITH_KEYWORD_PHRASE = false;
76 | }
77 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php:
--------------------------------------------------------------------------------
1 | getTokens();
41 |
42 | $prevPtr = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
43 | if (false === $prevPtr) {
44 | return;
45 | }
46 |
47 | if ($tokens[$prevPtr]['line'] === $tokens[$stackPtr]['line']) {
48 | $error = 'Each property must be on a line by itself';
49 | $phpcsFile->addError($error, $stackPtr, 'SameLine');
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Security/InsecureFunctionSniff.php:
--------------------------------------------------------------------------------
1 | null,
22 | 'create_function' => null,
23 | 'exec' => '\Magento\Framework\Shell::execute',
24 | 'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)',
25 | 'passthru' => null,
26 | 'pcntl_exec' => null,
27 | 'popen' => null,
28 | 'proc_open' => null,
29 | 'serialize' => '\Magento\Framework\Serialize\SerializerInterface::serialize',
30 | 'shell_exec' => null,
31 | 'system' => null,
32 | 'unserialize' => '\Magento\Framework\Serialize\SerializerInterface::unserialize',
33 | 'srand' => null,
34 | 'mt_srand' => null,
35 | 'mt_rand' => 'random_int',
36 | // Custom Rules - MTS-2096
37 | 'eval' => null,
38 | 'proc_nice' => null,
39 | 'proc_open' => null,
40 | 'proc_close' => null,
41 | 'proc_terminate' => null,
42 | 'proc_get_status' => null,
43 | ];
44 | }
45 |
--------------------------------------------------------------------------------
/eslint/rules/jquery-no-size.js:
--------------------------------------------------------------------------------
1 | // Import utils using ES module syntax
2 | import utils from './utils.js';
3 |
4 | export default {
5 | meta: {
6 | type: 'suggestion',
7 | docs: {
8 | description: 'Disallow the use of the deprecated `size` method',
9 | category: 'jQuery deprecated functions',
10 | recommended: true,
11 | url: 'https://api.jquery.com/size/'
12 | },
13 | schema: [],
14 | messages: {
15 | size: 'jQuery.size() removed, use jQuery.length'
16 | }
17 | },
18 |
19 | /**
20 | * Executes the function to check if size method is used.
21 | *
22 | * @param {Object} context
23 | * @returns {Object}
24 | */
25 | create: function (context) {
26 | return {
27 | /**
28 | * Checks if size method is used and reports it.
29 | *
30 | * @param {Object} node - The node to check.
31 | */
32 | CallExpression: function (node) {
33 | if (node.callee.type !== 'MemberExpression') {return;}
34 |
35 | if (node.callee.property.name !== 'size') {return;}
36 |
37 | if (utils.isjQuery(node)) {
38 | context.report({
39 | node: node,
40 | messageId: 'size'
41 | });
42 | }
43 | }
44 | };
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/Magento2/Tests/Templates/ObjectManagerUnitTest.php:
--------------------------------------------------------------------------------
1 | 1
33 | ];
34 | }
35 | return [];
36 | }
37 |
38 | /**
39 | * @inheritdoc
40 | */
41 | public function getErrorList($filename = '')
42 | {
43 | return [];
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Tests/Legacy/LayoutUnitTest.3.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | Magento_Paypal::hss/review/button.phtml
17 |
18 |
19 | Magento_Paypal::hss/review/button.phtml
20 |
21 |
22 | Magento_Paypal::hss/review/button.phtml
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php:
--------------------------------------------------------------------------------
1 | findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) {
39 | return;
40 | }
41 |
42 | // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
43 | $content = file_get_contents($phpcsFile->getFilename());
44 |
45 | if ($this->isCopyrightYearValid($content) === false) {
46 | $phpcsFile->addWarningOnLine(
47 | 'Copyright is missing or Copyright content/year is not valid',
48 | null,
49 | self::WARNING_CODE
50 | );
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Less/ImportantPropertySniff.php:
--------------------------------------------------------------------------------
1 | getTokens();
41 |
42 | // Will be implemented in MAGETWO-49778
43 | //$phpcsFile->addWarning('!important is used', $stackPtr, '!ImportantIsUsed');
44 |
45 | if (($tokens[$stackPtr + 1]['content'] === 'important')
46 | && ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE)
47 | ) {
48 | $phpcsFile->addError('Space before !important is missing', $stackPtr, 'NoSpace');
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/eslint/rules/jquery-no-trim.js:
--------------------------------------------------------------------------------
1 | // Import utils using ES module syntax
2 | import utils from './utils.js';
3 |
4 | export default {
5 | meta: {
6 | type: 'suggestion',
7 | docs: {
8 | description: 'Disallow the use of the deprecated `trim` function',
9 | category: 'jQuery deprecated functions',
10 | recommended: true,
11 | url: 'https://api.jquery.com/jQuery.trim/'
12 | },
13 | schema: [],
14 | messages: {
15 | trim: 'jQuery.trim is deprecated; use String.prototype.trim'
16 | }
17 | },
18 |
19 | /**
20 | * Executes the function to check if trim method is used.
21 | *
22 | * @param {Object} context
23 | * @returns {Object}
24 | */
25 | create: function (context) {
26 | return {
27 | /**
28 | * Checks if trim method is used and reports it.
29 | *
30 | * @param {Object} node - The node to check.
31 | */
32 | CallExpression: function (node) {
33 | if (node.callee.type !== 'MemberExpression') {return;}
34 |
35 | if (node.callee.property.name !== 'trim') {return;}
36 |
37 | if (utils.isjQuery(node)) {
38 | context.report({
39 | node: node,
40 | messageId: 'trim'
41 | });
42 | }
43 | }
44 | };
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/eslint/rules/jquery-no-andSelf.js:
--------------------------------------------------------------------------------
1 | // Import utils using ES module syntax
2 | import utils from './utils.js';
3 |
4 | export default {
5 | meta: {
6 | type: 'suggestion',
7 | docs: {
8 | description: 'Disallow the use of the deprecated `andSelf` method',
9 | category: 'jQuery deprecated functions',
10 | recommended: true,
11 | url: 'https://api.jquery.com/andself/'
12 | },
13 | schema: [],
14 | messages: {
15 | andSelf: 'jQuery.andSelf() removed, use jQuery.addBack()'
16 | }
17 | },
18 |
19 | /**
20 | * Executes the function to check if andSelf is used.
21 | *
22 | * @param {Object} context
23 | * @returns {Object}
24 | */
25 | create: function (context) {
26 | return {
27 | /**
28 | * Checks if andSelf is used in the node and reports it.
29 | *
30 | * @param {Object} node - The node to check.
31 | */
32 | CallExpression: function (node) {
33 | if (node.callee.type !== 'MemberExpression') {return;}
34 |
35 | if (node.callee.property.name !== 'andSelf') {return;}
36 |
37 | if (utils.isjQuery(node)) {
38 | context.report({
39 | node: node,
40 | messageId: 'andSelf'
41 | });
42 | }
43 | }
44 | };
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.1.php.inc:
--------------------------------------------------------------------------------
1 | model = $model ?? ObjectManager::getInstance()->get(ModelFactory::class);
19 | }
20 |
21 | /**
22 | * @return Model
23 | */
24 | public function otherMethodThatCallsGetInstanceBad(): void
25 | {
26 | $modelFactory = ObjectManager::getInstance()->get(OtherFactory::class);
27 | $modelFactory->create();
28 | }
29 |
30 | /**
31 | * @return Model
32 | */
33 | public function otherMethodThatCallsGetInstanceGood(): void
34 | {
35 | $model = $this->model ?? ObjectManager::getInstance()->get(Model::class);
36 | $model->something();
37 | }
38 |
39 | public function variablePositive(): void
40 | {
41 | $objectManager = ObjectManager::getInstance();
42 | $this->_entityFactory = $objectManager->get(EntityFactoryInterface::class);
43 | }
44 |
45 | public function variableNegative(): void
46 | {
47 | $objectManager = ObjectManager::getInstance();
48 | $this->_entityFactory = $objectManager->get(EntityFactory::class);
49 | }
50 | }
51 |
52 |
53 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Templates/ThisInTemplateSniff.php:
--------------------------------------------------------------------------------
1 | getTokensAsString($stackPtr, 1) !== '$this') {
33 | return;
34 | }
35 | $isHelperCall = $phpcsFile->findNext(T_STRING, $stackPtr, null, false, 'helper', true);
36 | if ($isHelperCall) {
37 | $phpcsFile->addWarning(self::MESSAGE_HELPER, $stackPtr, 'FoundHelper');
38 | }
39 | if ($phpcsFile->addFixableWarning(self::MESSAGE_THIS, $stackPtr, 'FoundThis') === true) {
40 | $phpcsFile->fixer->beginChangeset();
41 | $phpcsFile->fixer->replaceToken($stackPtr, '$block');
42 | $phpcsFile->fixer->endChangeset();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc:
--------------------------------------------------------------------------------
1 | _setExtensionAttributes($extensionAttributes);
24 | }
25 |
26 | /**
27 | * Short description of method
28 | *
29 | * @param int
30 | * @return int
31 | */
32 | public function invalidDocBlockShouldNotCauseFatalErrorInSniff(int $number): int
33 | {
34 | return $number;
35 | }
36 |
37 | /**
38 | * Short description.
39 | *
40 | * @param string $text
41 | * @return string
42 | */
43 | #[\ReturnTypeWillChange]
44 | public function methodWithAttributeAndValidDocblock(string $text): string
45 | {
46 | return $text;
47 | }
48 |
49 | #[\ReturnTypeWillChange]
50 | public function methodWithAttributeAndWithoutDocblock(string $text): string
51 | {
52 | return $text;
53 | }
54 |
--------------------------------------------------------------------------------
/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php:
--------------------------------------------------------------------------------
1 | 1,
19 | 10 => 1,
20 | 18 => 1,
21 | 30 => 1,
22 | 36 => 1,
23 | 45 => 2,
24 | 47 => 1,
25 | 55 => 1,
26 | 63 => 1,
27 | 80 => 1,
28 | 112 => 1,
29 | 118 => 1,
30 | 137 => 1,
31 | 145 => 2,
32 | 185 => 1,
33 | 227 => 1,
34 | 235 => 1,
35 | 261 => 1,
36 | 268 => 2,
37 | 269 => 1,
38 | 277 => 1,
39 | 278 => 1,
40 | 288 => 1,
41 | 289 => 1,
42 | 298 => 1,
43 | 396 => 1,
44 | 407 => 1,
45 | 418 => 1,
46 | 424 => 1,
47 | ];
48 | }
49 |
50 | /**
51 | * @inheritdoc
52 | */
53 | public function getWarningList()
54 | {
55 | return [
56 | 326 => 1,
57 | 336 => 1,
58 | 347 => 1,
59 | 358 => 1
60 | ];
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php:
--------------------------------------------------------------------------------
1 | 0) {
42 | return;
43 | }
44 |
45 | // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
46 | $content = file_get_contents($phpcsFile->getFilename());
47 |
48 | if ($this->isCopyrightYearValid($content) === false) {
49 | $phpcsFile->addWarningOnLine(
50 | 'Copyright is missing or Copyright content/year is not valid',
51 | null,
52 | self::WARNING_CODE
53 | );
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/eslint/rules/jquery-no-bind-unbind.js:
--------------------------------------------------------------------------------
1 | // Import utils using ES module syntax
2 | import utils from './utils.js';
3 |
4 | export default {
5 | meta: {
6 | type: 'suggestion',
7 | docs: {
8 | description: 'Disallow the use of the deprecated $.bind and $.unbind',
9 | category: 'jQuery deprecated functions',
10 | recommended: true,
11 | url: 'https://api.jquery.com/bind/'
12 | },
13 | schema: [],
14 | messages: {
15 | bind: 'jQuery $.bind and $.unbind are deprecated, use $.on and $.off instead'
16 | }
17 | },
18 |
19 | /**
20 | * Executes the function to check if bind and unbind are used.
21 | *
22 | * @param {Object} context
23 | * @returns {Object}
24 | */
25 | create: function (context) {
26 | return {
27 | /**
28 | * Checks if bind and unbind are used in the node and reports it.
29 | *
30 | * @param {Object} node - The node to check.
31 | */
32 | CallExpression: function (node) {
33 | if (node.callee.type !== 'MemberExpression') {return;}
34 |
35 | if (!['bind', 'unbind'].includes(node.callee.property.name)) {return;}
36 |
37 | if (utils.isjQuery(node)) {
38 | context.report({
39 | node: node,
40 | messageId: 'bind'
41 | });
42 | }
43 | }
44 | };
45 | }
46 | };
47 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Templates/ThisInTemplateSniff.md:
--------------------------------------------------------------------------------
1 | # Rule: Do not use `$this` in templates
2 | ## Background
3 | In PHTML templates, the current block is available as `$this` and `$block`. The alternative with `$this` has been deprecated and should not be used anymore.
4 |
5 | ## Reasoning
6 | `$this` in templates is a legacy from Magento 1. It still works, however this can change any time, should templates and blocks be further decoupled. That's why for new code you should always use `$block` and restrict it to public methods.
7 |
8 | ## How it works
9 | Any occurrence of `$this` in PHTML files (via file pattern in ruleset.xml) raises a warning.
10 |
11 | ## How to fix
12 |
13 | Replace `$this` with `$block`. If you use private or protected methods, make them public.
14 |
15 | ---
16 |
17 | # Rule: Do not use `helpers` in templates
18 | ## Background
19 | The use of helpers is in general discouraged. For template files, consider using a ViewModel instead.
20 |
21 | ## Reasoning
22 | The use of helpers is in general discouraged therefore any `$this->helper()` code used in PHTML templates should be refactored.
23 |
24 | Consider using ViewModel instead.
25 |
26 | ## How to fix
27 |
28 | Typical example of a helper being used in a PHTML:
29 | ```html
30 | helper()->...; ?>
31 | ```
32 |
33 | Once the ViewModel is created, call it in the PHTML as follow:
34 |
35 | ```html
36 | getViewModel(); ?>
37 | ```
38 | or
39 | ```html
40 | getData('viewModel'); ?>
41 | ```
42 |
--------------------------------------------------------------------------------
/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php:
--------------------------------------------------------------------------------
1 | getTokens();
49 |
50 | if (0 === strpos($tokens[$stackPtr + 1]['content'], '-')
51 | && in_array($tokens[$stackPtr - 1]['content'], $this->symbolsBeforeConcat)
52 | ) {
53 | $phpcsFile->addError('Concatenation is used', $stackPtr, 'ConcatenationUsage');
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------