@@ -57,9 +57,9 @@ public function processRoute(Route $route, array $rulesToApply = [])
5757 $ controller = new ReflectionClass ($ class );
5858 $ method = $ controller ->getMethod ($ method );
5959
60- list ($ routeGroupName , $ routeGroupDescription ) = $ this ->getRouteGroup ($ controller , $ method );
6160
6261 $ docBlock = $ this ->parseDocBlock ($ method );
62+ list ($ routeGroupName , $ routeGroupDescription , $ routeTitle ) = $ this ->getRouteGroup ($ controller , $ docBlock );
6363 $ bodyParameters = $ this ->getBodyParameters ($ method , $ docBlock ['tags ' ]);
6464 $ queryParameters = $ this ->getQueryParameters ($ method , $ docBlock ['tags ' ]);
6565 $ content = ResponseResolver::getResponse ($ route , $ docBlock ['tags ' ], [
@@ -72,7 +72,7 @@ public function processRoute(Route $route, array $rulesToApply = [])
7272 'id ' => md5 ($ this ->getUri ($ route ).': ' .implode ($ this ->getMethods ($ route ))),
7373 'groupName ' => $ routeGroupName ,
7474 'groupDescription ' => $ routeGroupDescription ,
75- 'title ' => $ docBlock ['short ' ],
75+ 'title ' => $ routeTitle ?: $ docBlock ['short ' ],
7676 'description ' => $ docBlock ['long ' ],
7777 'methods ' => $ this ->getMethods ($ route ),
7878 'uri ' => $ this ->getUri ($ route ),
@@ -271,24 +271,40 @@ protected function parseDocBlock(ReflectionMethod $method)
271271
272272 /**
273273 * @param ReflectionClass $controller
274- * @param ReflectionMethod $method
274+ * @param array $methodDocBlock
275275 *
276- * @return array The route group name and description
276+ * @return array The route group name, the group description, ad the route title
277277 */
278- protected function getRouteGroup (ReflectionClass $ controller , ReflectionMethod $ method )
278+ protected function getRouteGroup (ReflectionClass $ controller , array $ methodDocBlock )
279279 {
280280 // @group tag on the method overrides that on the controller
281- $ docBlockComment = $ method ->getDocComment ();
282- if ($ docBlockComment ) {
283- $ phpdoc = new DocBlock ($ docBlockComment );
284- foreach ($ phpdoc ->getTags () as $ tag ) {
281+ if (!empty ($ methodDocBlock ['tags ' ])) {
282+ foreach ($ methodDocBlock ['tags ' ] as $ tag ) {
285283 if ($ tag ->getName () === 'group ' ) {
286- $ routeGroup = trim ($ tag ->getContent ());
287- $ routeGroupParts = explode ("\n" , $ tag ->getContent ());
284+ $ routeGroupParts = explode ("\n" , trim ($ tag ->getContent ()));
288285 $ routeGroupName = array_shift ($ routeGroupParts );
289- $ routeGroupDescription = implode ("\n" , $ routeGroupParts );
290-
291- return [$ routeGroupName , $ routeGroupDescription ];
286+ $ routeGroupDescription = trim (implode ("\n" , $ routeGroupParts ));
287+
288+ // If the route has no title (aka "short"),
289+ // we'll assume the routeGroupDescription is actually the title
290+ // Something like this:
291+ // /**
292+ // * Fetch cars. <-- This is route title.
293+ // * @group Cars <-- This is group name.
294+ // * APIs for cars. <-- This is group description (not required).
295+ // **/
296+ // VS
297+ // /**
298+ // * @group Cars <-- This is group name.
299+ // * Fetch cars. <-- This is route title, NOT group description.
300+ // **/
301+
302+ // BTW, this is a spaghetti way of doing this.
303+ // It shall be refactored soon. Deus vult!💪
304+ if (empty ($ methodDocBlock ['short ' ])) {
305+ return [$ routeGroupName , '' , $ routeGroupDescription ];
306+ }
307+ return [$ routeGroupName , $ routeGroupDescription , $ methodDocBlock ['short ' ]];
292308 }
293309 }
294310 }
@@ -298,16 +314,16 @@ protected function getRouteGroup(ReflectionClass $controller, ReflectionMethod $
298314 $ phpdoc = new DocBlock ($ docBlockComment );
299315 foreach ($ phpdoc ->getTags () as $ tag ) {
300316 if ($ tag ->getName () === 'group ' ) {
301- $ routeGroupParts = explode ("\n" , $ tag ->getContent ());
317+ $ routeGroupParts = explode ("\n" , trim ( $ tag ->getContent () ));
302318 $ routeGroupName = array_shift ($ routeGroupParts );
303319 $ routeGroupDescription = implode ("\n" , $ routeGroupParts );
304320
305- return [$ routeGroupName , $ routeGroupDescription ];
321+ return [$ routeGroupName , $ routeGroupDescription, $ methodDocBlock [ ' short ' ] ];
306322 }
307323 }
308324 }
309325
310- return [$ this ->config ->get (('default_group ' )), '' ];
326+ return [$ this ->config ->get (('default_group ' )), '' , $ methodDocBlock [ ' short ' ] ];
311327 }
312328
313329 private function normalizeParameterType ($ type )
0 commit comments