Skip to content

Commit ee72865

Browse files
committed
ACP2E-1919: Implement sniff that reports usage of dynamic properties as deprecated
1 parent 17510c1 commit ee72865

12 files changed

+700
-20
lines changed

Magento2/Internal/Cache.php

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento2\Internal;
8+
9+
use PHP_CodeSniffer\Files\File;
10+
11+
/**
12+
* Wrapper for \PHPCSUtils\Internal\Cache
13+
*
14+
* @see \PHPCSUtils\Internal\Cache
15+
* @internal
16+
*/
17+
final class Cache
18+
{
19+
/**
20+
* Wrapper for \PHPCSUtils\Internal\Cache::isCached() method.
21+
*
22+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
23+
* @param string $key
24+
* @param int|string $id
25+
*
26+
* @return bool
27+
* @see \PHPCSUtils\Internal\Cache::isCached()
28+
*/
29+
public static function isCached(File $phpcsFile, $key, $id)
30+
{
31+
return \PHPCSUtils\Internal\Cache::isCached($phpcsFile, $key, $id);
32+
}
33+
34+
/**
35+
* Wrapper for \PHPCSUtils\Internal\Cache::get() method.
36+
*
37+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
38+
* @param string $key
39+
* @param int|string $id
40+
*
41+
* @return mixed
42+
* @see \PHPCSUtils\Internal\Cache::get()
43+
*/
44+
public static function get(File $phpcsFile, $key, $id)
45+
{
46+
return \PHPCSUtils\Internal\Cache::get($phpcsFile, $key, $id);
47+
}
48+
49+
/**
50+
* Wrapper for \PHPCSUtils\Internal\Cache::getForFile() method.
51+
*
52+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
53+
* @param string $key
54+
* @return array
55+
* @see \PHPCSUtils\Internal\Cache::getForFile()
56+
*/
57+
public static function getForFile(File $phpcsFile, $key)
58+
{
59+
return \PHPCSUtils\Internal\Cache::getForFile($phpcsFile, $key);
60+
}
61+
62+
/**
63+
* Wrapper for \PHPCSUtils\Internal\Cache::set() method.
64+
*
65+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
66+
* @param string $key
67+
* @param int|string $id
68+
* @param mixed $value
69+
* @return void
70+
* @see \PHPCSUtils\Internal\Cache::set()
71+
*/
72+
public static function set(File $phpcsFile, $key, $id, $value)
73+
{
74+
\PHPCSUtils\Internal\Cache::set($phpcsFile, $key, $id, $value);
75+
}
76+
77+
/**
78+
* Wrapper for \PHPCSUtils\Internal\Cache::clear() method.
79+
*
80+
* @return void
81+
* @see \PHPCSUtils\Internal\Cache::clear()
82+
*/
83+
public static function clear()
84+
{
85+
\PHPCSUtils\Internal\Cache::clear();
86+
}
87+
}

Magento2/Rector/Src/ReplacePregSplitNullLimit.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
namespace Magento2\Rector\Src;
99

1010
use PhpParser\Node;
11+
use PhpParser\Node\Expr\ConstFetch;
1112
use PhpParser\Node\Expr\FuncCall;
12-
use PhpParser\Node\Scalar\LNumber;
1313
use Rector\Core\Rector\AbstractRector;
1414
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1515
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -29,11 +29,12 @@ public function getNodeTypes(): array
2929
*/
3030
public function refactor(Node $node): ?Node
3131
{
32-
if (!$this->isName($node->name, 'preg_split')) {
32+
if (!$this->isName($node->name, 'preg_split') || !isset($node->args[2])) {
3333
return null;
3434
}
35+
$value = $node->args[2]->value;
3536

36-
if ($node->args[2] !== LNumber::class) {
37+
if ($value instanceof ConstFetch && $value->name->toString() === 'null') {
3738
$node->args[2] = $this->nodeFactory->createArg(-1);
3839
return $node;
3940
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?php
22

3-
preg_split('pattern', 'subject', null, 0)
3+
preg_split('pattern', 'subject', null, 0);
4+
preg_split('pattern', 'subject', 2);
5+
preg_split('pattern', 'subject', $var);
6+
preg_split('pattern', 'subject');
47

58
?>
69
-----
710
<?php
811

9-
preg_split('pattern', 'subject', -1, 0)
12+
preg_split('pattern', 'subject', -1, 0);
13+
preg_split('pattern', 'subject', 2);
14+
preg_split('pattern', 'subject', $var);
15+
preg_split('pattern', 'subject');
1016

1117
?>

0 commit comments

Comments
 (0)