File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
src/Rules/DisallowedConstructs
tests/Rules/DisallowedConstructs Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 2828* Check LSP even for static methods
2929* Check missing typehint in anonymous function when a native one could be added
3030* Require calling parent constructor
31+ * Disallow usage of backtick operator (`` $ls = `ls -la` `` )
3132
3233Additional rules are coming in subsequent releases!
3334
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Rules \DisallowedConstructs ;
4+
5+ use PhpParser \Node ;
6+ use PHPStan \Analyser \Scope ;
7+
8+ class DisallowedBacktickRule implements \PHPStan \Rules \Rule
9+ {
10+
11+ public function getNodeType (): string
12+ {
13+ return \PhpParser \Node \Expr \ShellExec::class;
14+ }
15+
16+ /**
17+ * @param \PhpParser\Node\Expr\Empty_ $node
18+ * @param \PHPStan\Analyser\Scope $scope
19+ * @return string[]
20+ */
21+ public function processNode (Node $ node , Scope $ scope ): array
22+ {
23+ return [
24+ 'Backtick operator is not allowed. Use shell_exec() instead. ' ,
25+ ];
26+ }
27+
28+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Rules \DisallowedConstructs ;
4+
5+ use PHPStan \Rules \Rule ;
6+
7+ class DisallowedBacktickRuleTest extends \PHPStan \Testing \RuleTestCase
8+ {
9+
10+ protected function getRule (): Rule
11+ {
12+ return new DisallowedBacktickRule ();
13+ }
14+
15+ public function testRule (): void
16+ {
17+ $ this ->analyse ([__DIR__ . '/data/backtick.php ' ], [
18+ [
19+ 'Backtick operator is not allowed. Use shell_exec() instead. ' ,
20+ 3 ,
21+ ],
22+ ]);
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ ls = `ls -la `;
You can’t perform that action at this time.
0 commit comments