Files
panel-pelican-dev/app/PHPStan/ForbiddenGlobalFunctionsRule.php

40 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2024-10-19 17:22:03 -04:00
<?php
namespace App\PHPStan;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
2025-09-24 13:34:19 +02:00
use PhpParser\Node\Name;
2024-10-19 17:22:03 -04:00
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
2024-10-19 17:22:03 -04:00
class ForbiddenGlobalFunctionsRule implements Rule
{
/** @var string[] */
public const FORBIDDEN_FUNCTIONS = ['app', 'resolve'];
2024-10-19 17:22:03 -04:00
public function getNodeType(): string
{
return FuncCall::class;
}
public function processNode(Node $node, Scope $scope): array
{
/** @var FuncCall $node */
if ($node->name instanceof Name) {
2024-10-19 17:22:03 -04:00
$functionName = (string) $node->name;
if (in_array($functionName, self::FORBIDDEN_FUNCTIONS, true)) {
2024-10-19 17:22:03 -04:00
return [
RuleErrorBuilder::message(sprintf(
'Usage of global function "%s" is forbidden.',
$functionName,
))->identifier('myCustomRules.forbiddenGlobalFunctions')->build(),
2024-10-19 17:22:03 -04:00
];
}
}
return [];
}
}