]> git.mxchange.org Git - friendica.git/blob - util/createdoxygen.php
Add missing doc in api.php
[friendica.git] / util / createdoxygen.php
1 #!/usr/bin/php
2 <?php
3 /**
4  * @file util/createdoxygen.php
5  * @brief Adds a doxygen header to functions
6  */
7
8 if (count($_SERVER["argv"]) < 2)
9         die("usage: createdoxygen.php file\n");
10
11 $file = $_SERVER["argv"][1];
12 $data = file_get_contents($file);
13
14 $lines = explode("\n", $data);
15
16 $previous = "";
17
18 foreach ($lines AS $line) {
19         $line = rtrim(trim($line, "\r"));
20
21         if (strstr(strtolower($line), "function")) {
22                 $detect = strtolower(trim($line));
23                 $detect = implode(" ", explode(" ", $detect));
24
25                 $found = false;
26
27                 if (substr($detect, 0, 9) == "function ")
28                         $found = true;
29
30                 if (substr($detect, 0, 17) == "private function ")
31                         $found = true;
32
33                 if (substr($detect, 0, 23) == "public static function ")
34                         $found = true;
35
36                 if (substr($detect, 0, 10) == "function (")
37                         $found = false;
38
39                 if ($found and (trim($previous) == "*/"))
40                         $found = false;
41
42                 if ($found and !strstr($detect, "{"))
43                         $found = false;
44
45                 if ($found) {
46                         echo add_documentation($line);
47                 }
48         }
49         echo $line."\n";
50         $previous = $line;
51 }
52
53 /**
54  * @brief Adds a doxygen header
55  *
56  * @param string $line The current line of the document
57  *
58  * @return string added doxygen header
59  */
60 function add_documentation($line) {
61
62         $trimmed = ltrim($line);
63         $length = strlen($line) - strlen($trimmed);
64         $space = substr($line, 0, $length);
65
66         $block = $space."/**\n".
67                 $space." * @brief \n".
68                 $space." *\n"; /**/
69
70
71         $left = strpos($line, "(");
72         $line = substr($line, $left + 1);
73
74         $right = strpos($line, ")");
75         $line = trim(substr($line, 0, $right));
76
77         if ($line != "") {
78                 $parameters = explode(",", $line);
79                 foreach ($parameters AS $parameter) {
80                         $parameter = trim($parameter);
81                         $splitted = explode("=", $parameter);
82
83                         $block .= $space." * @param ".trim($splitted[0], "& ")."\n";
84                 }
85                 if (count($parameters) > 0)
86                         $block .= $space." *\n";
87         }
88
89         $block .= $space." * @return \n".
90                 $space." */\n";
91
92         return $block;
93 }