Skip to content

Commit 5b82e31

Browse files
authored
Merge branch 'develop' into ticket-162
2 parents 76f5f2d + ea0eb81 commit 5b82e31

8 files changed

+143
-10
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ php:
55
- 7.1
66
- 7.2
77
- 7.3
8-
install: composer install --no-interaction --prefer-source
8+
- 7.4
9+
cache:
10+
directories:
11+
- $HOME/.composer/cache/files
12+
install: composer install --no-interaction --prefer-dist
913
script:
1014
- vendor/bin/phpunit
1115
- vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Sniffs\Methods;
7+
8+
use PHP_CodeSniffer\Sniffs\Sniff;
9+
use PHP_CodeSniffer\Files\File;
10+
11+
/**
12+
* Detects possible use of deprecated model methods.
13+
*/
14+
class DeprecatedModelMethodSniff implements Sniff
15+
{
16+
const RESOURCE_METHOD = "getResource";
17+
18+
/**
19+
* String representation of warning.
20+
*
21+
* @var string
22+
*/
23+
protected $warningMessage = "The use of the deprecated method 'getResource()' to '%s' the data detected.";
24+
25+
/**
26+
* Warning violation code.
27+
*
28+
* @var string
29+
*/
30+
protected $warningCode = 'FoundDeprecatedModelMethod';
31+
32+
/**
33+
* List of deprecated method.
34+
*
35+
* @var array
36+
*/
37+
protected $methods = [
38+
'save',
39+
'load',
40+
'delete'
41+
];
42+
43+
protected $severity = 0;
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function register()
49+
{
50+
return [
51+
T_OBJECT_OPERATOR
52+
];
53+
}
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function process(File $phpcsFile, $stackPtr)
58+
{
59+
$tokens = $phpcsFile->getTokens();
60+
$endOfStatement = $phpcsFile->findEndOfStatement($stackPtr);
61+
$resourcePosition = $phpcsFile->findNext(
62+
T_STRING,
63+
$stackPtr + 1,
64+
$endOfStatement,
65+
false,
66+
self::RESOURCE_METHOD
67+
);
68+
if ($resourcePosition !== false) {
69+
$methodPosition = $phpcsFile->findNext([T_STRING, T_VARIABLE], $resourcePosition + 1, $endOfStatement);
70+
if ($methodPosition !== false && in_array($tokens[$methodPosition]['content'], $this->methods, true)) {
71+
$phpcsFile->addWarning(
72+
sprintf($this->warningMessage, $tokens[$methodPosition]['content']),
73+
$stackPtr,
74+
$this->warningCode
75+
);
76+
}
77+
}
78+
}
79+
}

Magento2/Sniffs/Security/InsecureFunctionSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class InsecureFunctionSniff extends ForbiddenFunctionsSniff
2020
public $forbiddenFunctions = [
2121
'assert' => null,
2222
'create_function' => null,
23-
'exec' => null,
23+
'exec' => '\Magento\Framework\Shell::execute',
2424
'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)',
2525
'passthru' => null,
2626
'pcntl_exec' => null,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$model->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);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Methods;
7+
8+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
9+
10+
class DeprecatedModelMethodUnitTest 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 => 1,
27+
5 => 1,
28+
7 => 1,
29+
];
30+
}
31+
}

Magento2/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
<severity>8</severity>
216216
<type>warning</type>
217217
</rule>
218+
<rule ref="Magento2.Methods.DeprecatedModelMethod">
219+
<severity>8</severity>
220+
<type>warning</type>
221+
</rule>
218222

219223
<!-- Severity 7 warnings: General code issues. -->
220224
<rule ref="Generic.Arrays.DisallowLongArraySyntax">

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": "5",
1010
"require": {
1111
"php": ">=5.6.0",
12-
"squizlabs/php_codesniffer": "^3.4",
12+
"squizlabs/php_codesniffer": "^3.5",
1313
"webonyx/graphql-php": ">=0.12.6 <1.0"
1414
},
1515
"require-dev": {

composer.lock

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)