芝麻web文件管理V1.00
编辑当前文件:/home/sditechnicalteam/public_html/vendor/nunomaduro/larastan/src/Rules/NoModelMakeRule.php
*/ class NoModelMakeRule implements Rule { /** * @var \PHPStan\Reflection\ReflectionProvider */ protected $reflectionProvider; /** * @param ReflectionProvider $reflectionProvider */ public function __construct(ReflectionProvider $reflectionProvider) { $this->reflectionProvider = $reflectionProvider; } /** * @return string */ public function getNodeType(): string { return StaticCall::class; } /** * @param Node $node * @param Scope $scope * @return array
*/ public function processNode(Node $node, Scope $scope): array { /** @var StaticCall $node due to @see getNodeType() */ $name = $node->name; if (! $name instanceof Identifier) { return []; } if ($name->name !== 'make') { return []; } if (! $this->isCalledOnModel($node, $scope)) { return []; } return [ RuleErrorBuilder::message("Called 'Model::make()' which performs unnecessary work, use 'new Model()'.") ->identifier('rules.noModelMake') ->line($node->getLine()) ->file($scope->getFile()) ->build(), ]; } /** * Was the expression called on a Model instance? * * @param StaticCall $call * @param Scope $scope * @return bool */ protected function isCalledOnModel(StaticCall $call, Scope $scope): bool { $class = $call->class; if ($class instanceof FullyQualified) { $type = new ObjectType($class->toString()); } elseif ($class instanceof Expr) { $exprType = $scope->getType($class); if (! $exprType instanceof ConstantStringType) { return false; } if (! $exprType->isClassString()) { return false; } $type = new ObjectType($exprType->getValue()); } else { // TODO can we handle relative names, do they even occur here? return false; } return (new ObjectType(Model::class)) ->isSuperTypeOf($type) ->yes(); } }