OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
45
.phpstan/Rules/FacadeRule.php
Normal file
45
.phpstan/Rules/FacadeRule.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Leanstan\Rules;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Rules\Rule;
|
||||
|
||||
class FacadeRule implements Rule
|
||||
{
|
||||
private const ALLOWED_FACADES = ['Cache', 'Log', 'parent', 'self'];
|
||||
|
||||
public function getNodeType(): string
|
||||
{
|
||||
return StaticCall::class;
|
||||
}
|
||||
|
||||
public function processNode(Node $node, Scope $scope): array
|
||||
{
|
||||
if (!$node instanceof StaticCall) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!$node->class instanceof \PhpParser\Node\Name) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$className = $node->class->toString();
|
||||
|
||||
// Check if it's likely a facade
|
||||
$parts = $node->class->getParts();
|
||||
if (strpos($className, 'Illuminate\\Support\\Facades\\') === 0 || count($parts) === 1) {
|
||||
$facadeName = count($parts) === 1 ? $parts[0] : end($parts);
|
||||
|
||||
if (!in_array($facadeName, self::ALLOWED_FACADES)) {
|
||||
return [
|
||||
"Only Cache:: and Log:: facades are allowed. Consider using dependency injection or helpers instead of {$facadeName}::."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user