annotation($class); if( isset($annotation->command) ) { $numbers[strlen($annotation->command)] = strlen($annotation->description); $commands[$annotation->command] = $annotation->description; } } } $keys = array_keys($numbers); rsort($numbers); rsort($keys); $this->descriptionNameCount = $numbers[0]; $this->commandNameCount = $keys[0]; $line = $this->line(); $output = $line; $output .= $this->title(); $output .= $line; ksort($commands); foreach( $commands as $key => $command ) { $output .= $this->command($key, $command); } $output .= $line; echo $output; } /** * Protected Line */ protected function line() { return '+' . str_repeat('-', $this->commandNameCount + 2) . '+' . str_repeat('-', $this->descriptionNameCount + 2) . '+' . EOL; } /** * Protected Title */ protected function title() { return '| Command' . str_repeat(' ', $this->commandNameCount - 6) . '| Description' . str_repeat(' ', $this->descriptionNameCount - 11) . ' |' . EOL; } /** * Protected Command */ protected function command($key, $command) { $nameCount = $this->commandNameCount - strlen($key); $descriptionCount = $this->descriptionNameCount - strlen($command); $nameCount = $nameCount < 0 ? 0 : $nameCount; $descriptionCount = $descriptionCount < 0 ? 0 : $descriptionCount; return '| ' . $key . str_repeat(' ', $nameCount) . ' | '. $command . str_repeat(' ', $descriptionCount) . ' |' . EOL; } }