13
13
class LaravelRequestDocs
14
14
{
15
15
/**
16
+ * Get a collection of {@see \Rakutentech\LaravelRequestDocs\Doc} with route and rules information.
17
+ *
16
18
* @param bool $showGet
17
19
* @param bool $showPost
18
20
* @param bool $showPut
@@ -49,7 +51,7 @@ public function getDocs(
49
51
}
50
52
51
53
/**
52
- * Split {@see \Rakutentech\LaravelRequestDocs\Doc} by {@see \Rakutentech\LaravelRequestDocs\Doc::$methods}
54
+ * Loop and split {@see \Rakutentech\LaravelRequestDocs\Doc} by {@see \Rakutentech\LaravelRequestDocs\Doc::$methods}.
53
55
*
54
56
* @param \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc> $docs
55
57
* @return \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc>
@@ -72,6 +74,8 @@ public function splitByMethods(Collection $docs): Collection
72
74
}
73
75
74
76
/**
77
+ * Sort by `$sortBy`.
78
+ *
75
79
* @param \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc> $docs
76
80
* @param string|null $sortBy
77
81
* @return \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc>
@@ -104,6 +108,9 @@ public function sortDocs(Collection $docs, ?string $sortBy = 'default'): Collect
104
108
}
105
109
106
110
/**
111
+ * Group by `$groupBy`. {@see \Rakutentech\LaravelRequestDocs\Doc::$group} and {@see \Rakutentech\LaravelRequestDocs\Doc::$groupIndex} will be set.
112
+ * The return collection is always sorted by `group`, `group_index`.
113
+ *
107
114
* @param \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc> $docs
108
115
* @return \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc>
109
116
*/
@@ -129,6 +136,8 @@ public function groupDocs(Collection $docs, ?string $groupBy = 'default'): Colle
129
136
}
130
137
131
138
/**
139
+ * Get controllers and routes information and return a list of {@see \Rakutentech\LaravelRequestDocs\Doc}
140
+ *
132
141
* @param string[] $onlyMethods
133
142
* @return \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc>
134
143
* @throws \ReflectionException
@@ -191,6 +200,9 @@ public function getControllersInfo(array $onlyMethods): Collection
191
200
}
192
201
193
202
/**
203
+ * Parse from request object and set into {@see \Rakutentech\LaravelRequestDocs\Doc}
204
+ * This method also read docBlock and update into {@see \Rakutentech\LaravelRequestDocs\Doc}.
205
+ *
194
206
* @param \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc> $docs
195
207
* @return \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc>
196
208
* @throws \ReflectionException
@@ -245,6 +257,12 @@ public function appendRequestRules(Collection $docs): Collection
245
257
return $ docs ;
246
258
}
247
259
260
+ /**
261
+ * Get description in between @lrd:start and @lrd:end from the doc block.
262
+ *
263
+ * @param string $docComment
264
+ * @return string
265
+ */
248
266
public function lrdDocComment (string $ docComment ): string
249
267
{
250
268
$ lrdComment = "" ;
@@ -267,8 +285,10 @@ public function lrdDocComment(string $docComment): string
267
285
}
268
286
269
287
/**
288
+ * Parse rules from the request.
289
+ *
270
290
* @param array<string, \Illuminate\Contracts\Validation\Rule|array|string> $mixedRules
271
- * @return array<string, string[]>
291
+ * @return array<string, string[]> Key is attribute, value is a list of rules.
272
292
*/
273
293
public function flattenRules (array $ mixedRules ): array
274
294
{
@@ -300,7 +320,9 @@ public function flattenRules(array $mixedRules): array
300
320
}
301
321
302
322
/**
303
- * @return array<string, string[]>
323
+ * Read the source file and parse rules by regex.
324
+ *
325
+ * @return array<string, string[]> Key is attribute, value is a list of rules.
304
326
* @throws \ReflectionException
305
327
*/
306
328
public function rulesByRegex (string $ requestClassName , string $ methodName ): array
@@ -341,6 +363,8 @@ public function rulesByRegex(string $requestClassName, string $methodName): arra
341
363
}
342
364
343
365
/**
366
+ * Get additional rules by parsing the doc block.
367
+ *
344
368
* @param string $docComment
345
369
* @return array<string, string[]>
346
370
*/
@@ -366,8 +390,10 @@ private function customParamsDocComment(string $docComment): array
366
390
}
367
391
368
392
/**
393
+ * Get responses by parsing the doc block.
394
+ *
369
395
* @param string $docComment
370
- * @return string[]
396
+ * @return string[] A list of responses. Will overwrite the default responses.
371
397
*/
372
398
private function customResponsesDocComment (string $ docComment ): array
373
399
{
@@ -402,7 +428,7 @@ private function multiExplode(array $delimiters, string $string): array
402
428
}
403
429
404
430
/**
405
- * Parse the `$docs[' uri']` and attach ` group` and `group_index` details.
431
+ * Group by {@see \Rakutentech\LaravelRequestDocs\Doc::$ uri} and attach {@see \Rakutentech\LaravelRequestDocs\Doc::$ group} and {@see \Rakutentech\LaravelRequestDocs\Doc::$groupIndex} details.
406
432
*
407
433
* @param \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc> $docs
408
434
*/
@@ -431,7 +457,7 @@ private function groupDocsByAPIURI(Collection $docs): void
431
457
}
432
458
433
459
/**
434
- * Create and return group name by the ` $uri` .
460
+ * Create and return group name by the {@see \Rakutentech\LaravelRequestDocs\Doc:: $uri} .
435
461
*/
436
462
private function getGroupByURI (string $ prefix , string $ uri ): string
437
463
{
@@ -448,7 +474,7 @@ private function getGroupByURI(string $prefix, string $uri): string
448
474
}
449
475
450
476
/**
451
- * Parse the `$docs['controller_full_path']` and attach ` group` and `group_index` details.
477
+ * Group by {@see \Rakutentech\LaravelRequestDocs\Doc::$controllerFullPath} and attach {@see \Rakutentech\LaravelRequestDocs\Doc::$ group} and {@see \Rakutentech\LaravelRequestDocs\Doc::$groupIndex} details.
452
478
*
453
479
* @param \Illuminate\Support\Collection<int, \Rakutentech\LaravelRequestDocs\Doc> $docs
454
480
*/
0 commit comments