3 namespace Friendica\Core\Console;
\r
6 * Description of CreateDoxygen
\r
8 * @author Hypolite Petovan <mrpetovan@gmail.com>
\r
10 class CreateDoxygen extends \Asika\SimpleConsole\Console
\r
12 protected $helpOptions = ['h', 'help', '?'];
\r
14 protected function getHelp()
\r
17 console createdoxygen - Generate Doxygen headers
\r
19 bin/console createdoxygen <file> [-h|--help|-?] [-v]
\r
22 Outputs the provided file with added Doxygen headers to functions
\r
25 -h|--help|-? Show help information
\r
26 -v Show more debug information.
\r
31 protected function doExecute()
\r
33 if ($this->getOption('v')) {
\r
34 $this->out('Class: ' . __CLASS__);
\r
35 $this->out('Arguments: ' . var_export($this->args, true));
\r
36 $this->out('Options: ' . var_export($this->options, true));
\r
39 if (count($this->args) == 0) {
\r
40 $this->out($this->getHelp());
\r
44 if (count($this->args) > 1) {
\r
45 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
\r
48 $file = $this->getArgument(0);
\r
49 if (!file_exists($file)) {
\r
50 throw new \RuntimeException('Unable to find specified file.');
\r
53 $data = file_get_contents($file);
\r
55 $lines = explode("\n", $data);
\r
59 foreach ($lines AS $line) {
\r
60 $line = rtrim(trim($line, "\r"));
\r
62 if (strstr(strtolower($line), "function")) {
\r
63 $detect = strtolower(trim($line));
\r
64 $detect = implode(" ", explode(" ", $detect));
\r
68 if (substr($detect, 0, 9) == "function ") {
\r
72 if (substr($detect, 0, 19) == "protected function ") {
\r
76 if (substr($detect, 0, 17) == "private function ") {
\r
80 if (substr($detect, 0, 23) == "public static function ") {
\r
84 if (substr($detect, 0, 24) == "private static function ") {
\r
88 if (substr($detect, 0, 10) == "function (") {
\r
92 if ($found && ( trim($previous) == "*/")) {
\r
97 $this->out($this->addDocumentation($line));
\r
108 * @brief Adds a doxygen header
\r
110 * @param string $line The current line of the document
\r
112 * @return string added doxygen header
\r
114 private function addDocumentation($line)
\r
116 $trimmed = ltrim($line);
\r
117 $length = strlen($line) - strlen($trimmed);
\r
118 $space = substr($line, 0, $length);
\r
120 $block = $space . "/**\n" .
\r
121 $space . " * @brief \n" .
\r
122 $space . " *\n"; /**/
\r
125 $left = strpos($line, "(");
\r
126 $line = substr($line, $left + 1);
\r
128 $right = strpos($line, ")");
\r
129 $line = trim(substr($line, 0, $right));
\r
132 $parameters = explode(",", $line);
\r
133 foreach ($parameters AS $parameter) {
\r
134 $parameter = trim($parameter);
\r
135 $splitted = explode("=", $parameter);
\r
137 $block .= $space . " * @param " . trim($splitted[0], "& ") . "\n";
\r
139 if (count($parameters) > 0) $block .= $space . " *\n";
\r
142 $block .= $space . " * @return \n" .
\r