├── Magento2Framework ├── Tests │ └── Header │ │ ├── CopyrightUnitTest.1.inc │ │ ├── CopyrightUnitTest.3.inc │ │ ├── CopyrightUnitTest.4.inc │ │ ├── CopyrightUnitTest.5.inc │ │ ├── LicenseUnitTest.5.less │ │ ├── LicenseUnitTest.1.inc │ │ ├── LicenseUnitTest.2.inc │ │ ├── LicenseUnitTest.4.xml │ │ ├── LicenseUnitTest.3.xml │ │ ├── CopyrightAnotherExtensionsFilesUnitTest.3.xml │ │ ├── CopyrightAnotherExtensionsFilesUnitTest.4.js │ │ ├── CopyrightUnitTest.2.inc │ │ ├── CopyrightAnotherExtensionsFilesUnitTest.5.less │ │ ├── CopyrightAnotherExtensionsFilesUnitTest.2.js │ │ ├── CopyrightAnotherExtensionsFilesUnitTest.1.xml │ │ ├── CopyrightGraphQLUnitTest.php │ │ ├── CopyrightUnitTest.php │ │ └── LicenseUnitTest.php ├── Sniffs │ └── Header │ │ ├── CopyrightValidation.php │ │ ├── CopyrightGraphQLSniff.php │ │ └── CopyrightAnotherExtensionsFilesSniff.php └── ruleset.xml ├── Magento2 ├── Tests │ ├── Legacy │ │ ├── _files │ │ │ ├── InstallUpgradeUnitTest │ │ │ │ ├── InstallData.inc │ │ │ │ ├── UpgradeData.inc │ │ │ │ ├── data │ │ │ │ │ └── file2.inc │ │ │ │ ├── recurring.inc │ │ │ │ ├── sql │ │ │ │ │ └── file.inc │ │ │ │ ├── upgrade-.inc │ │ │ │ ├── valid-file.inc │ │ │ │ ├── InstallSchema.inc │ │ │ │ ├── UpgradeSchema.inc │ │ │ │ ├── data-install-.inc │ │ │ │ ├── data-upgrade-.inc │ │ │ │ ├── install-sample.inc │ │ │ │ ├── another-data-folder │ │ │ │ │ └── file3.inc │ │ │ │ └── another-sql-folder │ │ │ │ │ └── file4.inc │ │ │ ├── RestrictedCodeUnitTest │ │ │ │ ├── FileWithRestrictedClass.inc │ │ │ │ └── Magento │ │ │ │ │ └── Framework │ │ │ │ │ └── Model │ │ │ │ │ └── ResourceModel │ │ │ │ │ └── Iterator.php │ │ │ └── PhtmlTemplateUnitTest │ │ │ │ └── view │ │ │ │ ├── base │ │ │ │ └── templates │ │ │ │ │ └── PhtmlTemplateUnitTest.1.phtml │ │ │ │ ├── adminhtml │ │ │ │ └── templates │ │ │ │ │ └── PhtmlTemplateUnitTest.3.phtml │ │ │ │ └── frontend │ │ │ │ └── templates │ │ │ │ └── PhtmlTemplateUnitTest.2.phtml │ │ ├── EmailTemplateUnitTest.1.html │ │ ├── EmailTemplateUnitTest.2.html │ │ ├── ModuleXMLUnitTest.3.xml │ │ ├── ModuleXMLUnitTest.1.xml │ │ ├── ModuleXMLUnitTest.4.xml │ │ ├── ObsoleteSystemConfigurationUnitTest.1.xml │ │ ├── ModuleXMLUnitTest.2.xml │ │ ├── WidgetXMLUnitTest.3.xml │ │ ├── ObsoleteSystemConfigurationUnitTest.2.xml │ │ ├── MageEntityUnitTest.inc │ │ ├── WidgetXMLUnitTest.1.xml │ │ ├── ObsoleteAclUnitTest.php │ │ ├── AbstractBlockUnitTest.php │ │ ├── DiConfigUnitTest.php │ │ ├── TableNameUnitTest.php │ │ ├── WidgetXMLUnitTest.2.xml │ │ ├── MageEntityUnitTest.php │ │ ├── AbstractBlockUnitTest.inc │ │ ├── ObsoleteConnectionUnitTest.inc │ │ ├── ObsoleteConfigNodesUnitTest.php │ │ ├── ObsoleteConnectionUnitTest.php │ │ ├── DiConfigUnitTest.xml │ │ ├── ObsoleteAclUnitTest.xml │ │ ├── ObsoleteMenuUnitTest.php │ │ ├── ClassReferencesInConfigurationFilesUnitTest.3.xml │ │ ├── EmailTemplateUnitTest.php │ │ ├── ObsoleteSystemConfigurationUnitTest.php │ │ ├── WidgetXMLUnitTest.php │ │ ├── EscapeMethodsOnBlockClassUnitTest.php │ │ ├── TableNameUnitTest.inc │ │ ├── ModuleXMLUnitTest.php │ │ ├── LayoutUnitTest.php │ │ ├── ClassReferencesInConfigurationFilesUnitTest.php │ │ └── LayoutUnitTest.3.xml │ ├── Classes │ │ ├── AbstractApiUnitTest.2.inc │ │ ├── AbstractApiUnitTest.1.inc │ │ ├── AbstractApiUnitTest.php │ │ ├── DiscouragedDependenciesUnitTest.php │ │ ├── DiscouragedDependenciesUnitTest.1.inc │ │ └── DiscouragedDependenciesUnitTest.2.inc │ ├── PHP │ │ ├── ShortEchoSyntaxUnitTest.inc.fixed │ │ ├── ShortEchoSyntaxUnitTest.inc │ │ ├── VarUnitTest.inc │ │ ├── FinalImplementationUnitTest.inc │ │ ├── GotoUnitTest.inc │ │ ├── LiteralNamespacesUnitTest.inc │ │ ├── LiteralNamespacesUnitTest.php │ │ ├── ShortEchoSyntaxUnitTest.php │ │ ├── FinalImplementationUnitTest.php │ │ ├── GotoUnitTest.php │ │ ├── VarUnitTest.php │ │ ├── ArrayAutovivificationUnitTest.php │ │ ├── ReturnValueCheckUnitTest.php │ │ ├── AutogeneratedClassNotInConstructorUnitTest.php │ │ ├── AutogeneratedClassNotInConstructorUnitTest.2.php.inc │ │ └── AutogeneratedClassNotInConstructorUnitTest.1.php.inc │ ├── NamingConvention │ │ ├── InterfaceNameUnitTest.inc │ │ ├── ReservedWordsUnitTest.inc │ │ ├── InterfaceNameUnitTest.php │ │ └── ReservedWordsUnitTest.php │ ├── Commenting │ │ ├── ConstantsPHPDocFormattingUnitTest.3.inc │ │ ├── ConstantsPHPDocFormattingUnitTest.1.inc │ │ ├── ClassAndInterfacePHPDocFormattingUnitTest.php │ │ ├── ClassPropertyPHPDocFormattingUnitTest.php │ │ ├── ConstantsPHPDocFormattingUnitTest.php │ │ └── ConstantsPHPDocFormattingUnitTest.2.inc │ ├── Eslint │ │ ├── SizeTest.js │ │ ├── BindUnbindTest.js │ │ ├── TrimTest.js │ │ ├── AndSelfTest.js │ │ ├── EventShorthandTest.js │ │ ├── InputEventShorthandTest.js │ │ ├── DeprecatedExprTest.js │ │ ├── MiscDeprecatedFunctionsTest.js │ │ ├── DelegateUndelegateTest.js │ │ ├── SizeTest.php │ │ ├── TrimTest.php │ │ ├── AndSelfTest.php │ │ ├── BindUnbindTest.php │ │ ├── DelegateUndelegateTest.php │ │ ├── DeprecatedExprTest.php │ │ ├── EventShorthandTest.php │ │ ├── InputEventShorthandTest.php │ │ ├── AbstractEslintTestCase.php │ │ └── MiscDeprecatedFunctionsTest.php │ ├── Templates │ │ ├── ThisInTemplateUnitTest.inc │ │ ├── ThisInTemplateUnitTest.inc.fixed │ │ ├── ThisInTemplateUnitTest.php │ │ ├── ObjectManagerUnitTest.1.phtml.inc │ │ └── ObjectManagerUnitTest.php │ ├── Less │ │ ├── QuotesUnitTest.less │ │ ├── PropertiesLineBreakUnitTest.less │ │ ├── SelectorDelimiterUnitTest.less │ │ ├── BracesFormattingUnitTest.less │ │ ├── SemicolonSpacingUnitTest.less │ │ ├── ZeroUnitsUnitTest.less │ │ ├── ImportantPropertyUnitTest.less │ │ ├── CombinatorIndentationUnitTest.less │ │ ├── VariablesUnitTest.less │ │ ├── ColourDefinitionUnitTest.less │ │ ├── TypeSelectorsUnitTest.less │ │ ├── IndentationUnitTest.less │ │ ├── TypeSelectorConcatenationUnitTest.less │ │ ├── QuotesUnitTest.php │ │ ├── PropertiesSortingUnitTest.less │ │ ├── TypeSelectorsUnitTest.php │ │ ├── ImportantPropertyUnitTest.php │ │ ├── PropertiesLineBreakUnitTest.php │ │ ├── SelectorDelimiterUnitTest.php │ │ ├── ZeroUnitsUnitTest.php │ │ ├── VariablesUnitTest.php │ │ ├── BracesFormattingUnitTest.php │ │ ├── SemicolonSpacingUnitTest.php │ │ ├── PropertiesSortingUnitTest.php │ │ ├── TypeSelectorConcatenationUnitTest.php │ │ ├── ColourDefinitionUnitTest.php │ │ ├── CombinatorIndentationUnitTest.php │ │ ├── ClassNamingUnitTest.php │ │ ├── ColonSpacingUnitTest.php │ │ ├── CommentLevelsUnitTest.php │ │ ├── AvoidIdUnitTest.less │ │ ├── IndentationUnitTest.php │ │ ├── ClassNamingUnitTest.less │ │ ├── AbstractLessSniffUnitTestCase.php │ │ ├── ColonSpacingUnitTest.less │ │ ├── AvoidIdUnitTest.php │ │ └── CommentLevelsUnitTest.less │ ├── Namespaces │ │ ├── ImportsFromTestNamespaceUnitTest.inc │ │ └── ImportsFromTestNamespaceUnitTest.php │ ├── Security │ │ ├── SuperglobalUnitTest.inc │ │ ├── LanguageConstructUnitTest.inc │ │ ├── InsecureFunctionUnitTest.inc │ │ ├── LanguageConstructUnitTest.php │ │ ├── IncludeFileUnitTest.inc │ │ ├── SuperglobalUnitTest.php │ │ ├── IncludeFileUnitTest.php │ │ ├── InsecureFunctionUnitTest.php │ │ └── XssTemplateUnitTest.php │ ├── Whitespace │ │ ├── MultipleEmptyLinesUnitTest.inc │ │ └── MultipleEmptyLinesUnitTest.php │ ├── Strings │ │ ├── StringConcatUnitTest.inc │ │ ├── ExecutableRegExUnitTest.inc │ │ ├── ExecutableRegExUnitTest.php │ │ └── StringConcatUnitTest.php │ ├── Html │ │ ├── HtmlDirectiveUnitTest.2.inc │ │ ├── HtmlBindingUnitTest.php │ │ ├── HtmlClosingVoidTagsUnitTest.php │ │ ├── HtmlSelfClosingTagsUnitTest.php │ │ ├── HtmlCollapsibleAttributeUnitTest.php │ │ ├── HtmlClosingVoidTagsUnitTest.inc │ │ ├── HtmlDirectiveUnitTest.php │ │ ├── HtmlBindingUnitTest.1.inc │ │ ├── HtmlSelfClosingTagsUnitTest.1.inc │ │ └── HtmlCollapsibleAttributeUnitTest.1.inc │ ├── Methods │ │ ├── DeprecatedModelMethodUnitTest.inc │ │ └── DeprecatedModelMethodUnitTest.php │ ├── Functions │ │ ├── StaticFunctionUnitTest.inc │ │ ├── StaticFunctionUnitTest.php │ │ ├── FunctionsDeprecatedWithoutArgumentUnitTest.php │ │ ├── FunctionsDeprecatedWithoutArgumentUnitTest.inc │ │ └── FunctionsDeprecatedWithoutArgumentUnitTest.inc.fixed │ ├── Exceptions │ │ ├── DirectThrowUnitTest.1.inc │ │ ├── ThrowCatchUnitTest.1.inc │ │ ├── DirectThrowUnitTest.2.inc │ │ ├── TryProcessSystemResourcesUnitTest.php │ │ ├── TryProcessSystemResourcesUnitTest.inc │ │ ├── ThrowCatchUnitTest.php │ │ └── DirectThrowUnitTest.php │ ├── Annotation │ │ ├── MethodArgumentsUnitTest.php │ │ ├── MethodArgumentsUnitTest.inc │ │ └── MethodAnnotationStructureUnitTest.php │ ├── Performance │ │ ├── ForeachArrayMergeUnitTest.php │ │ └── ForeachArrayMergeUnitTest.inc │ ├── GraphQL │ │ ├── ValidEnumValueUnitTest.php │ │ ├── ValidTopLevelFieldNameUnitTest.php │ │ ├── ValidFieldNameUnitTest.php │ │ ├── ValidArgumentNameUnitTest.php │ │ ├── AbstractGraphQLSniffUnitTestCase.php │ │ ├── ValidEnumValueUnitTest.graphqls │ │ ├── ValidFieldNameUnitTest.graphqls │ │ └── ValidTopLevelFieldNameUnitTest.graphqls │ ├── Translation │ │ ├── ConstantUsageUnitTest.php │ │ └── ConstantUsageUnitTest.inc │ ├── SQL │ │ └── RawQueryUnitTest.php │ └── CodeAnalysis │ │ └── EmptyBlockUnitTest.php ├── Rector │ └── Tests │ │ ├── ReplaceMbStrposNullLimit │ │ ├── Fixture │ │ │ └── replace_null.php.inc │ │ ├── config │ │ │ └── configured_rule.php │ │ └── ReplaceMbStrposNullLimitTest.php │ │ ├── ReplaceNewDateTimeNull │ │ ├── Fixture │ │ │ └── replace_null.php.inc │ │ ├── config │ │ │ └── configured_rule.php │ │ └── ReplaceNewDateTimeNullTest.php │ │ ├── ReplacePregSplitNullLimit │ │ ├── config │ │ │ └── configured_rule.php │ │ ├── Fixture │ │ │ └── replace_null.php.inc │ │ └── ReplacePregSplitNullLimitTest.php │ │ └── AddArrayAccessInterfaceReturnTypes │ │ ├── config │ │ └── configured_rule.php │ │ ├── Fixture │ │ └── addReturnTypes.php.inc │ │ └── AddArrayAccessInterfaceReturnTypesTest.php └── Sniffs │ ├── Functions │ └── DiscouragedFunctionSniff.md │ ├── Less │ ├── TokenizerSymbolsInterface.php │ ├── QuotesSniff.php │ ├── CombinatorIndentationSniff.php │ ├── PropertiesLineBreakSniff.php │ ├── ImportantPropertySniff.php │ └── TypeSelectorConcatenationSniff.php │ ├── Performance │ └── ForeachArrayMergeSniff.md │ ├── Namespaces │ └── ImportsFromTestNamespaceSniff.md │ ├── PHP │ ├── GotoSniff.php │ ├── FinalImplementationSniff.php │ └── VarSniff.php │ ├── GraphQL │ └── ValidFieldNameSniff.php │ ├── Security │ └── InsecureFunctionSniff.php │ └── Templates │ ├── ThisInTemplateSniff.php │ └── ThisInTemplateSniff.md ├── .gitignore ├── COPYING.txt ├── eslint ├── package.json ├── .eslintrc-jquery ├── index.js └── rules │ ├── jquery-no-size.js │ ├── jquery-no-trim.js │ ├── jquery-no-andSelf.js │ └── jquery-no-bind-unbind.js ├── phpunit-bootstrap.php ├── package.json ├── .github ├── ISSUE_TEMPLATE │ ├── new-rule-proposal.md │ ├── existing-rule-enhancement.md │ └── bug_report.md └── .metadata.json ├── phpunit.xml.dist └── rector.php /Magento2Framework/Tests/Header/CopyrightUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /Magento2/Tests/Classes/AbstractApiUnitTest.2.inc: -------------------------------------------------------------------------------- 1 | {{var "H1"}} 2 |

{{var "H2"}}

3 |

{{var "p"}} {{var "p"}}

4 | 5 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/CopyrightUnitTest.4.inc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/CopyrightUnitTest.5.inc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/LicenseUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | escapeHtml($block->getGroupCode()); 3 | echo $this->escapeHtml($this->getGroupCode()); 4 | $this->foo(); 5 | $this->helper(); 6 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/BindUnbindTest.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | ], function ($) { 4 | $(function () { 5 | 'use strict'; 6 | 7 | $('.btn1').bind('click'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html: -------------------------------------------------------------------------------- 1 |

{{htmlescape "H1"}}

2 |

{{escapehtml "H2"}}

3 |

{{escapehtml "p"}} {{htmlescape "p"}}

4 |

{{trans "Translateme"}}

5 | -------------------------------------------------------------------------------- /Magento2/Tests/Templates/ThisInTemplateUnitTest.inc.fixed: -------------------------------------------------------------------------------- 1 | escapeHtml($block->getGroupCode()); 3 | echo $block->escapeHtml($block->getGroupCode()); 4 | $block->foo(); 5 | $block->helper(); 6 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/TrimTest.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | ], function ($) { 4 | $(function () { 5 | 'use strict'; 6 | 7 | $.trim(' hello, how are you? '); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/LicenseUnitTest.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/LicenseUnitTest.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/AndSelfTest.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | ], function ($) { 4 | $(function () { 5 | 'use strict'; 6 | 7 | $('div').find('p').andSelf().addClass('border'); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2021 Adobe 3 | * All Rights Reserved. 4 | */ 5 | 6 | define([ 7 | 'jquery' 8 | ], function () { 9 | 'use strict'; 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /Magento2Framework/Tests/Header/CopyrightUnitTest.2.inc: -------------------------------------------------------------------------------- 1 | 7 | 6 | ----- 7 | 12 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/EventShorthandTest.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | ], function (jQuery) { 4 | jQuery(document).ready(function () { 5 | 'use strict'; 6 | jQuery('#result').unload(function () { 7 | }); 8 | }); 9 | }); 10 | 11 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/InputEventShorthandTest.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | ], function ($) { 4 | $(function () { 5 | 'use strict'; 6 | 7 | $('#result').blur(); 8 | $.fn.focus(function () { 9 | }); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/DeprecatedExprTest.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'jquery', 3 | ], function (jQuery) { 4 | $(function () { 5 | 'use strict'; 6 | 7 | jQuery.extend(jQuery.expr[':'], {}); 8 | jQuery.extend(jQuery.expr.filters, {}); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/VarUnitTest.inc: -------------------------------------------------------------------------------- 1 | 9 | ----- 10 | 18 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc: -------------------------------------------------------------------------------- 1 | 7 | 11 | 12 | Template content doesn't matter. The JSON is invalid. 13 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ImportantPropertyUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .correct-important-property { 7 | background-color: green !important; 8 | } 9 | 10 | .incorrect-important-property { 11 | background-color: red!important; 12 | } 13 | -------------------------------------------------------------------------------- /Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc: -------------------------------------------------------------------------------- 1 | getResource()->save($model); 4 | 5 | $model->getResource()->load($model, $id); 6 | 7 | $model->getResource()->delete($model); 8 | 9 | $model->getResource()->myCustomMethod(); 10 | 11 | $model->myCustomMethod(); 12 | 13 | $model->anotherMethodWithResource()->save($model); 14 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/GotoUnitTest.inc: -------------------------------------------------------------------------------- 1 | create(Magento\CustomerSegment\Model\Segment\Condition\Customer\Address::class); 8 | } 9 | 10 | public function notOk() 11 | { 12 | $this->create('Magento\CustomerSegment\Model\Segment\Condition\Customer\Address'); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ModuleXMLUnitTest.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/CombinatorIndentationUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .nav+.bar { 7 | color: @bar__color; 8 | } 9 | 10 | .nav +.foo { 11 | color: @bar__color; 12 | } 13 | 14 | .nav+ .baz { 15 | color: @bar__color; 16 | } 17 | 18 | .nav + .qux { 19 | color: @bar__color; 20 | } 21 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/VariablesUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .nav { 7 | random: 'stuff'; 8 | } 9 | 10 | @INCORRECT-PROPERTY__color: red; 11 | 12 | // 13 | // Variables not correctly located 14 | // _____________________________________________ 15 | 16 | // Colors 17 | @btn__color: red; 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "eslint/eslint.config.mjs", 6 | "scripts": { 7 | "eslint": "./node_modules/.bin/eslint -c eslint/eslint.config.mjs" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "eslint": "~9.22.0", 13 | "magento-coding-standard-eslint-plugin": "file:./eslint" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/ReplaceNewDateTimeNull/config/configured_rule.php: -------------------------------------------------------------------------------- 1 | rule(ReplaceNewDateTimeNull::class); 13 | }; 14 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ModuleXMLUnitTest.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/ReplaceMbStrposNullLimit/config/configured_rule.php: -------------------------------------------------------------------------------- 1 | rule(ReplaceMbStrposNullLimit::class); 13 | }; 14 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ColourDefinitionUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | @red: #aaaaaa; 7 | @blue: #00F; 8 | @green: #0f0; 9 | @purple: #abcdef; 10 | 11 | .my{ 12 | color: @red; 13 | } 14 | 15 | .foo { 16 | color: #aaa; 17 | } 18 | 19 | .baz { 20 | color: @blue; 21 | } 22 | 23 | .bar { 24 | color: @green; 25 | } 26 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/ReplacePregSplitNullLimit/config/configured_rule.php: -------------------------------------------------------------------------------- 1 | rule(ReplacePregSplitNullLimit::class); 13 | }; 14 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ModuleXMLUnitTest.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Magento2/Tests/NamingConvention/ReservedWordsUnitTest.inc: -------------------------------------------------------------------------------- 1 | LI { 18 | #bar .baz(); 19 | } 20 | 21 | .nav > ul { 22 | foo: 'bar'; 23 | } 24 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/IndentationUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .nav { 7 | background: green; 8 | .nav-item { 9 | background: green; 10 | } 11 | } 12 | 13 | .bar { 14 | background: red; 15 | .bar-item { 16 | background: red; 17 | .bar-item-child { 18 | background: red; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/AddArrayAccessInterfaceReturnTypes/config/configured_rule.php: -------------------------------------------------------------------------------- 1 | rule(AddArrayAccessInterfaceReturnTypes::class); 13 | }; 14 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteSystemConfigurationUnitTest.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | test sections 10 | test tabs 11 | 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new-rule-proposal.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: New rule proposal 3 | about: Proposal for new Magento Coding Standard rule 4 | title: '' 5 | labels: proposal 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Rule 11 | 12 | 13 | ### Reason 14 | 15 | 16 | ### Implementation 17 | 18 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/ReplacePregSplitNullLimit/Fixture/replace_null.php.inc: -------------------------------------------------------------------------------- 1 | 9 | ----- 10 | 18 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ModuleXMLUnitTest.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/_files/RestrictedCodeUnitTest/FileWithRestrictedClass.inc: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .product-list-item { 7 | background: green; 8 | } 9 | 10 | .product-image { 11 | background: green; 12 | } 13 | 14 | .product { 15 | random: 'stuff'; 16 | &-list { 17 | background: red; 18 | &-item { 19 | background: red; 20 | } 21 | } 22 | &-image { 23 | background: red; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteSystemConfigurationUnitTest.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | test no error 11 | test no error 12 |
13 |
14 |
15 |
16 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/QuotesUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | ]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/PropertiesSortingUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .menu { 7 | color: white; 8 | text-align: center; 9 | background-color: red; 10 | 11 | .item { 12 | background-color: green; 13 | color: white; 14 | text-align: center; 15 | } 16 | } 17 | 18 | .nav { 19 | background-color: green; 20 | color: white; 21 | text-align: center; 22 | 23 | .item { 24 | color: white; 25 | text-align: center; 26 | background-color: red; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/TypeSelectorsUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | ]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/SizeTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'SizeTest.js', 21 | ['jQuery.size() removed, use jQuery.length'] 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ImportantPropertyUnitTest.php: -------------------------------------------------------------------------------- 1 | 1 17 | ]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/PropertiesLineBreakUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | ]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/SelectorDelimiterUnitTest.php: -------------------------------------------------------------------------------- 1 | 1 17 | ]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/TrimTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'TrimTest.js', 21 | ['jQuery.trim is deprecated; use String.prototype.trim'] 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ZeroUnitsUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 8 => 1, 18 | ]; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList() 25 | { 26 | return []; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/VariablesUnitTest.php: -------------------------------------------------------------------------------- 1 | 2, 17 | 17 => 1 18 | ]; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList() 25 | { 26 | return []; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/AndSelfTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'AndSelfTest.js', 21 | ['jQuery.andSelf() removed, use jQuery.addBack()'] 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlBindingUnitTest.php: -------------------------------------------------------------------------------- 1 | 6]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/MageEntityUnitTest.inc: -------------------------------------------------------------------------------- 1 | getAttributeRawValue($categoryId, 'name', Mage::app()->getStore()); 5 | $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute(); 6 | $lnk = Mage_Downloadable_Model_Link::getLinkDir(); 7 | $lnk = Enterprise_Mage_Downloadable_Model_Link::getLinkDir(); 8 | $lnk = new Enterprise_Mage_Downloadable_Model_Link; 9 | $instance = new Mage(); 10 | 11 | $staticCall = SomeClass::call(); 12 | 13 | $directObject = new SomeClass; 14 | 15 | $instance = new MagentoAllowedClass(); 16 | $model = MagentoAllowedClass :: getModel(); 17 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/BracesFormattingUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 16 => 1, 18 | ]; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList() 25 | { 26 | return []; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/SemicolonSpacingUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 12 => 1 18 | ]; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList() 25 | { 26 | return []; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/existing-rule-enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Existing rule enhancement 3 | about: Improvement for existing Magento Coding Standard rule 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Description 11 | 12 | 13 | ### Expected behavior 14 | 15 | 16 | ### Benefits 17 | 18 | 19 | ### Additional information 20 | 21 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.php: -------------------------------------------------------------------------------- 1 | 15]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.php: -------------------------------------------------------------------------------- 1 | 9]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/PropertiesSortingUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 26 => 1 18 | ]; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList() 25 | { 26 | return []; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlCollapsibleAttributeUnitTest.php: -------------------------------------------------------------------------------- 1 | 3]; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | List of Products that are set as New 12 | Deprecated 13 | 14 | Deprecated 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 22 => 1 18 | ]; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList() 25 | { 26 | return []; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ColourDefinitionUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 7 => 1, 18 | 16 => 1, 19 | ]; 20 | } 21 | 22 | /** 23 | * @inheritdoc 24 | */ 25 | public function getWarningList() 26 | { 27 | return []; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | vendor/squizlabs/php_codesniffer/tests/Standards/AllSniffs.php 6 | 7 | 8 | Magento2/Rector/Tests 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/BindUnbindTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'BindUnbindTest.js', 21 | ['jQuery $.bind and $.unbind are deprecated, use $.on and $.off instead'] 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/CombinatorIndentationUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 10 => 1, 18 | 14 => 1, 19 | ]; 20 | } 21 | 22 | /** 23 | * @inheritdoc 24 | */ 25 | public function getWarningList() 26 | { 27 | return []; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/LiteralNamespacesUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Magento2/Tests/Strings/ExecutableRegExUnitTest.inc: -------------------------------------------------------------------------------- 1 | (.*?))xes', '"" . strtoupper("$2") . ""', $html); 17 | 18 | $a = preg_replace( 19 | '#(.*?)#e', 20 | '"" . strtoupper("$2") . ""', 21 | $html 22 | ); 23 | 24 | $string = 'April 15, 2003'; 25 | $replacement = '${1}1,$3'; 26 | $b = preg_replace('/(\w+) (\d+), (\d+)/i', $replacement, $string); 27 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/DirectThrowUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | isEnabled) { 10 | throw new Exception('Action disabled.'); 11 | } 12 | } 13 | 14 | public function exceptionTest() 15 | { 16 | if (!$this->isEnabled) { 17 | throw new \Exception('Action disabled.'); 18 | } 19 | } 20 | 21 | public function localizedExceptionTest() 22 | { 23 | 24 | if (!$this->isEnabled) { 25 | throw new LocalizedException('Localized exception.'); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ClassNamingUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 10 => 1, 18 | 14 => 1, 19 | 18 => 1 20 | ]; 21 | } 22 | 23 | /** 24 | * @inheritdoc 25 | */ 26 | public function getWarningList() 27 | { 28 | return []; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ColonSpacingUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 12 => 1, 18 | 16 => 2, 19 | 20 => 1, 20 | ]; 21 | } 22 | 23 | /** 24 | * @inheritdoc 25 | */ 26 | public function getWarningList() 27 | { 28 | return []; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md: -------------------------------------------------------------------------------- 1 | # Rule: getimagesize() is discouraged 2 | 3 | ## Reason 4 | 5 | [getimagesize](https://www.php.net/manual/en/function.getimagesize.php) function works only with local and supported streams. 6 | With introduction of more advanced storages, like AWS S3 or Azure Blob Storage this function will cause issues where file is not accessible. 7 | 8 | ## How to fix 9 | 10 | [getimagesizefromstring](https://www.php.net/manual/en/function.getimagesizefromstring.php) can be used instead to retrieve all the information from file. 11 | This function works with data strings, so you should read the file content using specific adapter before using it. 12 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 7 => 1, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Magento2/Tests/Classes/AbstractApiUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | 1, 19 | 6 => 1, 20 | ]; 21 | } 22 | 23 | /** 24 | * @inheritdoc 25 | */ 26 | public function getWarningList() 27 | { 28 | return []; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/GotoUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 4 => 1, 20 | 15 => 1, 21 | ]; 22 | } 23 | 24 | /** 25 | * @inheritdoc 26 | */ 27 | public function getWarningList() 28 | { 29 | return []; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/DelegateUndelegateTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'DelegateUndelegateTest.js', 21 | ['jQuery $.delegate and $.undelegate are deprecated, use $.on and $.off instead'] 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Magento2/Tests/Whitespace/MultipleEmptyLinesUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 12 => 1, 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/VarUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 10 => 1, 28 | 11 => 1, 29 | 12 => 1, 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/ThrowCatchUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | 2, 27 | 4 => 1, 28 | 5 => 2, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 |
21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteAclUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 20 => 1, 28 | 23 => 1 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/CommentLevelsUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 30 => 1, 18 | 31 => 1, 19 | 44 => 1, 20 | 46 => 1, 21 | 47 => 1 22 | ]; 23 | } 24 | 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function getWarningList() 29 | { 30 | return []; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 5 => 1, 28 | 7 => 1, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/AvoidIdUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | #foo[bar], 7 | #foo[bar=bash], 8 | #foo[bar~=bash], 9 | #foo[bar$=bash], 10 | #foo[bar*=bash], 11 | #foo[bar|=bash], 12 | #foo[bar='bash'], 13 | #foo:hover, 14 | #foo:nth-last-of-type(n), 15 | #foo::before, 16 | #foo + div, 17 | #foo > div, 18 | #foo ~ div, 19 | #foo\3Abar ~ div, 20 | #foo\:bar ~ div, 21 | #foo.bar .baz, 22 | div#foo { 23 | blah: 'abc'; 24 | } 25 | 26 | .my #foo, 27 | #foo .blah, 28 | .my #foo .blah { 29 | some: 'stuff'; 30 | } 31 | .blah { 32 | #bar .baz(); 33 | .foo #bar .baz(); 34 | #bar .baz(); 35 | 36 | #bar .baz; 37 | .foo #bar .baz; 38 | #bar .baz; 39 | } 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/IndentationUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 17 | 15 => 1, 18 | 16 => 1, 19 | 17 => 1, 20 | 18 => 1, 21 | 19 => 1, 22 | 20 => 1 23 | ]; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getWarningList() 30 | { 31 | return []; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Strings/ExecutableRegExUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 10 => 1, 20 | 16 => 1, 21 | 18 => 1, 22 | ]; 23 | } 24 | 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function getWarningList() 29 | { 30 | return []; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Magento2/Tests/Annotation/MethodArgumentsUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 21 => 1, 20 | 32 => 1, 21 | 50 => 1 22 | ]; 23 | } 24 | 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function getWarningList() 29 | { 30 | return []; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Technical issue with Magento Coding Standard 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Preconditions 11 | 14 | 1. 15 | 2. 16 | 17 | ### Steps to reproduce 18 | 21 | 1. 22 | 2. 23 | 24 | ### Expected result 25 | 26 | 1. 27 | 2. 28 | 29 | ### Actual result 30 | 31 | 1. 32 | 2. 33 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/DirectThrowUnitTest.2.inc: -------------------------------------------------------------------------------- 1 | isEnabled) { 13 | throw new Exception('Action disabled.'); 14 | } 15 | } 16 | 17 | public function exceptionTest() 18 | { 19 | if (!$this->isEnabled) { 20 | throw new \Exception('Action disabled.'); 21 | } 22 | } 23 | 24 | public function localizedExceptionTest() 25 | { 26 | 27 | if (!$this->isEnabled) { 28 | throw new LocalizedException('Localized exception.'); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/Functions/StaticFunctionUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 30 | 17 => 1 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.github/.metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "templateVersion": "0.2", 3 | "product": { 4 | "name": "magento/magento-coding-standard", 5 | "description": "A set of Magento specific PHP CodeSniffer rules" 6 | }, 7 | "contacts": { 8 | "team": { 9 | "name": "HAMMER", 10 | "DL": "Grp-RQ-HAMMER", 11 | "slackChannel": "gl-hammer-team" 12 | } 13 | }, 14 | "ticketTracker": { 15 | "functionalJiraQueue": { 16 | "projectKey": "AC", 17 | "component": "Github" 18 | }, 19 | "securityJiraQueue": { 20 | "projectKey": "MAGREQ", 21 | "component": "Commerce M2" 22 | } 23 | }, 24 | "productionCodeBranches": ["develop"] 25 | } -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/AbstractBlockUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 20 => 1, 20 | 24 => 1, 21 | 28 => 1, 22 | 30 => 1 23 | ]; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getWarningList() 30 | { 31 | return []; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/DiConfigUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 16 => 1, 28 | 17 => 1, 29 | 18 => 1, 30 | 19 => 1 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 30 | 5 => 1 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Security/LanguageConstructUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 8 => 1, 20 | 10 => 1, 21 | 14 => 1, 22 | 15 => 1, 23 | ]; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getWarningList() 30 | { 31 | return []; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/TableNameUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 7 => 1, 20 | 16 => 1, 21 | 20 => 1, 22 | 40 => 1, 23 | ]; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getWarningList($testFile = '') 30 | { 31 | return []; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 17 | 18 | 19 | List of Products that are set as New 20 | 21 | 22 | 23 | 24 | Deprecated 25 | 26 | 27 | 28 | Deprecated 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Magento2/Tests/NamingConvention/InterfaceNameUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 30 | 4 => 1, 31 | 5 => 1, 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Magento2/Tests/Performance/ForeachArrayMergeUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 31 | 19 => 1, 32 | 41 => 1 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Magento2/Tests/Strings/StringConcatUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 4 => 1, 28 | 6 => 1, 29 | 10 => 1, 30 | 11 => 1, 31 | 15 => 1, 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/DeprecatedExprTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'DeprecatedExprTest.js', 21 | [ 22 | 'jQuery.expr[":"] is deprecated; Use jQuery.expr.pseudos instead', 23 | 'jQuery.expr.filters is deprecated; Use jQuery.expr.pseudos instead' 24 | ] 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/MageEntityUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 4 => 1, 20 | 5 => 1, 21 | 6 => 1, 22 | 7 => 1, 23 | 8 => 1, 24 | 9 => 1 25 | ]; 26 | } 27 | 28 | /** 29 | * @inheritdoc 30 | */ 31 | public function getWarningList() 32 | { 33 | return []; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Magento2/Sniffs/Less/TokenizerSymbolsInterface.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'EventShorthandTest.js', 21 | [ 22 | 'jQuery.unload() was removed, use .on("unload", fn) instead', 23 | 'jQuery.ready(handler) is deprecated and should be replaced with jQuery(handler)' 24 | ] 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ClassNamingUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | .UPPERCASE { 7 | background: red; 8 | } 9 | 10 | .Capital { 11 | background: red; 12 | } 13 | 14 | .camelCase { 15 | background: red; 16 | } 17 | 18 | .snake_case { 19 | background: red; 20 | } 21 | 22 | ._helper { 23 | background: green; 24 | } 25 | 26 | .__another-helper { 27 | background: green; 28 | } 29 | 30 | .category-title { 31 | background: green; 32 | } 33 | 34 | // @see https://github.com/magento/magento-coding-standard/issues/425 35 | .a { 36 | text-decoration: none; 37 | } 38 | 39 | // @see https://github.com/magento/magento-coding-standard/issues/409 40 | .admin__allowed { 41 | background: green; 42 | } 43 | -------------------------------------------------------------------------------- /Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md: -------------------------------------------------------------------------------- 1 | # Rule: array_merge(...) is used in a loop and is a resources greedy construction 2 | 3 | ## Reason 4 | Merging arrays in a loop is slow and causes high CPU usage. 5 | 6 | ## How to Fix 7 | Typical example when `array_merge` is being used in the loop: 8 | ``` php 9 | $options = []; 10 | foreach ($configurationSources as $source) { 11 | // code here 12 | $options = array_merge($options, $source->getOptions()); 13 | } 14 | ``` 15 | 16 | In order to reduce execution time `array_merge` can be called only once: 17 | ``` php 18 | $options = []; 19 | foreach ($configurationSources as $source) { 20 | // code here 21 | $options[] = $source->getOptions(); 22 | } 23 | 24 | $options = array_merge([], ...$options); 25 | ``` 26 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/AbstractBlockUnitTest.inc: -------------------------------------------------------------------------------- 1 | getChildHtml( 4 | function($param){ 5 | $param->something(); 6 | }, 7 | 'aa' 8 | ); 9 | 10 | $this->getChildHtml( 11 | function($param){ 12 | $param->something(); 13 | }, 14 | 'aa', 15 | 2 16 | ); 17 | 18 | return $this->getChildHtml('aa', 'bb'); 19 | 20 | return $this->getChildHtml('aa', 'bb', 1, true); 21 | 22 | $this->getChildHtml(); 23 | 24 | $this->testMethod()->getChildHtml('aa', 'bb', 'cc'); 25 | 26 | $this->getChildChildHtml('aa', true, 'cc'); 27 | 28 | $this->getChildChildHtml('aa', true, 'cc', 1); 29 | 30 | $this->getChildChildHtml('aa' . 'bb', !(1 + 1) * (int) $this, 'cc', 1); 31 | 32 | private function getChildHtml($aa, $bb, $cc = 'cc') 33 | { 34 | } 35 | 36 | $this->getChilChilddHtml(); 37 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/TryProcessSystemResourcesUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 30 | 24 => 1, 31 | 26 => 1, 32 | 28 => 1 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 20 | 15 => 1, 21 | 16 => 1, 22 | 17 => 1, 23 | 18 => 1, 24 | 19 => 1, 25 | ]; 26 | } 27 | 28 | /** 29 | * @inheritDoc 30 | */ 31 | protected function getWarningList() 32 | { 33 | return []; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/AddArrayAccessInterfaceReturnTypes/Fixture/addReturnTypes.php.inc: -------------------------------------------------------------------------------- 1 | 20 | ----- 21 | 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.inc: -------------------------------------------------------------------------------- 1 | _getReadConnection(); 8 | 9 | $connection = new Connection(); 10 | return $connection->_getWriteConnection(); 11 | 12 | $this->getMethod( 13 | function($param){ 14 | $param->_getWriteAdapter(); 15 | } 16 | ); 17 | 18 | $writeAdapter = $this->getWriteAdapter(); 19 | 20 | protected function getConnection() 21 | { 22 | return $this->_resource->getReadConnection($this->connection); 23 | } 24 | 25 | return $this->_getReadAdapter(); 26 | 27 | $this->getReadAdapterMyMehtod(); 28 | 29 | private function getReadAdapter() 30 | { 31 | 32 | } 33 | 34 | $getWriteAdapter = new WriteAdapter(); 35 | 36 | $getWriteAdapter = $this->getWriteAdapter(); 37 | -------------------------------------------------------------------------------- /Magento2/Tests/Security/IncludeFileUnitTest.inc: -------------------------------------------------------------------------------- 1 | 20]; 19 | } elseif ($testFile === 'HtmlDirectiveUnitTest.2.inc') { 20 | return [1 => 1]; 21 | } 22 | 23 | return []; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getWarningList() 30 | { 31 | return []; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteConfigNodesUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 20 | 37 => 1, 21 | ]; 22 | } 23 | return []; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function getWarningList(): array 30 | { 31 | return []; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteConnectionUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 10 => 1, 28 | 14 => 1, 29 | 18 => 1, 30 | 22 => 1, 31 | 25 => 1, 32 | 29 => 1, 33 | 36 => 1 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/ArrayAutovivificationUnitTest.php: -------------------------------------------------------------------------------- 1 | 1 30 | ]; 31 | } 32 | 33 | return []; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/InputEventShorthandTest.php: -------------------------------------------------------------------------------- 1 | assertFileContainsError( 20 | 'InputEventShorthandTest.js', 21 | [ 22 | 'Instead of .blur(fn) use .on("blur", fn). Instead of .blur() use .trigger("blur")', 23 | 'Instead of .focus(fn) use .on("focus", fn). Instead of .focus() use .trigger("focus")', 24 | ] 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.md: -------------------------------------------------------------------------------- 1 | # Rule: Do not import from `Test` namespaces 2 | ## Background 3 | Sometimes IDE imports the namespace with `Test` automatically for return data type like string, float etc or any other means. 4 | 5 | ## Reasoning 6 | Time to time we're getting issue with running tests on PRs in magento/magento2 repository because someone imported `\Magento\Tests\NamingConvention\true\string` by mistake. As result - we have "No build reports available" for "Database Compare build", "Functional Tests build", "Sample Data Tests build" while Static tests are shown as "failing" but in results - we don't really have reason 7 | 8 | ## How it works 9 | Any occurrence starts with `Magento\Tests` in import from the namespace will raise the warning. 10 | 11 | ## How to fix 12 | 13 | Remove `Magento\Tests` from the imported namespaces 14 | -------------------------------------------------------------------------------- /Magento2/Tests/Security/SuperglobalUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 19 | 3 => 1, 20 | 4 => 1, 21 | 5 => 1, 22 | 6 => 1, 23 | 7 => 1, 24 | 8 => 1, 25 | ]; 26 | } 27 | 28 | /** 29 | * @inheritdoc 30 | */ 31 | public function getWarningList() 32 | { 33 | return [ 34 | 9 => 1, 35 | 10 => 1, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Magento2/Tests/Translation/ConstantUsageUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 7 => 1, 28 | 9 => 1, 29 | 12 => 1, 30 | 15 => 1, 31 | 17 => 1, 32 | 19 => 1, 33 | 21 => 1, 34 | 24 => 1, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Magento2/Tests/Classes/AbstractApiUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 31 | 23 => 1 32 | ]; 33 | } 34 | 35 | return []; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/TryProcessSystemResourcesUnitTest.inc: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | Magento\Catalog\Pricing\Price\RegularPrice 13 | 14 | 15 | 16 | 17 | 18 | 19 | scalar5 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Magento2/Tests/SQL/RawQueryUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 27 | 35 => 1, 28 | 44 => 1, 29 | 52 => 1, 30 | 59 => 1, 31 | 65 => 1, 32 | 80 => 1, 33 | 102 => 1, 34 | 106 => 1, 35 | 109 => 1, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Magento2Framework/Sniffs/Header/CopyrightValidation.php: -------------------------------------------------------------------------------- 1 | = 2010 && $year <= date("Y")) { 25 | return true; 26 | } else { 27 | return false; 28 | } 29 | } else { 30 | return false; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php: -------------------------------------------------------------------------------- 1 | 1, 20 | 7 => 1, 21 | 8 => 1, 22 | 9 => 1, 23 | 16 => 1, 24 | 17 => 1, 25 | 27 => 1, 26 | 31 => 1, 27 | ]; 28 | } 29 | 30 | /** 31 | * @inheritDoc 32 | */ 33 | protected function getWarningList() 34 | { 35 | return []; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteAclUnitTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | </children> 12 | <title value="bar"/> 13 | <children default_policy="deny"/> 14 | <acl> 15 | <children> 16 | <title value="foo"/> 17 | </children> 18 | <children default_policy="deny"/> 19 | <title value="bar"/> 20 | <title> 21 | <children default_policy="deny"/> 22 | 23 | 24 | 26 | </children> 27 | </acl> 28 | </config> 29 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteMenuUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ObsoleteMenuUnitTest 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(): array 24 | { 25 | return [ 26 | 17 => 1, 27 | 20 => 1, 28 | 23 => 1, 29 | 28 => 1, 30 | 31 => 1, 31 | 34 => 1, 32 | 39 => 1, 33 | 42 => 1, 34 | 45 => 1, 35 | 49 => 1 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.php: -------------------------------------------------------------------------------- 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 Magento2\Tests\Functions; 9 | 10 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 11 | 12 | /** 13 | * Test to validate PHP functions usage of which without passing arguments. 14 | */ 15 | class FunctionsDeprecatedWithoutArgumentUnitTest extends AbstractSniffUnitTest 16 | { 17 | /** 18 | * @inheritdoc 19 | */ 20 | public function getErrorList(): array 21 | { 22 | return []; 23 | } 24 | 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function getWarningList(): array 29 | { 30 | return [ 31 | 23 => 1, 32 | 25 => 1, 33 | 27 => 1 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/ThrowCatchUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | 7 | namespace Magento2\Tests\Exceptions; 8 | 9 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 10 | 11 | class ThrowCatchUnitTest extends AbstractSniffUnitTest 12 | { 13 | /** 14 | * @inheritdoc 15 | */ 16 | protected function getErrorList() 17 | { 18 | return []; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | protected function getWarningList($testFile = '') 25 | { 26 | 27 | if ($testFile === 'ThrowCatchUnitTest.1.inc') { 28 | return []; 29 | } 30 | 31 | return [ 32 | 41 => 1, 33 | 120 => 1, 34 | 126 => 1, 35 | 145 => 1, 36 | 156 => 1 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ClassReferencesInConfigurationFilesUnitTest.3.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0"?> 2 | <!-- 3 | /** 4 | * Copyright © Magento, Inc. All rights reserved. 5 | * See COPYING.txt for license details. 6 | */ 7 | --> 8 | <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"> 9 | <menu> 10 | <add id="Magento_CatalogRule::promo" title="Promotions" translate="title" module="Magento CatalogRule" parent="Magento_Backend::marketing" sortOrder="10" resource="Magento_CatalogRule::promo"/> 11 | <add id="Magento_CatalogRule::promo_catalog" title="Catalog Price Rule" translate="title" sortOrder="10" module="Magento_CatalogRule" parent="Magento_CatalogRule::promo" action="catalog_rule/promo_catalog/" dependsOnModule="Magento_Catalog" resource="Magento_CatalogRule::promo_catalog"/> 12 | </menu> 13 | </config> 14 | -------------------------------------------------------------------------------- /Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\GraphQL; 7 | 8 | /** 9 | * Covers {@link \Magento2\Sniffs\GraphQL\ValidFieldNameSniff}. 10 | */ 11 | class ValidFieldNameUnitTest extends AbstractGraphQLSniffUnitTestCase 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | protected function getErrorList() 17 | { 18 | return [ 19 | 10 => 1, 20 | 11 => 1, 21 | 12 => 1, 22 | 13 => 1, 23 | 14 => 1, 24 | 26 => 1, 25 | 27 => 1, 26 | 28 => 1, 27 | 29 => 1, 28 | 30 => 1, 29 | ]; 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | protected function getWarningList() 36 | { 37 | return []; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Less; 7 | 8 | use PHP_CodeSniffer\Config; 9 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 10 | 11 | /** 12 | * Implements an abstract base for unit tests that cover less sniffs. 13 | */ 14 | abstract class AbstractLessSniffUnitTestCase extends AbstractSniffUnitTest 15 | { 16 | /** 17 | * @inheritDoc 18 | */ 19 | protected function setUp(): void 20 | { 21 | parent::setUp(); 22 | 23 | $config = new Config(); 24 | $config->extensions = array_merge( 25 | $config->extensions, 26 | [ 27 | 'less' => 'CSS' 28 | ] 29 | ); 30 | 31 | $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Magento2/Tests/NamingConvention/ReservedWordsUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\NamingConvention; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ReservedWordsUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return [ 18 | 2 => 1, 19 | 4 => 1, 20 | 6 => 1, 21 | 8 => 1, 22 | 10 => 1, 23 | 12 => 1, 24 | 14 => 1, 25 | 16 => 1, 26 | 18 => 1, 27 | 20 => 1, 28 | 22 => 1, 29 | ]; 30 | } 31 | 32 | /** 33 | * @inheritdoc 34 | */ 35 | public function getWarningList() 36 | { 37 | return []; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Less/ColonSpacingUnitTest.less: -------------------------------------------------------------------------------- 1 | // /** 2 | // * Copyright © Magento, Inc. All rights reserved. 3 | // * See COPYING.txt for license details. 4 | // */ 5 | 6 | 7 | div#foo { 8 | blah:'abc'; 9 | } 10 | 11 | .my #foo .blah { 12 | some: 'stuff'; 13 | } 14 | 15 | .blah { 16 | foo :'jkl'; 17 | } 18 | 19 | .foo { 20 | bar: 21 | 'xyz'; 22 | } 23 | 24 | .right { 25 | way: 'good'; 26 | } 27 | 28 | a:active { 29 | color: #000; 30 | } 31 | 32 | @abs-action-button-as-link: { 33 | &:not(:focus) { 34 | box-shadow: none; 35 | } 36 | } 37 | 38 | .actions-toolbar { 39 | &:not(:first-child) { 40 | &:extend(.abs-add-clearfix all); 41 | > .secondary { 42 | .action { 43 | &.add { 44 | margin-top: @indent__l; 45 | } 46 | } 47 | float: left; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Magento2/Tests/Exceptions/DirectThrowUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Exceptions; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class DirectThrowUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | protected function getErrorList() 16 | { 17 | return []; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | protected function getWarningList($testFile = '') 24 | { 25 | if ($testFile === 'DirectThrowUnitTest.1.inc') { 26 | return [ 27 | 10 => 1, 28 | 17 => 1, 29 | ]; 30 | } elseif ($testFile === 'DirectThrowUnitTest.2.inc') { 31 | return [ 32 | 20 => 1 33 | ]; 34 | } 35 | return []; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlBindingUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | <!-- 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | --> 7 | 8 | <div data-bind="attr: test.value"></div> 9 | <p>Test</p> 10 | <span data-bind="html: testError()"></span> 11 | <div data-bind=" 12 | attr : tst, 13 | html: test.getSomething().value.error() 14 | "></div> 15 | <p data-bind="html: '<b>Some html</b>', attr: test"></p> 16 | <div data-bind="html: valueUnsanitizedHtml"></div> 17 | <div data-bind="attr: testhtml, html: valueUnsanitizedHtml()"></div> 18 | <p data-bind="other_html: bind, html: bind_stuff(1, 2)"></p> 19 | 20 | <div style="tst()"></div> 21 | <span html="testError()"></span> 22 | <div html=" 23 | test.getSomething().value.error(1) 24 | "></div> 25 | <p html="'<b>Some html</b>'"></p> 26 | <div html="valueUnsanitizedHtml"></div> 27 | <div html=" 28 | valueUnsanitizedHtml('test') 29 | "></div> 30 | <p html="bind_stuff()"></p> 31 | -------------------------------------------------------------------------------- /Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Directory separator shorthand, intended to make code more readable. 5 | */ 6 | define('DS', DIRECTORY_SEPARATOR); 7 | 8 | define('BP', dirname(__FILE__)); 9 | 10 | /** 11 | * @deprecated New implementation available 12 | * @see \Ascii\Asterisk 13 | */ 14 | define('ANSWER', '42'); 15 | 16 | class Profiler 17 | { 18 | const NESTING_SEPARATOR = '->'; 19 | 20 | /** 21 | * Unlike first const, this one is not self explanatory. 22 | */ 23 | const NUMBER_TWO = 2; 24 | 25 | /** 26 | * @deprecated Unable to identify the question, replaced 27 | * @see \ComputationalMatrix\Earth 28 | */ 29 | const COMPUTER = 'Deep Thought'; 30 | 31 | /** 32 | * @deprecated 33 | * @see \ComputationalMatrix\Mars 34 | */ 35 | const KEYBOARD = 'Ergonomic'; 36 | 37 | /** 38 | * @see 39 | */ 40 | const SOMETHING = 'else'; 41 | } 42 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/EmailTemplateUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | 7 | namespace Magento2\Tests\Legacy; 8 | 9 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 10 | 11 | class EmailTemplateUnitTest extends AbstractSniffUnitTest 12 | { 13 | /** 14 | * @inheritdoc 15 | */ 16 | public function getErrorList($testFile = '') 17 | { 18 | if ($testFile === 'EmailTemplateUnitTest.1.html') { 19 | return []; 20 | } 21 | if ($testFile === 'EmailTemplateUnitTest.2.html') { 22 | return [ 23 | 1 => 1, 24 | 2 => 1, 25 | 3 => 2, 26 | ]; 27 | } 28 | 29 | return []; 30 | } 31 | 32 | /** 33 | * @inheritdoc 34 | */ 35 | public function getWarningList($testFile = '') 36 | { 37 | return []; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/_files/PhtmlTemplateUnitTest/view/base/templates/PhtmlTemplateUnitTest.1.phtml: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | ?> 7 | <script type="text/x-magento-init"> 8 | </script> 9 | <script type="text/javascript"> 10 | </script> 11 | <div id="block-testing" 12 | class="block shipping" 13 | data-mage-init='{}' 14 | > 15 | <?php 16 | function _testing() 17 | { 18 | return true; 19 | } 20 | $_productCollection = $block->_getTestFunction(); 21 | $block->getTestFunction(); 22 | $_something = $this->something(); 23 | $block->_getTest(); 24 | $block = _testing(); 25 | ?> 26 | <?php 27 | $block->_getTestAnotherFunction(); 28 | ?> 29 | 30 | <?php $scriptString = <<<script 31 | require([ 32 | "jquery", 33 | "jquery/ui", 34 | ], function ($, Confirm) { 35 | }); 36 | script; 37 | $this->helper(); 38 | ?> 39 | <script type="jquery/ui"> 40 | </script> 41 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/ObsoleteSystemConfigurationUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ObsoleteSystemConfigurationUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList($testFile = '') 16 | { 17 | return []; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList($testFile = '') 24 | { 25 | if ($testFile === 'ObsoleteSystemConfigurationUnitTest.1.xml') { 26 | return [ 27 | 9 => 1, 28 | 10 => 1, 29 | ]; 30 | } 31 | if ($testFile === 'ObsoleteSystemConfigurationUnitTest.2.xml') { 32 | return []; 33 | } 34 | return []; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/_files/PhtmlTemplateUnitTest/view/adminhtml/templates/PhtmlTemplateUnitTest.3.phtml: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | ?> 7 | <script type="text/x-magento-init"> 8 | </script> 9 | <script type="text/javascript"> 10 | </script> 11 | <div id="block-testing" 12 | class="block shipping" 13 | data-mage-init='{}' 14 | > 15 | <?php 16 | function _testing() 17 | { 18 | return true; 19 | } 20 | $_productCollection = $block->_getTestFunction(); 21 | $block->getTestFunction(); 22 | $_something = $this->something(); 23 | $block->_getTest(); 24 | $block = _testing(); 25 | ?> 26 | <?php 27 | $block->_getTestAnotherFunction(); 28 | ?> 29 | 30 | <?php $scriptString = <<<script 31 | require([ 32 | "jquery", 33 | "jquery/ui", 34 | ], function ($, Confirm) { 35 | }); 36 | script; 37 | $this->helper(); 38 | ?> 39 | <script type="jquery/ui"> 40 | </script> 41 | -------------------------------------------------------------------------------- /Magento2/Tests/Legacy/_files/PhtmlTemplateUnitTest/view/frontend/templates/PhtmlTemplateUnitTest.2.phtml: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | ?> 7 | <script type="text/x-magento-init"> 8 | </script> 9 | <script type="text/javascript"> 10 | </script> 11 | <div id="block-testing" 12 | class="block shipping" 13 | data-mage-init='{}' 14 | > 15 | <?php 16 | function _testing() 17 | { 18 | return true; 19 | } 20 | $_productCollection = $block->_getTestFunction(); 21 | $block->getTestFunction(); 22 | $_something = $this->something(); 23 | $block->_getTest(); 24 | $block = _testing(); 25 | ?> 26 | <?php 27 | $block->_getTestAnotherFunction(); 28 | ?> 29 | 30 | <?php $scriptString = <<<script 31 | require([ 32 | "jquery", 33 | "jquery/ui", 34 | ], function ($, Confirm) { 35 | }); 36 | script; 37 | $this->helper(); 38 | ?> 39 | <script type="jquery/ui"> 40 | </script> 41 | -------------------------------------------------------------------------------- /Magento2/Tests/Security/IncludeFileUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Security; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class IncludeFileUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return [ 18 | 3 => 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 | <?php 2 | /************************************************************************ 3 | * 4 | * Copyright 2024 Adobe 5 | * All Rights Reserved. 6 | * 7 | * NOTICE: All information contained herein is, and remains 8 | * the property of Adobe and its suppliers, if any. The intellectual 9 | * and technical concepts contained herein are proprietary to Adobe 10 | * and its suppliers and are protected by all applicable intellectual 11 | * property laws, including trade secret and copyright laws. 12 | * Dissemination of this information or reproduction of this material 13 | * is strictly forbidden unless prior written permission is obtained 14 | * from Adobe. 15 | * ********************************************************************** 16 | */ 17 | 18 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 19 | ?> 20 | 21 | <div class="block test"> 22 | </div> 23 | <script type="jquery/ui"> 24 | </script> 25 | 26 | -------------------------------------------------------------------------------- /Magento2/Sniffs/PHP/GotoSniff.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright 2018 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\PHP; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Detects use of GOTO. 13 | */ 14 | class GotoSniff implements Sniff 15 | { 16 | /** 17 | * String representation of warning. 18 | * 19 | * @var string 20 | */ 21 | protected $errorMessage = 'Use of goto is discouraged.'; 22 | 23 | /** 24 | * Warning violation code. 25 | * 26 | * @var string 27 | */ 28 | protected $errorCode = 'FoundGoto'; 29 | 30 | /** 31 | * @inheritdoc 32 | */ 33 | public function register() 34 | { 35 | return [T_GOTO]; 36 | } 37 | 38 | /** 39 | * @inheritdoc 40 | */ 41 | public function process(File $phpcsFile, $stackPtr) 42 | { 43 | $phpcsFile->addError($this->errorMessage, $stackPtr, $this->errorCode); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Magento2/Sniffs/PHP/FinalImplementationSniff.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright 2019 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\PHP; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Magento is a highly extensible and customizable platform. The use of final classes and methods is prohibited. 13 | */ 14 | class FinalImplementationSniff implements Sniff 15 | { 16 | /** 17 | * @inheritdoc 18 | */ 19 | public function register() 20 | { 21 | return [T_FINAL]; 22 | } 23 | 24 | /** 25 | * @inheritdoc 26 | */ 27 | public function process(File $phpcsFile, $stackPtr) 28 | { 29 | $phpcsFile->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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * See COPYING.txt for license details. 5 | */ 6 | declare(strict_types=1); 7 | 8 | namespace Magento2\Rector\Tests\ReplaceNewDateTimeNull; 9 | 10 | use Iterator; 11 | use Rector\Testing\PHPUnit\AbstractRectorTestCase; 12 | use Symplify\SmartFileSystem\SmartFileInfo; 13 | 14 | class ReplaceNewDateTimeNullTest extends AbstractRectorTestCase 15 | { 16 | /** 17 | * @dataProvider provideData() 18 | */ 19 | public function test(string $fileInfo): void 20 | { 21 | $this->doTestFile($fileInfo); 22 | } 23 | 24 | /** 25 | * @return Iterator<SmartFileInfo> 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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * See COPYING.txt for license details. 5 | */ 6 | declare(strict_types=1); 7 | 8 | namespace Magento2\Rector\Tests\ReplacePregSplitNullLimit; 9 | 10 | use Iterator; 11 | use Rector\Testing\PHPUnit\AbstractRectorTestCase; 12 | use Symplify\SmartFileSystem\SmartFileInfo; 13 | 14 | class ReplacePregSplitNullLimitTest extends AbstractRectorTestCase 15 | { 16 | /** 17 | * @dataProvider provideData() 18 | */ 19 | public function test(string $fileInfo): void 20 | { 21 | $this->doTestFile($fileInfo); 22 | } 23 | 24 | /** 25 | * @return Iterator<SmartFileInfo> 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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | 7 | namespace Magento2\Tests\Security; 8 | 9 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 10 | 11 | class InsecureFunctionUnitTest extends AbstractSniffUnitTest 12 | { 13 | /** 14 | * @inheritdoc 15 | */ 16 | public function getErrorList() 17 | { 18 | return [ 19 | 3 => 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 | <?php 2 | 3 | // Incorrect arguments 4 | 5 | __(ClassName::CONSTANT); 6 | 7 | __(self::CONSTANT); 8 | 9 | __(\ClassNamespace\ClassName::CONSTANT); 10 | 11 | __( 12 | ClassName::CONSTANT 13 | ); 14 | 15 | Phrase(ClassName::CONSTANT); 16 | 17 | Phrase(self::CONSTANT); 18 | 19 | Phrase(\ClassNamespace\ClassName::CONSTANT); 20 | 21 | \Magento\Framework\Phrase(ClassName::CONSTANT); 22 | 23 | \Magento\Framework\Phrase( 24 | ClassName::CONSTANT 25 | ); 26 | 27 | // Correct arguments 28 | 29 | __($variable); 30 | 31 | __($variable[ClassName::CONSTANT]); 32 | 33 | __($variable[\ClassNamespace\ClassName::CONSTANT]); 34 | 35 | __($variable['value']); 36 | 37 | __( 38 | $variable 39 | ); 40 | 41 | Phrase($variable); 42 | 43 | Phrase($variable[ClassName::CONSTANT]); 44 | 45 | Phrase($variable[\ClassNamespace\ClassName::CONSTANT]); 46 | 47 | \Magento\Framework\Phrase($variable['value']); 48 | 49 | \Magento\Framework\Phrase( 50 | $variable[ClassName::CONSTANT] 51 | 52 | ); 53 | -------------------------------------------------------------------------------- /Magento2/Tests/CodeAnalysis/EmptyBlockUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\CodeAnalysis; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class EmptyBlockUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return [ 18 | 3 => 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 | <?php 2 | /** 3 | * Copyright © Magento. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class WidgetXMLUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList($testFile = '') 16 | { 17 | if ($testFile === 'WidgetXMLUnitTest.1.xml') { 18 | return [ 19 | 9 => 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 | <?php 2 | /** 3 | * Copyright 2018 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\PHP; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Detects possible usage of 'var' language construction. 13 | */ 14 | class VarSniff implements Sniff 15 | { 16 | /** 17 | * String representation of warning. 18 | * 19 | * @var string 20 | */ 21 | protected $warningMessage = 'Use of var class variables is discouraged.'; 22 | 23 | /** 24 | * Warning violation code. 25 | * 26 | * @var string 27 | */ 28 | protected $warningCode = 'FoundVar'; 29 | 30 | /** 31 | * @inheritdoc 32 | */ 33 | public function register() 34 | { 35 | return [T_VAR]; 36 | } 37 | 38 | /** 39 | * @inheritdoc 40 | */ 41 | public function process(File $phpcsFile, $stackPtr) 42 | { 43 | $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Magento2/Rector/Tests/AddArrayAccessInterfaceReturnTypes/AddArrayAccessInterfaceReturnTypesTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * See COPYING.txt for license details. 5 | */ 6 | declare(strict_types=1); 7 | 8 | namespace Magento2\Rector\Tests\AddArrayAccessInterfaceReturnTypes; 9 | 10 | use Iterator; 11 | use Rector\Testing\PHPUnit\AbstractRectorTestCase; 12 | use Symplify\SmartFileSystem\SmartFileInfo; 13 | 14 | class AddArrayAccessInterfaceReturnTypesTest extends AbstractRectorTestCase 15 | { 16 | /** 17 | * @dataProvider provideData() 18 | */ 19 | public function test(string $fileInfo): void 20 | { 21 | $this->doTestFile($fileInfo); 22 | } 23 | 24 | /** 25 | * @return Iterator<SmartFileInfo> 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 | <!-- 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | --> 7 | 8 | <html> 9 | <head> 10 | <base/> 11 | <link/> 12 | </head> 13 | <body> 14 | <area alt=""/> 15 | <br/> 16 | <table> 17 | <colgroup> 18 | <col/> 19 | </colgroup> 20 | </table> 21 | <embed/> 22 | <hr/> 23 | <img src="" alt=""/> 24 | <input type="text" id="test_input"/> 25 | <keygen/> 26 | <link/> 27 | <meta/> 28 | <param name="" value=""/> 29 | <video> 30 | <source/> 31 | <track src=""/> 32 | </video> 33 | <wbr/> 34 | 35 | <label for="test_input"/> 36 | <style type="text/css"/> 37 | <div/> 38 | <span/> 39 | <text/> 40 | <render/> 41 | <each/> 42 | <translate/> 43 | <scope/> 44 | </body> 45 | </html> 46 | -------------------------------------------------------------------------------- /Magento2/Tests/Security/XssTemplateUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Security; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class XssTemplateUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return []; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return [ 26 | 3 => 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 | <?php 2 | 3 | /** 4 | * Copyright © Magento, Inc. All rights reserved. 5 | * See COPYING.txt for license details. 6 | */ 7 | namespace Magento2\Tests\Commenting; 8 | 9 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 10 | 11 | class ClassAndInterfacePHPDocFormattingUnitTest extends AbstractSniffUnitTest 12 | { 13 | /** 14 | * @inheritdoc 15 | */ 16 | public function getErrorList() 17 | { 18 | return []; 19 | } 20 | 21 | /** 22 | * @inheritdoc 23 | */ 24 | public function getWarningList($testFile = '') 25 | { 26 | return [ 27 | 19 => 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 | <?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 Magento2\Tests\Functions; 9 | 10 | /** 11 | * Class to test validate PHP functions usage of which without passing arguments. 12 | */ 13 | class FunctionsDeprecatedWithoutArgument 14 | { 15 | /** 16 | * Test deprecation function. 17 | * 18 | * @return array 19 | */ 20 | public function testDeprecatedMethod(): array 21 | { 22 | return [ 23 | mb_check_encoding(), // Calling without argument is deprecated. 24 | mb_check_encoding('test-argument'), 25 | get_class(), // Calling without argument is deprecated. 26 | get_class(new FunctionsDeprecatedWithoutArgument()), 27 | get_parent_class(), // Calling without argument is deprecated. 28 | get_parent_class(new FunctionsDeprecatedWithoutArgument()) 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\GraphQL; 7 | 8 | /** 9 | * Covers {@link \Magento2\Sniffs\GraphQL\ValidArgumentNameSniff}. 10 | */ 11 | class ValidArgumentNameUnitTest extends AbstractGraphQLSniffUnitTestCase 12 | { 13 | /** 14 | * @inheritDoc 15 | */ 16 | protected function getErrorList() 17 | { 18 | return [ 19 | 11 => 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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Less; 7 | 8 | class AvoidIdUnitTest extends AbstractLessSniffUnitTestCase 9 | { 10 | /** 11 | * @inheritdoc 12 | */ 13 | public function getErrorList() 14 | { 15 | return [ 16 | 6 => 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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * See COPYING.txt for license details. 5 | */ 6 | declare(strict_types=1); 7 | 8 | namespace Magento2\Rector\Tests\ReplaceMbStrposNullLimit; 9 | 10 | use Iterator; 11 | use Rector\Testing\PHPUnit\AbstractRectorTestCase; 12 | use Symplify\SmartFileSystem\SmartFileInfo; 13 | 14 | class ReplaceMbStrposNullLimitTest extends AbstractRectorTestCase 15 | { 16 | /** 17 | * @dataProvider provideData() 18 | */ 19 | public function test(string $fileInfo): void 20 | { 21 | $this->doTestFile($fileInfo); 22 | } 23 | 24 | /** 25 | * @return Iterator<SmartFileInfo> 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 | <?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 Magento2\Tests\Functions; 9 | 10 | /** 11 | * Class to test validate PHP functions usage of which without passing arguments. 12 | */ 13 | class FunctionsDeprecatedWithoutArgument 14 | { 15 | /** 16 | * Test deprecation function. 17 | * 18 | * @return array 19 | */ 20 | public function testDeprecatedMethod(): array 21 | { 22 | return [ 23 | mb_check_encoding(), // Calling without argument is deprecated. 24 | mb_check_encoding('test-argument'), 25 | get_class($this), // Calling without argument is deprecated. 26 | get_class(new FunctionsDeprecatedWithoutArgument()), 27 | get_parent_class($this), // Calling without argument is deprecated. 28 | get_parent_class(new FunctionsDeprecatedWithoutArgument()) 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Commenting; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ClassPropertyPHPDocFormattingUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return []; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList() 24 | { 25 | return [ 26 | 13 => 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 | <?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 Magento2\Tests\GraphQL\AbstractGraphQLSniffUnitTestCase; 9 | 10 | class CopyrightGraphQLUnitTest extends AbstractGraphQLSniffUnitTestCase 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.graphqls' || 26 | $testFile === 'CopyrightGraphQLUnitTest.2.graphqls') { 27 | return []; 28 | } 29 | 30 | if ($testFile === 'CopyrightGraphQLUnitTest.3.graphqls' || 31 | $testFile === 'CopyrightGraphQLUnitTest.4.graphqls') { 32 | return [ 33 | null => 1 34 | ]; 35 | } 36 | 37 | return []; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Magento2/Tests/Eslint/AbstractEslintTestCase.php: -------------------------------------------------------------------------------- 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 Magento2\Tests\Eslint; 9 | 10 | use PHPUnit\Framework\TestCase; 11 | 12 | /** 13 | * Abstract class AbstractEslintTestCase 14 | * 15 | * Test Eslint Rules (magento-coding-standard/eslint/rules) 16 | */ 17 | abstract class AbstractEslintTestCase extends TestCase 18 | { 19 | /** 20 | * Assert that file contains a specific error. 21 | * 22 | * @param string $testFile 23 | * @param array $expectedMessages 24 | */ 25 | protected function assertFileContainsError(string $testFile, array $expectedMessages): void 26 | { 27 | // phpcs:disable 28 | exec( 29 | 'npm run eslint -- Magento2/Tests/Eslint/' . $testFile, 30 | $output 31 | ); 32 | 33 | foreach ($expectedMessages as $message) { 34 | $this->assertStringContainsString($message, implode(' ', $output)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Commenting; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ConstantsPHPDocFormattingUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return []; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList($testFile = '') 24 | { 25 | if ($testFile !== 'ConstantsPHPDocFormattingUnitTest.2.inc') { 26 | return []; 27 | } 28 | 29 | return [ 30 | 6 => 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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\GraphQL; 7 | 8 | use PHP_CodeSniffer\Config; 9 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 10 | 11 | /** 12 | * Implements an abstract base for unit tests that cover GraphQL sniffs. 13 | */ 14 | abstract class AbstractGraphQLSniffUnitTestCase extends AbstractSniffUnitTest 15 | { 16 | /** 17 | * @inheritDoc 18 | */ 19 | protected function setUp(): void 20 | { 21 | //let parent do its job 22 | parent::setUp(); 23 | 24 | //generate a config that allows ro use our GraphQL tokenizer 25 | $config = new Config(); 26 | $config->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 | <?php 2 | 3 | /** 4 | * Copyright © Magento, Inc. All rights reserved. 5 | * See COPYING.txt for license details. 6 | */ 7 | 8 | namespace Magento2\Tests\Legacy; 9 | 10 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 11 | 12 | class EscapeMethodsOnBlockClassUnitTest extends AbstractSniffUnitTest 13 | { 14 | protected function getErrorList() 15 | { 16 | return []; 17 | } 18 | 19 | protected function getWarningList() 20 | { 21 | return [ 22 | 19 => 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 | <?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 Magento2\Tests\Eslint; 9 | 10 | /** 11 | * Class MiscDeprecatedFunctionsTest 12 | * 13 | * Test Eslint Rule: jquery-no-misc-deprecated-functions.js 14 | */ 15 | class MiscDeprecatedFunctionsTest extends AbstractEslintTestCase 16 | { 17 | public function testExecute(): void 18 | { 19 | $this->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 | <?php 2 | 3 | $productTable = $this->_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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\PHP; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | /** 11 | * Class StringPositionUnitTest 12 | */ 13 | class ReturnValueCheckUnitTest extends AbstractSniffUnitTest 14 | { 15 | /** 16 | * @inheritdoc 17 | */ 18 | public function getErrorList() 19 | { 20 | return [ 21 | 4 => 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 | <?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 CopyrightUnitTest 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 === 'CopyrightUnitTest.4.inc' || $testFile === 'CopyrightUnitTest.5.inc') { 26 | return []; 27 | } 28 | 29 | if ($testFile === 'CopyrightUnitTest.1.inc') { 30 | return [ 31 | 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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ModuleXMLUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return []; 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function getWarningList($testFile = '') 24 | { 25 | if ($testFile === 'ModuleXMLUnitTest.1.xml') { 26 | return [ 27 | 9 => 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 | <?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 Magento2\Tests\PHP; 9 | 10 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 11 | 12 | class AutogeneratedClassNotInConstructorUnitTest extends AbstractSniffUnitTest 13 | { 14 | /** 15 | * @inheritdoc 16 | */ 17 | public function getErrorList($filename = '') 18 | { 19 | if ($filename === 'AutogeneratedClassNotInConstructorUnitTest.1.php.inc') { 20 | return [ 21 | 26 => 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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Less; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Class QuotesSniff 13 | * 14 | * Ensure that single quotes are used 15 | * 16 | * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#quotes 17 | */ 18 | class QuotesSniff implements Sniff 19 | { 20 | /** 21 | * A list of tokenizers this sniff supports. 22 | * 23 | * @var array 24 | */ 25 | public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function register() 31 | { 32 | return [T_CONSTANT_ENCAPSED_STRING]; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function process(File $phpcsFile, $stackPtr) 39 | { 40 | $tokens = $phpcsFile->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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Classes; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | /** 11 | * Class DiscouragedDependenciesUnitTest 12 | * 13 | * Tests for interceptors in constructors 14 | */ 15 | class DiscouragedDependenciesUnitTest extends AbstractSniffUnitTest 16 | { 17 | /** 18 | * @inheritdoc 19 | */ 20 | public function getErrorList($testFile = '') 21 | { 22 | if ($testFile === 'DiscouragedDependenciesUnitTest.1.inc') { 23 | return [ 24 | 17 => 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 | <?php 2 | /** 3 | * Copyright © Magento. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class LayoutUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList($testFile = '') 16 | { 17 | if ($testFile === 'LayoutUnitTest.1.xml') { 18 | return [ 19 | 13 => 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 | <?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 LicenseUnitTest 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 === 'LicenseUnitTest.1.inc' || $testFile === 'LicenseUnitTest.3.xml') { 26 | return []; 27 | } 28 | 29 | if ($testFile === 'LicenseUnitTest.2.inc') { 30 | return [ 31 | 3 => 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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy\_files\RestrictedCodeUnitTest\Magento\Framework\Model\ResourceModel; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | /** 11 | * This is NOT actually a test, but a file that must be ignored by RestrictedCodeSniff 12 | * when doing its analysis, even if it contains restricted classes. 13 | * We need this file to have the exact expected path, even with the PHP extension that makes AbstractSniffUnitTest 14 | * to recognize this as an actual test file instead of a fixture. 15 | */ 16 | class IteratorDummyFile extends AbstractSniffUnitTest 17 | { 18 | protected function shouldSkipTest(): bool 19 | { 20 | return true; 21 | } 22 | 23 | protected function getErrorList(): array 24 | { 25 | return []; 26 | } 27 | 28 | protected function getWarningList(): array 29 | { 30 | return []; 31 | } 32 | 33 | private function withProtectedClass(): Zend_Db_Expr 34 | { 35 | return new \Zend_Db_Expr(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Magento2/Tests/Performance/ForeachArrayMergeUnitTest.inc: -------------------------------------------------------------------------------- 1 | <?php 2 | $configurationSources = [ 3 | 0 => '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 | <?php 2 | /** 3 | * Copyright 2019 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\GraphQL; 7 | 8 | use PHP_CodeSniffer\Files\File; 9 | 10 | /** 11 | * Detects field names the are not specified in <kbd>snake_case</kbd>. 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 | <?php 2 | 3 | namespace Vendor\Module\Anyname; 4 | 5 | use \Vendor\Module\AnyName\Interceptor as InterAlias; 6 | use \Exception as SafeAlias; 7 | 8 | class Interceptor {} 9 | 10 | /** 11 | * // Rule find: constructor use of interceptor class 12 | */ 13 | class Foo 14 | { 15 | public function __construct( 16 | $first, 17 | \Vendor\Module\AnyName\Interceptor $anything, 18 | $interceptorOnlyInName, 19 | InterAliasMorethan $fine, // should not match 20 | $another = [] 21 | ) 22 | { 23 | 24 | } 25 | public function notAConstruct( 26 | \Vendor\Module\Anyname\Interceptor $anything 27 | ) 28 | { 29 | 30 | } 31 | } 32 | 33 | /** 34 | * // Rule find: constructor use of interceptor class with alias 35 | */ 36 | class Foo2 { 37 | public function __construct(InterAlias $anything, $aInterceptorInName) {} 38 | } 39 | 40 | /** 41 | * // Rule find: constructor use of interceptor class with use statement 42 | */ 43 | class Foo3 { 44 | public function __construct(Interceptor $anything) {} 45 | } 46 | 47 | /** 48 | * // Rule find: This is fine 49 | */ 50 | class Foo4 51 | { 52 | public function __construct(SafeAlias $other) { 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /Magento2/Tests/Classes/DiscouragedDependenciesUnitTest.2.inc: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace Vendor\Module\Anyname; 4 | 5 | use \Vendor\Module\AnyName\Proxy as ProxAlias; 6 | use \Exception as SafeAlias; 7 | 8 | class Proxy {} 9 | 10 | /** 11 | * // Rule find: constructor use of proxy class 12 | */ 13 | class Foo 14 | { 15 | public function __construct( 16 | $first, 17 | \Vendor\Module\AnyName\Proxy $anything, 18 | $proxyOnlyInName, 19 | ProxAliasNope $notAProblem, // should not match 20 | $another = [] 21 | ) 22 | { 23 | 24 | } 25 | public function notAConstruct( 26 | \Vendor\Module\Anyname\Proxy $anything 27 | ) 28 | { 29 | 30 | } 31 | } 32 | 33 | /** 34 | * // Rule find: constructor use of proxy class with alias 35 | */ 36 | class Foo2 { 37 | public function __construct(ProxAlias $anything, $aProxyInName) {} 38 | } 39 | 40 | /** 41 | * // Rule find: constructor use of proxy class with use statement 42 | */ 43 | class Foo3 { 44 | public function __construct(Proxy $anything, InterAlias $oldAliasInName) {} 45 | } 46 | 47 | /** 48 | * // Rule find: This is fine 49 | */ 50 | class Foo4 51 | { 52 | public function __construct(SafeAlias $other) { 53 | 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /Magento2/Tests/Html/HtmlCollapsibleAttributeUnitTest.1.inc: -------------------------------------------------------------------------------- 1 | <!-- 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | --> 7 | 8 | <html> 9 | <head> 10 | <base/> 11 | <link/> 12 | </head> 13 | <body> 14 | <div class="action-dropdown"> 15 | <button type="button" class="action-toggle" data-mage-init='{"dropdown":{}}' data-toggle="dropdown"> 16 | <span>Test</span> 17 | </button> 18 | </div> 19 | <div class="fieldset-wrapper-title"> 20 | <strong class="admin__collapsible-title" data-toggle="collapse" data-bind="attr:{'data-target': '#'+id}"> 21 | <span data-bind="text: title"></span> 22 | </strong> 23 | </div> 24 | <div class="admin__collapsible-title" 25 | data-toggle="collapse" 26 | data-target="#id-content"> 27 | <span>Test</span> 28 | </div> 29 | <strong <?= /* @noEscape */ $isCollapsable ? 30 | 'class="admin__collapsible-title" data-toggle="collapse" data-target="#' . $id . '-content"' : 31 | 'class="title"'; ?>> 32 | <span><?= $block->escapeHtml($element->getLegend()) ?></span> 33 | </strong> 34 | </body> 35 | </html> 36 | -------------------------------------------------------------------------------- /Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc: -------------------------------------------------------------------------------- 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 Magento2\Tests\PHP; 9 | 10 | use Magento\Catalog\Model\Product; 11 | use Magento\Eav\Api\AttributeRepositoryInterface; 12 | use Magento\Eav\Setup\AddOptionToAttribute; 13 | use Magento\Eav\Setup\EavSetup; 14 | use Magento\Eav\Setup\EavSetupFactory; 15 | use Magento\Framework\App\ObjectManager; 16 | use Magento\Framework\Setup\ModuleDataSetupInterface; 17 | 18 | class Bad 19 | { 20 | public function __construct() 21 | { 22 | $this->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 | <?xml version="1.0"?> 2 | <ruleset name="Magento2Framework"> 3 | <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 | 7 | <rule ref="Magento2" /> 8 | 9 | <rule ref="Magento2Framework.Header.License"> 10 | <severity>5</severity> 11 | <type>warning</type> 12 | </rule> 13 | <rule ref="Magento2Framework.Header.CopyrightAnotherExtensionsFiles"> 14 | <severity>5</severity> 15 | <type>warning</type> 16 | <exclude-pattern>*\.php$</exclude-pattern> 17 | <exclude-pattern>*\.phtml$</exclude-pattern> 18 | </rule> 19 | <rule ref="Magento2Framework.Header.Copyright"> 20 | <severity>5</severity> 21 | <type>warning</type> 22 | <include-pattern>*\.php$</include-pattern> 23 | <include-pattern>*\.phtml$</include-pattern> 24 | <exclude-pattern>*/PHPCSUtils/*</exclude-pattern> 25 | </rule> 26 | <rule ref="Magento2Framework.Header.CopyrightGraphQL"> 27 | <severity>5</severity> 28 | <type>warning</type> 29 | <include-pattern>*\.graphqls$</include-pattern> 30 | </rule> 31 | 32 | <rule ref="Internal.NoCodeFound"> 33 | <severity>0</severity> 34 | </rule> 35 | </ruleset> 36 | -------------------------------------------------------------------------------- /Magento2/Sniffs/Less/CombinatorIndentationSniff.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Less; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Class CombinatorIndentationSniff 13 | * 14 | * Ensure that spaces are used before and after combinators 15 | * 16 | * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#combinator-indents 17 | */ 18 | class CombinatorIndentationSniff implements Sniff 19 | { 20 | /** 21 | * A list of tokenizers this sniff supports. 22 | * 23 | * @var array 24 | */ 25 | public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function register() 31 | { 32 | return [T_PLUS]; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function process(File $phpcsFile, $stackPtr) 39 | { 40 | $tokens = $phpcsFile->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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Legacy; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class ClassReferencesInConfigurationFilesUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList($testFile = '') 16 | { 17 | if ($testFile === 'ClassReferencesInConfigurationFilesUnitTest.1.xml') { 18 | return [ 19 | 22 => 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 | <?php 2 | 3 | declare(strict_types=1); 4 | 5 | use Magento2\Rector\Src\ReplaceMbStrposNullLimit; 6 | use Magento2\Rector\Src\ReplaceNewDateTimeNull; 7 | use Rector\Config\RectorConfig; 8 | use Rector\ValueObject\PhpVersion; 9 | use Rector\Php80\Rector\Class_\StringableForToStringRector; 10 | use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector; 11 | use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector; 12 | use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector; 13 | use Rector\Php81\Rector\FuncCall\Php81ResourceReturnToObjectRector; 14 | use Magento2\Rector\Src\ReplacePregSplitNullLimit; 15 | 16 | return static function (RectorConfig $rectorConfig): void { 17 | $rectorConfig->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 | <?php 2 | 3 | /** 4 | * Nesting separator. 5 | */ 6 | define("NESTING_SEPARATOR", '->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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Less; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Class PropertiesLineBreakSniff 13 | * 14 | * Start each property declaration in a new line 15 | * 16 | * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#properties-line-break 17 | */ 18 | class PropertiesLineBreakSniff implements Sniff 19 | { 20 | /** 21 | * A list of tokenizers this sniff supports. 22 | * 23 | * @var array 24 | */ 25 | public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function register() 31 | { 32 | return [T_SEMICOLON]; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function process(File $phpcsFile, $stackPtr) 39 | { 40 | $tokens = $phpcsFile->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 | <?php 2 | /** 3 | * Copyright 2019 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Security; 7 | 8 | use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff; 9 | 10 | /** 11 | * Detects the use of insecure functions. 12 | */ 13 | class InsecureFunctionSniff extends ForbiddenFunctionsSniff 14 | { 15 | /** 16 | * List of patterns for forbidden functions. 17 | * 18 | * @var array 19 | */ 20 | public $forbiddenFunctions = [ 21 | 'assert' => 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 | <?php 2 | /************************************************************************ 3 | * 4 | * Copyright 2024 Adobe 5 | * All Rights Reserved. 6 | * 7 | * NOTICE: All information contained herein is, and remains 8 | * the property of Adobe and its suppliers, if any. The intellectual 9 | * and technical concepts contained herein are proprietary to Adobe 10 | * and its suppliers and are protected by all applicable intellectual 11 | * property laws, including trade secret and copyright laws. 12 | * Dissemination of this information or reproduction of this material 13 | * is strictly forbidden unless prior written permission is obtained 14 | * from Adobe. 15 | * ********************************************************************** 16 | */ 17 | declare(strict_types = 1); 18 | 19 | namespace Magento2\Tests\Templates; 20 | 21 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 22 | 23 | class ObjectManagerUnitTest extends AbstractSniffUnitTest 24 | { 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function getWarningList($filename = '') 29 | { 30 | if ($filename === 'ObjectManagerUnitTest.1.phtml.inc') { 31 | return [ 32 | 18 => 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 | <?xml version="1.0"?> 2 | <!-- 3 | /** 4 | * Copyright © Magento, Inc. All rights reserved. 5 | * See COPYING.txt for license details. 6 | */ 7 | --> 8 | <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 9 | <body> 10 | <referenceContainer name="checkout.onepage.review.info.items.after"> 11 | <block class="Magento\Paypal\Block\Iframe" name="paypal.iframe" cacheable="false"/> 12 | </referenceContainer> 13 | <referenceBlock name="checkout.onepage.review.button"> 14 | <action method="setTemplate"> 15 | <argument name="template" xsi:type="helper" helper="Magento\Paypal\Helper\Hss"> 16 | <param name="name">Magento_Paypal::hss/review/button.phtml</param> 17 | </argument> 18 | <argument name="template" xsi:type="helper" helper="Magento/Paypal/Helper/Hss::getReviewButtonTemplate"> 19 | <param name="name">Magento_Paypal::hss/review/button.phtml</param> 20 | </argument> 21 | <argument name="template" xsi:type="helper" helper="Magento\Paypal\Helper\Hss::getReviewButtonTemplate"> 22 | <param name="name">Magento_Paypal::hss/review/button.phtml</param> 23 | </argument> 24 | </action> 25 | </referenceBlock> 26 | </body> 27 | </page> 28 | -------------------------------------------------------------------------------- /Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 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 | use CopyrightValidation; 16 | private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat'; 17 | 18 | private const FILE_EXTENSION = 'graphqls'; 19 | 20 | /** 21 | * @var string[] 22 | */ 23 | public $supportedTokenizers = ['GRAPHQL']; 24 | 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function register() 29 | { 30 | return [T_OPEN_TAG]; 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | public function process(File $phpcsFile, $stackPtr) 37 | { 38 | if ($phpcsFile->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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Less; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Class ImportantPropertySniff 13 | * 14 | * Ensure that single quotes are used 15 | * 16 | * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#important-property 17 | */ 18 | class ImportantPropertySniff implements Sniff 19 | { 20 | /** 21 | * A list of tokenizers this sniff supports. 22 | * 23 | * @var array 24 | */ 25 | public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function register() 31 | { 32 | return [T_BOOLEAN_NOT]; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function process(File $phpcsFile, $stackPtr) 39 | { 40 | $tokens = $phpcsFile->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 | <?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 Magento2\Tests\PHP; 9 | 10 | use Magento2\OneModel as Model; 11 | 12 | class Good 13 | { 14 | public function __construct( 15 | ModelFactory $model = null 16 | ) 17 | { 18 | $this->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 | <?php 2 | /** 3 | * Copyright 2018 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Templates; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Detects possible usage of $this variable files. 13 | */ 14 | class ThisInTemplateSniff implements Sniff 15 | { 16 | private const MESSAGE_THIS = 'The use of $this in templates is deprecated. Use $block instead.'; 17 | private const MESSAGE_HELPER = 'The use of helpers in templates is discouraged. Use ViewModel instead.'; 18 | 19 | /** 20 | * @inheritdoc 21 | */ 22 | public function register() 23 | { 24 | return [T_VARIABLE]; 25 | } 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function process(File $phpcsFile, $stackPtr) 31 | { 32 | if ($phpcsFile->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 | <?php 2 | /** 3 | * This is the summary for a DocBlock. 4 | * 5 | * This is the description for a DocBlock. This text may contain 6 | * multiple lines and even some _markdown_. 7 | * * Markdown style lists function too 8 | * * Just try this out once 9 | * The section after the description contains the tags; which provide 10 | * structured meta-data concerning the given element. 11 | * 12 | * @param int $example This is an example function/method parameter description. 13 | * @param string $example2 This is a second example. 14 | * 15 | */ 16 | public function getProductListDefaultSortBy2($example, $example2) 17 | { 18 | return $example === $example2; 19 | } 20 | 21 | public function setExtensionAs(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) 22 | { 23 | return $this->_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 | <?php 2 | /** 3 | * Copyright © Magento, Inc. All rights reserved. 4 | * See COPYING.txt for license details. 5 | */ 6 | namespace Magento2\Tests\Annotation; 7 | 8 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; 9 | 10 | class MethodAnnotationStructureUnitTest extends AbstractSniffUnitTest 11 | { 12 | /** 13 | * @inheritdoc 14 | */ 15 | public function getErrorList() 16 | { 17 | return [ 18 | 2 => 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 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 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 CopyrightAnotherExtensionsFilesSniff implements Sniff 14 | { 15 | use CopyrightValidation; 16 | private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat'; 17 | 18 | /** 19 | * Defines the tokenizers that this sniff is using. 20 | * 21 | * @var array 22 | */ 23 | public $supportedTokenizers = ['CSS', 'PHP', 'JS']; 24 | 25 | /** 26 | * @inheritDoc 27 | */ 28 | public function register(): array 29 | { 30 | return [ 31 | T_INLINE_HTML, 32 | T_OPEN_TAG 33 | ]; 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | public function process(File $phpcsFile, $stackPtr) 40 | { 41 | if ($stackPtr > 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(<helper_class>)` 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 | <?php $_incl = $this->helper(<helper_class>)->...; ?> 31 | ``` 32 | 33 | Once the ViewModel is created, call it in the PHTML as follow: 34 | 35 | ```html 36 | <?php $viewModel = $block->getViewModel(); ?> 37 | ``` 38 | or 39 | ```html 40 | <?php $viewModel = $block->getData('viewModel'); ?> 41 | ``` 42 | -------------------------------------------------------------------------------- /Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Copyright 2021 Adobe 4 | * All Rights Reserved. 5 | */ 6 | namespace Magento2\Sniffs\Less; 7 | 8 | use PHP_CodeSniffer\Sniffs\Sniff; 9 | use PHP_CodeSniffer\Files\File; 10 | 11 | /** 12 | * Class TypeSelectorConcatenation 13 | * 14 | * Ensure that selector in one line, concatenation is not used 15 | * 16 | * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#formatting-1 17 | */ 18 | class TypeSelectorConcatenationSniff implements Sniff 19 | { 20 | /** 21 | * A list of tokenizers this sniff supports. 22 | * 23 | * @var array 24 | */ 25 | public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; 26 | 27 | /** 28 | * @var array 29 | */ 30 | private $symbolsBeforeConcat = [ 31 | TokenizerSymbolsInterface::INDENT_SPACES, 32 | TokenizerSymbolsInterface::NEW_LINE, 33 | ]; 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function register() 39 | { 40 | return [T_BITWISE_AND]; 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function process(File $phpcsFile, $stackPtr) 47 | { 48 | $tokens = $phpcsFile->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 | --------------------------------------------------------------------------------