diff --git a/Extdn/ruleset.xml b/Extdn/ruleset.xml index 7b937f2..9490b4b 100644 --- a/Extdn/ruleset.xml +++ b/Extdn/ruleset.xml @@ -3,6 +3,9 @@ Magento 2 Additional Rules by ExtDN + + *.php + diff --git a/MEQP2/Sniffs/Templates/ThisInTemplateSniff.md b/MEQP2/Sniffs/Templates/ThisInTemplateSniff.md new file mode 100644 index 0000000..c214a72 --- /dev/null +++ b/MEQP2/Sniffs/Templates/ThisInTemplateSniff.md @@ -0,0 +1,13 @@ +# Rule: Do not use `$this` in templates +## Background +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. + +## Reasoning +`$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. + +## How it works +Any occurence of `$this` in PHTML files (via file pattern in ruleset.xml) raises a warning. + +## How to fix + +Replace `$this` with `$block`. If you use private or protected methods, make them public. \ No newline at end of file diff --git a/README.md b/README.md index c6f296b..71f7ffd 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ As an example, you can use the `SetTemplateInBlockSniff` within the folder `Extd To run the sniff unit tests from a main repository, where the rules are installed via composer, first configure phpcs to find the rules: - vendor/bin/phpcs --config-set installed_paths vendor/extdn/phpcs/Extdn + vendor/bin/phpcs --config-set installed_paths vendor/extdn/phpcs/Extdn,vendor/magento/marketplace-eqp/MEQP2 Then tests can be run like this: diff --git a/composer.json b/composer.json index db65216..c5a1ce3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ ], "require": { "php": ">=7.1.0", - "squizlabs/php_codesniffer": "3.*" + "squizlabs/php_codesniffer": "3.*", + "magento/marketplace-eqp": "dev-master" }, "autoload": { "psr-4": { @@ -31,5 +32,11 @@ "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths ../../..", "post-update-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths ../../..", "test": "vendor/bin/phpunit" + }, + "repositories": { + "meqp": { + "type": "vcs", + "url": "git@github.com:magento/marketplace-eqp.git" + } } }