Skip to content

Commit bdc9b09

Browse files
committed
fix doc block extends
1 parent 61e74cf commit bdc9b09

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

php-templates/models.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,30 @@ protected function collectExistingProperties($reflection)
119119
return collect();
120120
}
121121

122+
protected function getParentClass(\ReflectionClass $reflection)
123+
{
124+
if (!$reflection->getParentClass()) {
125+
return null;
126+
}
127+
128+
$parent = $reflection->getParentClass()->getName();
129+
130+
if ($parent === \Illuminate\Database\Eloquent\Model::class) {
131+
return null;
132+
}
133+
134+
return \Illuminate\Support\Str::start($parent, '\\');
135+
}
136+
122137
protected function getInfo($className)
123138
{
124139
if (($data = $this->fromArtisan($className)) === null) {
125140
return null;
126141
}
127142

128-
$reflection = (new \ReflectionClass($className));
143+
$reflection = new \ReflectionClass($className);
144+
145+
$data["extends"] = $this->getParentClass($reflection);
129146

130147
$existingProperties = $this->collectExistingProperties($reflection);
131148

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ declare namespace Eloquent {
8282
events: Event[];
8383
observers: Observer[];
8484
scopes: string[];
85+
extends: string | null;
8586
}
8687

8788
interface Attribute {

src/support/docblocks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface ClassBlock {
88
namespace: string;
99
className: string;
1010
blocks: string[];
11+
extends: string | null;
1112
}
1213

1314
const modelBuilderType = (className: string) =>
@@ -29,6 +30,7 @@ export const writeEloquentDocBlocks = (
2930
namespace: pathParts.join("\\"),
3031
className: cls || "",
3132
blocks: getBlocks(model, cls || "", builderMethods),
33+
extends: model.extends || null,
3234
};
3335
});
3436

@@ -181,7 +183,9 @@ const classToDocBlock = (block: ClassBlock, namespace: string) => {
181183
...block.blocks,
182184
" * @mixin \\Illuminate\\Database\\Query\\Builder",
183185
" */",
184-
`class ${block.className} extends \\Illuminate\\Database\\Eloquent\\Model`,
186+
`class ${block.className} extends ${
187+
block.extends ?? "\\Illuminate\\Database\\Eloquent\\Model"
188+
}`,
185189
`{`,
186190
indent("//"),
187191
`}`,

src/templates/models.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,30 @@ $models = new class($factory) {
119119
return collect();
120120
}
121121
122+
protected function getParentClass(\\ReflectionClass $reflection)
123+
{
124+
if (!$reflection->getParentClass()) {
125+
return null;
126+
}
127+
128+
$parent = $reflection->getParentClass()->getName();
129+
130+
if ($parent === \\Illuminate\\Database\\Eloquent\\Model::class) {
131+
return null;
132+
}
133+
134+
return \\Illuminate\\Support\\Str::start($parent, '\\\\');
135+
}
136+
122137
protected function getInfo($className)
123138
{
124139
if (($data = $this->fromArtisan($className)) === null) {
125140
return null;
126141
}
127142
128-
$reflection = (new \\ReflectionClass($className));
143+
$reflection = new \\ReflectionClass($className);
144+
145+
$data["extends"] = $this->getParentClass($reflection);
129146
130147
$existingProperties = $this->collectExistingProperties($reflection);
131148

0 commit comments

Comments
 (0)