mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix references, add helpful comments
This commit is contained in:
parent
b2c777e3eb
commit
4531681a24
@ -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…
Reference in New Issue
Block a user