@@ -246,57 +246,27 @@ private function filterRoutes( array $routes ): array
246246 private function outputTable ( array $ routes ): void
247247 {
248248 $ this ->output ->title ( 'MVC Routes ' );
249- $ this ->output ->write ( str_repeat ( '= ' , 80 ) );
250249
251- // Calculate column widths
252- $ maxPattern = 20 ;
253- $ maxController = 20 ;
254- $ maxAction = 15 ;
250+ // Prepare table headers
251+ $ headers = ['Pattern ' , 'Method ' , 'Controller ' , 'Action ' , 'Parameters ' ];
255252
253+ // Prepare table rows
254+ $ rows = [];
256255 foreach ( $ routes as $ route )
257256 {
258- $ maxPattern = max ( $ maxPattern , strlen ( $ route ['pattern ' ] ) );
259- $ maxController = max ( $ maxController , strlen ( $ route ['controller ' ] ) );
260- $ maxAction = max ( $ maxAction , strlen ( $ route ['action ' ] ) );
261- }
262-
263- // Limit widths
264- $ maxPattern = min ( $ maxPattern , 40 );
265- $ maxController = min ( $ maxController , 30 );
266- $ maxAction = min ( $ maxAction , 20 );
267-
268- // Output header
269- $ header = sprintf (
270- "%- {$ maxPattern }s | %-6s | %- {$ maxController }s | %- {$ maxAction }s | %s " ,
271- 'Pattern ' ,
272- 'Method ' ,
273- 'Controller ' ,
274- 'Action ' ,
275- 'Parameters '
276- );
277-
278- $ this ->output ->info ( $ header );
279- $ this ->output ->write ( str_repeat ( '- ' , strlen ( $ header ) + 10 ) );
280-
281- // Output routes
282- foreach ( $ routes as $ route )
283- {
284- $ pattern = $ this ->truncate ( $ route ['pattern ' ], $ maxPattern );
285- $ controller = $ this ->truncate ( $ route ['controller ' ], $ maxController );
286- $ action = $ this ->truncate ( $ route ['action ' ], $ maxAction );
287- $ parameters = empty ( $ route ['parameters ' ] ) ? '- ' : implode ( ', ' , $ route ['parameters ' ] );
288-
289- $ this ->output ->write ( sprintf (
290- "%- {$ maxPattern }s | %-6s | %- {$ maxController }s | %- {$ maxAction }s | %s " ,
291- $ pattern ,
257+ $ rows [] = [
258+ $ route ['pattern ' ],
292259 $ route ['method ' ],
293- $ controller ,
294- $ action ,
295- $ parameters
296- )) ;
260+ $ route [ ' controller ' ] ,
261+ $ route [ ' action ' ] ,
262+ empty ( $ route [ ' parameters ' ] ) ? ' - ' : implode ( ' , ' , $ route [ ' parameters ' ] )
263+ ] ;
297264 }
298265
299- $ this ->output ->write ( '' );
266+ // Display the table using Output's table method
267+ $ this ->output ->table ( $ headers , $ rows );
268+
269+ $ this ->output ->newLine ();
300270 $ this ->output ->info ( 'Total routes: ' . count ( $ routes ) );
301271
302272 // Show method distribution
@@ -320,23 +290,6 @@ private function outputJson( array $routes ): void
320290 $ this ->output ->write ( json_encode ( $ routes , JSON_PRETTY_PRINT ) );
321291 }
322292
323- /**
324- * Truncate string to maximum length
325- *
326- * @param string $str
327- * @param int $maxLength
328- * @return string
329- */
330- private function truncate ( string $ str , int $ maxLength ): string
331- {
332- if ( strlen ( $ str ) <= $ maxLength )
333- {
334- return $ str ;
335- }
336-
337- return substr ( $ str , 0 , $ maxLength - 3 ) . '... ' ;
338- }
339-
340293 /**
341294 * Try to find the configuration directory
342295 *
0 commit comments