瀏覽代碼

fixed type/name order

tags/0.1.0
Robin Thoni 8 年之前
父節點
當前提交
ac6858df56
共有 1 個檔案被更改,包括 32 行新增37 行删除
  1. 32
    37
      src/Doc/Business/DocBlock.php

+ 32
- 37
src/Doc/Business/DocBlock.php 查看文件

12
 
12
 
13
 class DocBlock {
13
 class DocBlock {
14
 
14
 
15
-    public $docblock,
16
-        $description = null,
17
-        $all_params = array();
15
+    public $docblock;
16
+    public $description = null;
17
+    public $all_params = array();
18
 
18
 
19
     /**
19
     /**
20
      * Parses a docblock;
20
      * Parses a docblock;
21
      */
21
      */
22
-    function __construct($docblock) {
23
-        if( !is_string($docblock) ) {
22
+    function __construct($docblock)
23
+    {
24
+        if (!is_string($docblock)) {
24
             throw new Exception("DocBlock expects first parameter to be a string");
25
             throw new Exception("DocBlock expects first parameter to be a string");
25
         }
26
         }
26
 
27
 
45
      * @param string $param_name
46
      * @param string $param_name
46
      * @return mixed
47
      * @return mixed
47
      */
48
      */
48
-    public function __call($param_name, $values = null) {
49
-        if( $param_name == "description" ) {
49
+    public function __call($param_name, $values = null)
50
+    {
51
+        if ($param_name == "description") {
50
             return $this->description;
52
             return $this->description;
51
-        }else if( isset($this->all_params[$param_name]) ) {
53
+        }
54
+        else if (isset($this->all_params[$param_name])) {
52
             $params = $this->all_params[$param_name];
55
             $params = $this->all_params[$param_name];
53
 
56
 
54
-            if( count($params) == 1 ) {
57
+            if (count($params) == 1) {
55
                 return $params[0];
58
                 return $params[0];
56
-            }else {
59
+            }
60
+            else {
57
                 return $params;
61
                 return $params;
58
             }
62
             }
59
         }
63
         }
60
-
61
         return null;
64
         return null;
62
     }
65
     }
63
 
66
 
67
      * and the rest in `$this->description`
70
      * and the rest in `$this->description`
68
      */
71
      */
69
     private function parse_block() {
72
     private function parse_block() {
70
-        // split at each line
71
-        foreach(preg_split("/(\r?\n)/", $this->docblock) as $line){
73
+        foreach(preg_split("/(\r?\n)/", $this->docblock) as $line) {
72
 
74
 
73
-            // if starts with an asterisk
74
-            if( preg_match('/^(?=\s+?\*[^\/])(.+)/', $line, $matches) ) {
75
+            if (preg_match('/^(?=\s+?\*[^\/])(.+)/', $line, $matches)) {
75
 
76
 
76
                 $info = $matches[1];
77
                 $info = $matches[1];
77
-
78
-                // remove wrapping whitespace
79
                 $info = trim($info);
78
                 $info = trim($info);
80
-
81
-                // remove leading asterisk
82
                 $info = preg_replace('/^(\*\s+?)/', '', $info);
79
                 $info = preg_replace('/^(\*\s+?)/', '', $info);
83
 
80
 
84
-                // if it doesn't start with an "@" symbol
85
-                // then add to the description
86
-                if( $info[0] !== "@" ) {
81
+                if ($info[0] !== "@") {
87
                     $this->description .= "\n$info";
82
                     $this->description .= "\n$info";
88
-                    continue;
89
-                }else {
90
-                    // get the name of the param
91
-                    if (preg_match('/@param +\\$([^ ]+) +([^ ]+) +(.*)$/', $info, $matches) == 1) {
83
+                }
84
+                else if (preg_match('/@param +([^ ]+) +([^ ]+) +(.*)$/', $info, $matches) == 1) {
85
+                    if ($matches[1][0] == "$") {
92
                         $param_name = $matches[1];
86
                         $param_name = $matches[1];
93
                         $param_type = $matches[2];
87
                         $param_type = $matches[2];
94
-                        $value = $matches[3];
95
-
96
-
97
-                        // push the param value into place
98
-                        $this->all_params[$param_name] = [
99
-                            "name" => $param_name,
100
-                            "type" => $param_type,
101
-                            "description" => $value
102
-                        ];
103
-
104
-                        continue;
105
                     }
88
                     }
89
+                    else {
90
+                        $param_name = $matches[2];
91
+                        $param_type = $matches[1];
92
+                    }
93
+                    $value = $matches[3];
94
+                    $param_name = substr($param_name, 1);
95
+
96
+                    $this->all_params[$param_name] = [
97
+                        "name" => $param_name,
98
+                        "type" => $param_type,
99
+                        "description" => $value
100
+                    ];
106
                 }
101
                 }
107
             }
102
             }
108
         }
103
         }

Loading…
取消
儲存