From 2443aa4f10fee1265f562f54f271241d7e286beb Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Thu, 19 Sep 2024 16:17:27 +0800 Subject: [PATCH] Added `ModelUpdateVisitor::getReturnType` method (#7077) --- CHANGELOG-3.1.md | 1 + src/database/src/Commands/Ast/ModelUpdateVisitor.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md index 284896cfe..383191167 100644 --- a/CHANGELOG-3.1.md +++ b/CHANGELOG-3.1.md @@ -4,6 +4,7 @@ - [#7059](https://github.com/hyperf/hyperf/pull/7059) Added `Hyperf\Database\Schema\Schema::getForeignKeys()`. - [#7064](https://github.com/hyperf/hyperf/pull/7064) Support db type `enum` for `DoctrineConnection`. +- [#7077](https://github.com/hyperf/hyperf/pull/7077) Added `ModelUpdateVisitor::getReturnType` method. # v3.1.40 - 2024-09-12 diff --git a/src/database/src/Commands/Ast/ModelUpdateVisitor.php b/src/database/src/Commands/Ast/ModelUpdateVisitor.php index 3b6f5fbf5..d75347195 100644 --- a/src/database/src/Commands/Ast/ModelUpdateVisitor.php +++ b/src/database/src/Commands/Ast/ModelUpdateVisitor.php @@ -259,7 +259,7 @@ class ModelUpdateVisitor extends NodeVisitorAbstract // Magic getAttribute $name = Str::snake(substr($method->getName(), 3, -9)); if (! empty($name)) { - $type = PhpDocReader::getInstance()->getReturnType($method, true); + $type = $this->getReturnType($method, true); $this->setProperty($name, $type, true, false, '', false, 1); } continue; @@ -438,4 +438,9 @@ class ModelUpdateVisitor extends NodeVisitorAbstract $model = new $className(); return '\\' . get_class($model->newCollection()); } + + protected function getReturnType(ReflectionMethod $method, bool $withoutNamespace = false): array + { + return PhpDocReader::getInstance()->getReturnType($method, $withoutNamespace); + } }