mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Merge pull request #14 from nickyr/patch-1
Fix references, add helpful comments to StringChecker example
This commit is contained in:
commit
d998003e02
@ -1,31 +1,36 @@
|
||||
<?php
|
||||
namespace Psalm\Example\Plugin;
|
||||
|
||||
use PhpParser;
|
||||
use Psalm\Checker;
|
||||
use Psalm\Context;
|
||||
use Psalm\CodeLocation;
|
||||
|
||||
/**
|
||||
* Checks all strings to see if they contain references to classes
|
||||
* and, if so, checks that those classes exist
|
||||
* and, if so, checks that those classes exist.
|
||||
*
|
||||
* You will need to add `"nikic/PHP-Parser": ">=3.0.2"` to your
|
||||
* composer.json.
|
||||
*/
|
||||
class StringChecker extends \Psalm\Plugin
|
||||
{
|
||||
/**
|
||||
* checks an expression
|
||||
* @param PhpParser\Node\Expr $stmt
|
||||
* @param Context $context
|
||||
* @param CodeLocation $file_name
|
||||
* @param array<string> $suppressed_issues
|
||||
* Checks an expression
|
||||
*
|
||||
* @param \PhpParser\Node\Expr $stmt
|
||||
* @param Context $context
|
||||
* @param CodeLocation $code_location
|
||||
* @param array<string> $suppressed_issues
|
||||
* @return null|false
|
||||
*/
|
||||
public function checkExpression(
|
||||
PhpParser\Node\Expr $stmt,
|
||||
\PhpParser\Node\Expr $stmt,
|
||||
Context $context,
|
||||
CodeLocation $code_location,
|
||||
array $suppressed_issues
|
||||
) {
|
||||
if ($stmt instanceof \PhpParser\Node\Scalar\String_) {
|
||||
// Replace "Psalm" with your namespace
|
||||
$class_or_class_method = '/^\\\?Psalm(\\\[A-Z][A-Za-z0-9]+)+(::[A-Za-z0-9]+)?$/';
|
||||
|
||||
if (preg_match($class_or_class_method, $stmt->value)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user