|
11 | 11 |
|
12 | 12 | class LaravelRequestDocs
|
13 | 13 | {
|
14 |
| - public function getDocs() |
| 14 | + public function getDocs(): array |
15 | 15 | {
|
16 | 16 | $docs = [];
|
17 | 17 | $excludePatterns = config('request-docs.hide_matching') ?? [];
|
@@ -68,20 +68,22 @@ public function getControllersInfo(): array
|
68 | 68 | $routes = collect(Route::getRoutes());
|
69 | 69 | $onlyRouteStartWith = config('request-docs.only_route_uri_start_with') ?? '';
|
70 | 70 |
|
| 71 | + /** @var \Illuminate\Routing\Route $route */ |
71 | 72 | foreach ($routes as $route) {
|
72 | 73 | if ($onlyRouteStartWith && !Str::startsWith($route->uri, $onlyRouteStartWith)) {
|
73 | 74 | continue;
|
74 | 75 | }
|
75 | 76 |
|
76 | 77 | try {
|
77 | 78 | $actionControllerName = $route->action['controller'] ?? $route->action["0"];
|
78 |
| - /// Show Pnly Controller Name |
| 79 | + /// Show Only Controller Name |
79 | 80 | $controllerFullPath = explode('@', $actionControllerName)[0];
|
80 | 81 | $getStartWord = strrpos(explode('@', $actionControllerName)[0], '\\') + 1;
|
81 | 82 | $controllerName = substr($controllerFullPath, $getStartWord);
|
82 | 83 |
|
83 | 84 | $method = explode('@', $actionControllerName)[1] ?? '__invoke';
|
84 | 85 | $httpMethod = $route->methods[0];
|
| 86 | + |
85 | 87 | foreach ($controllersInfo as $controllerInfo) {
|
86 | 88 | if ($controllerInfo['uri'] == $route->uri && $controllerInfo['httpMethod'] == $httpMethod) {
|
87 | 89 | // is duplicate
|
@@ -113,16 +115,17 @@ public function getControllersInfo(): array
|
113 | 115 | return $controllersInfo;
|
114 | 116 | }
|
115 | 117 |
|
116 |
| - public function appendRequestRules(array $controllersInfo) |
| 118 | + public function appendRequestRules(array $controllersInfo): array |
117 | 119 | {
|
118 | 120 | foreach ($controllersInfo as $index => $controllerInfo) {
|
119 | 121 | $controller = $controllerInfo['controller_full_path'];
|
120 | 122 | $method = $controllerInfo['method'];
|
121 | 123 | try {
|
122 | 124 | $reflectionMethod = new ReflectionMethod($controller, $method);
|
123 | 125 | } catch (Throwable $e) {
|
| 126 | + // Skip to next if controller is not exists. |
124 | 127 | if (config('request-docs.debug')) {
|
125 |
| - throw $e; |
| 128 | + throw $e; // @codeCoverageIgnore |
126 | 129 | }
|
127 | 130 | continue;
|
128 | 131 | }
|
@@ -187,16 +190,6 @@ public function lrdDocComment($docComment): string
|
187 | 190 | return $lrdComment;
|
188 | 191 | }
|
189 | 192 |
|
190 |
| - // get text between first and last tag |
191 |
| - private function getTextBetweenTags($docComment, $tag1, $tag2) |
192 |
| - { |
193 |
| - $docComment = trim($docComment); |
194 |
| - $start = strpos($docComment, $tag1); |
195 |
| - $end = strpos($docComment, $tag2); |
196 |
| - $text = substr($docComment, $start + strlen($tag1), $end - $start - strlen($tag1)); |
197 |
| - return $text; |
198 |
| - } |
199 |
| - |
200 | 193 | public function flattenRules($mixedRules)
|
201 | 194 | {
|
202 | 195 | $rules = [];
|
|
0 commit comments