Browse Source

fixed type/name order

tags/0.1.0
Robin Thoni 8 years ago
parent
commit
ac6858df56
1 changed files with 32 additions and 37 deletions
  1. 32
    37
      src/Doc/Business/DocBlock.php

+ 32
- 37
src/Doc/Business/DocBlock.php View File

@@ -12,15 +12,16 @@ use Exception;
12 12
 
13 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 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 25
             throw new Exception("DocBlock expects first parameter to be a string");
25 26
         }
26 27
 
@@ -45,19 +46,21 @@ class DocBlock {
45 46
      * @param string $param_name
46 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 52
             return $this->description;
51
-        }else if( isset($this->all_params[$param_name]) ) {
53
+        }
54
+        else if (isset($this->all_params[$param_name])) {
52 55
             $params = $this->all_params[$param_name];
53 56
 
54
-            if( count($params) == 1 ) {
57
+            if (count($params) == 1) {
55 58
                 return $params[0];
56
-            }else {
59
+            }
60
+            else {
57 61
                 return $params;
58 62
             }
59 63
         }
60
-
61 64
         return null;
62 65
     }
63 66
 
@@ -67,42 +70,34 @@ class DocBlock {
67 70
      * and the rest in `$this->description`
68 71
      */
69 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 77
                 $info = $matches[1];
77
-
78
-                // remove wrapping whitespace
79 78
                 $info = trim($info);
80
-
81
-                // remove leading asterisk
82 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 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 86
                         $param_name = $matches[1];
93 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…
Cancel
Save