Skip to content

Commit 441d24f

Browse files
committed
完善
1 parent 3514cd7 commit 441d24f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/ModelGenerator.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function getPropertiesFromTable()
168168

169169
if (in_array($name, [$properties['createTime'], $properties['updateTime']])) {
170170
if (false !== strpos($dateFormat, '\\')) {
171-
$type = "\\" . $dateFormat;
171+
$type = $dateFormat;
172172
} else {
173173
$type = 'string';
174174
}
@@ -188,7 +188,7 @@ protected function getPropertiesFromTable()
188188
$format = !empty($param) ? $param : $dateFormat;
189189

190190
if (false !== strpos($format, '\\')) {
191-
$type = "\\" . $format;
191+
$type = $format;
192192
} else {
193193
$type = 'string';
194194
}
@@ -199,10 +199,6 @@ protected function getPropertiesFromTable()
199199
case 'serialize':
200200
$type = 'mixed';
201201
break;
202-
default:
203-
if (false !== strpos($type, '\\')) {
204-
$type = "\\" . $type;
205-
}
206202
}
207203
} else {
208204
if (!preg_match('/^([\w]+)(\(([\d]+)*(,([\d]+))*\))*(.+)*$/', $field['type'], $matches)) {
@@ -311,19 +307,19 @@ protected function getPropertiesFromMethods()
311307

312308
$name = Str::snake($methodName);
313309
if ($return instanceof HasOne || $return instanceof BelongsTo || $return instanceof MorphOne || $return instanceof HasOneThrough) {
314-
$this->addProperty($name, "\\" . get_class($return->getModel()), true, null);
310+
$this->addProperty($name, get_class($return->getModel()), true, null);
315311
}
316312

317313
if ($return instanceof HasMany || $return instanceof HasManyThrough || $return instanceof BelongsToMany) {
318-
$this->addProperty($name, "\\" . get_class($return->getModel()) . "[]", true, null);
314+
$this->addProperty($name, get_class($return->getModel()) . "[]", true, null);
319315
}
320316

321317
if ($return instanceof MorphTo || $return instanceof MorphMany) {
322318
$this->addProperty($name, "mixed", true, null);
323319
}
324320

325321
if ($return instanceof MorphToMany) {
326-
$this->addProperty($name, "\\" . Collection::class, true, null);
322+
$this->addProperty($name, Collection::class, true, null);
327323
}
328324
}
329325
} catch (Exception $e) {
@@ -402,7 +398,7 @@ protected function createPhpDocs()
402398

403399
$tagLine = trim("@{$attr} {$property['type']} \${$name} {$property['comment']}");
404400

405-
$tags[] = $tagFactory->create($tagLine, $context);
401+
$tags[] = $tagFactory->create($tagLine);
406402
}
407403

408404
foreach ($this->methods as $name => $method) {
@@ -412,7 +408,7 @@ protected function createPhpDocs()
412408

413409
$arguments = implode(', ', $method['arguments']);
414410

415-
$tags[] = $tagFactory->create("@method {$method['static']} {$method['return']} {$name}({$arguments})", $context);
411+
$tags[] = $tagFactory->create("@method {$method['static']} {$method['return']} {$name}({$arguments})");
416412
}
417413

418414
$tags = $this->sortTags($tags);
@@ -472,7 +468,7 @@ protected function getParameters($method)
472468
/** @var ReflectionParameter $param */
473469
foreach ($method->getParameters() as $param) {
474470
$paramClass = $param->getClass();
475-
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
471+
$paramStr = (!is_null($paramClass) ? $paramClass->getName() . ' ' : '') . '$' . $param->getName();
476472
$params[] = $paramStr;
477473
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
478474
$default = $param->getDefaultValue();
@@ -503,7 +499,7 @@ protected function getReturnTypeFromDocBlock(ReflectionMethod $reflection)
503499
$returnTag = $phpdoc->getTagsByName('return')[0];
504500
$type = $returnTag->getType();
505501
if ($type instanceof This || $type instanceof Static_ || $type instanceof Self_) {
506-
$type = "\\" . $reflection->getDeclaringClass()->getName();
502+
$type = $reflection->getDeclaringClass()->getName();
507503
}
508504
}
509505
} catch (InvalidArgumentException $e) {

0 commit comments

Comments
 (0)