diff --git a/.travis.yml b/.travis.yml index 0de98557..ea3eb825 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,11 @@ php: - 7.1 - 7.2 - 7.3 -install: composer install --no-interaction --prefer-source + - 7.4 +cache: + directories: + - $HOME/.composer/cache/files +install: composer install --no-interaction --prefer-dist script: - vendor/bin/phpunit - vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php new file mode 100644 index 00000000..94bfc2d5 --- /dev/null +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -0,0 +1,79 @@ +getTokens(); + $endOfStatement = $phpcsFile->findEndOfStatement($stackPtr); + $resourcePosition = $phpcsFile->findNext( + T_STRING, + $stackPtr + 1, + $endOfStatement, + false, + self::RESOURCE_METHOD + ); + if ($resourcePosition !== false) { + $methodPosition = $phpcsFile->findNext([T_STRING, T_VARIABLE], $resourcePosition + 1, $endOfStatement); + if ($methodPosition !== false && in_array($tokens[$methodPosition]['content'], $this->methods, true)) { + $phpcsFile->addWarning( + sprintf($this->warningMessage, $tokens[$methodPosition]['content']), + $stackPtr, + $this->warningCode + ); + } + } + } +} diff --git a/Magento2/Sniffs/Security/InsecureFunctionSniff.php b/Magento2/Sniffs/Security/InsecureFunctionSniff.php index 16c69030..b5253193 100644 --- a/Magento2/Sniffs/Security/InsecureFunctionSniff.php +++ b/Magento2/Sniffs/Security/InsecureFunctionSniff.php @@ -20,7 +20,7 @@ class InsecureFunctionSniff extends ForbiddenFunctionsSniff public $forbiddenFunctions = [ 'assert' => null, 'create_function' => null, - 'exec' => null, + 'exec' => '\Magento\Framework\Shell::execute', 'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)', 'passthru' => null, 'pcntl_exec' => null, diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc new file mode 100644 index 00000000..38e7a817 --- /dev/null +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc @@ -0,0 +1,13 @@ +getResource()->save($model); + +$model->getResource()->load($model, $id); + +$model->getResource()->delete($model); + +$model->getResource()->myCustomMethod(); + +$model->myCustomMethod(); + +$model->anotherMethodWithResource()->save($model); diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php new file mode 100644 index 00000000..43d88dd3 --- /dev/null +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php @@ -0,0 +1,31 @@ + 1, + 5 => 1, + 7 => 1, + ]; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 96188ad7..0a0bed7b 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -215,6 +215,10 @@ 8 warning + + 8 + warning + diff --git a/composer.json b/composer.json index 2c9a1844..a700503a 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "version": "5", "require": { "php": ">=5.6.0", - "squizlabs/php_codesniffer": "^3.4", + "squizlabs/php_codesniffer": "^3.5", "webonyx/graphql-php": ">=0.12.6 <1.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 34b78adc..8a7111b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "de90fd51a20a688a7385615a0fd7d86e", + "content-hash": "45be18e23c6041ce36bc5d0ffb9c85d6", "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "3.4.2", + "version": "3.5.6", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e97627871a7eab2f70e59166072a6b767d5834e0", + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0", "shasum": "" }, "require": { @@ -55,7 +55,7 @@ "phpcs", "standards" ], - "time": "2019-04-10T23:49:02+00:00" + "time": "2020-08-10T04:50:15+00:00" }, { "name": "webonyx/graphql-php", @@ -659,6 +659,7 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2017-12-04T08:55:13+00:00" }, { @@ -1492,5 +1493,6 @@ "platform": { "php": ">=5.6.0" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" }