-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66fdf01
commit 0745fbd
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
rules: | ||
- PHPStan\Rules\Playground\FunctionNeverRule | ||
- PHPStan\Rules\Playground\MethodNeverRule | ||
- PHPStan\Rules\Playground\NoPhpCodeRule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Playground; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\FileNode; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use function count; | ||
|
||
/** | ||
* @implements Rule<FileNode> | ||
*/ | ||
class NoPhpCodeRule implements Rule | ||
{ | ||
|
||
public function getNodeType(): string | ||
{ | ||
return FileNode::class; | ||
} | ||
|
||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
if (count($node->getNodes()) !== 1) { | ||
return []; | ||
} | ||
|
||
$html = $node->getNodes()[0]; | ||
if (!$html instanceof Node\Stmt\InlineHTML) { | ||
return []; | ||
} | ||
|
||
return [ | ||
RuleErrorBuilder::message('The example does not contain any PHP code. Did you forget the opening <?php tag?') | ||
->identifier('phpstanPlayground.noPhp') | ||
->build(), | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Playground; | ||
|
||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<NoPhpCodeRule> | ||
*/ | ||
class NoPhpCodeRuleTest extends RuleTestCase | ||
{ | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return new NoPhpCodeRule(); | ||
} | ||
|
||
public function testEmptyFile(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/empty.php'], []); | ||
} | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/no-php-code.php'], [ | ||
[ | ||
'The example does not contain any PHP code. Did you forget the opening <?php tag?', | ||
1, | ||
], | ||
]); | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Foo | ||
{ | ||
private int $foo; | ||
} |