@@ -9,8 +9,9 @@ interface ClassBlock {
9
9
blocks : string [ ] ;
10
10
}
11
11
12
- // TODO: Chunk into several files if we have a lot of models?
13
- // TODO: Check if doc block is already in model file, skip if it is
12
+ const modelBuilderType = ( className : string ) =>
13
+ `\\Illuminate\\Database\\Eloquent\\Builder<${ className } >|${ className } ` ;
14
+
14
15
export const writeEloquentDocBlocks = (
15
16
models : Eloquent . Models ,
16
17
builderMethods : Eloquent . BuilderMethod [ ] ,
@@ -77,25 +78,27 @@ const getBuilderReturnType = (
77
78
}
78
79
79
80
if ( [ "static" , "self" ] . includes ( method . return ) ) {
80
- return `\\Illuminate\\Database\\Eloquent\\Builder< ${ className } >| ${ className } ` ;
81
+ return modelBuilderType ( className ) ;
81
82
}
82
83
83
- const certainOfType = [ "sole" , "find" , "first" , "firstOrFail" ] . includes ( method . name ) ;
84
+ const returnsSingleModel = [
85
+ "sole" ,
86
+ "find" ,
87
+ "first" ,
88
+ "firstOrFail" ,
89
+ ] . includes ( method . name ) ;
84
90
85
91
const returnType = method . return
86
- . replace (
87
- "$this" ,
88
- `\\Illuminate\\Database\\Eloquent\\Builder<${ className } >|${ className } ` ,
89
- )
92
+ . replace ( "$this" , modelBuilderType ( className ) )
90
93
. replace ( "\\TReturn" , "mixed" )
91
94
. replace ( "TReturn" , "mixed" )
92
- . replace ( "\\TValue" , certainOfType ? className : "mixed" )
93
- . replace ( "TValue" , certainOfType ? className : "mixed" )
94
- . replace ( "object" , certainOfType ? className : "mixed" ) ;
95
-
95
+ . replace ( "\\TValue" , returnsSingleModel ? className : "mixed" )
96
+ . replace ( "TValue" , returnsSingleModel ? className : "mixed" )
97
+ . replace ( "object" , returnsSingleModel ? className : "mixed" ) ;
98
+
96
99
if ( returnType . includes ( "mixed" ) ) {
97
100
return "mixed" ;
98
- } ;
101
+ }
99
102
100
103
return returnType ;
101
104
} ;
@@ -110,7 +113,7 @@ const getBlocks = (
110
113
. concat (
111
114
[ ...model . scopes , "newModelQuery" , "newQuery" , "query" ] . map (
112
115
( method ) => {
113
- return `@method static \\Illuminate\\Database\\Eloquent\\Builder< ${ className } >| ${ className } ${ method } ()` ;
116
+ return `@method static ${ modelBuilderType ( className ) } ${ method } ()` ;
114
117
} ,
115
118
) ,
116
119
)
@@ -202,7 +205,7 @@ const getAttributeBlocks = (
202
205
203
206
if ( ! [ "accessor" , "attribute" ] . includes ( attr . cast || "" ) ) {
204
207
blocks . push (
205
- `@method static \\Illuminate\\Database\\Eloquent\\Builder< ${ className } >| ${ className } where${ attr . title_case } ($value)` ,
208
+ `@method static ${ modelBuilderType ( className ) } where${ attr . title_case } ($value)` ,
206
209
) ;
207
210
}
208
211
0 commit comments