7a5ce790821429de45a81d58bb696df497119491
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / src / phpDocumentor / Reflection / DocBlock / Tag / MethodTag.php
1 <?php
2 /**
3  * phpDocumentor
4  *
5  * PHP Version 5.3
6  *
7  * @author    Mike van Riel <mike.vanriel@naenius.com>
8  * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
9  * @license   http://www.opensource.org/licenses/mit-license.php MIT
10  * @link      http://phpdoc.org
11  */
12
13 namespace phpDocumentor\Reflection\DocBlock\Tag;
14
15 use phpDocumentor\Reflection\DocBlock\Tag;
16
17 /**
18  * Reflection class for a @method in a Docblock.
19  *
20  * @author  Mike van Riel <mike.vanriel@naenius.com>
21  * @license http://www.opensource.org/licenses/mit-license.php MIT
22  * @link    http://phpdoc.org
23  */
24 class MethodTag extends ReturnTag
25 {
26
27     /** @var string */
28     protected $method_name = '';
29
30     /** @var string */
31     protected $arguments = '';
32     
33     /** @var bool */
34     protected $isStatic = false;
35
36     /**
37      * {@inheritdoc}
38      */
39     public function getContent()
40     {
41         if (null === $this->content) {
42             $this->content = '';
43             if ($this->isStatic) {
44                 $this->content .= 'static ';
45             }
46             $this->content .= $this->type .
47                 " {$this->method_name}({$this->arguments}) " .
48                 $this->description;
49         }
50
51         return $this->content;
52     }
53
54     /**
55      * {@inheritdoc}
56      */
57     public function setContent($content)
58     {
59         Tag::setContent($content);
60         // 1. none or more whitespace
61         // 2. optionally the keyword "static" followed by whitespace
62         // 3. optionally a word with underscores followed by whitespace : as
63         //    type for the return value
64         // 4. then optionally a word with underscores followed by () and
65         //    whitespace : as method name as used by phpDocumentor
66         // 5. then a word with underscores, followed by ( and any character
67         //    until a ) and whitespace : as method name with signature
68         // 6. any remaining text : as description
69         if (preg_match(
70             '/^
71                 # Static keyword
72                 # Declates a static method ONLY if type is also present
73                 (?:
74                     (static)
75                     \s+
76                 )?
77                 # Return type
78                 (?:
79                     ([\w\|_\\\\]+)
80                     \s+
81                 )?
82                 # Legacy method name (not captured)
83                 (?:
84                     [\w_]+\(\)\s+
85                 )?
86                 # Method name
87                 ([\w\|_\\\\]+)
88                 # Arguments
89                 \(([^\)]*)\)
90                 \s*
91                 # Description
92                 (.*)
93             $/sux',
94             $this->description,
95             $matches
96         )) {
97             list(
98                 ,
99                 $static,
100                 $this->type,
101                 $this->method_name,
102                 $this->arguments,
103                 $this->description
104             ) = $matches;
105             if ($static) {
106                 if (!$this->type) {
107                     $this->type = 'static';
108                 } else {
109                     $this->isStatic = true;
110                 }
111             } else {
112                 if (!$this->type) {
113                     $this->type = 'void';
114                 }
115             }
116             $this->parsedDescription = null;
117         }
118
119         return $this;
120     }
121
122     /**
123      * Sets the name of this method.
124      *
125      * @param string $method_name The name of the method.
126      *
127      * @return $this
128      */
129     public function setMethodName($method_name)
130     {
131         $this->method_name = $method_name;
132
133         $this->content = null;
134         return $this;
135     }
136
137     /**
138      * Retrieves the method name.
139      *
140      * @return string
141      */
142     public function getMethodName()
143     {
144         return $this->method_name;
145     }
146
147     /**
148      * Sets the arguments for this method.
149      *
150      * @param string $arguments A comma-separated arguments line.
151      *
152      * @return void
153      */
154     public function setArguments($arguments)
155     {
156         $this->arguments = $arguments;
157
158         $this->content = null;
159         return $this;
160     }
161
162     /**
163      * Returns an array containing each argument as array of type and name.
164      *
165      * Please note that the argument sub-array may only contain 1 element if no
166      * type was specified.
167      *
168      * @return string[]
169      */
170     public function getArguments()
171     {
172         if (empty($this->arguments)) {
173             return array();
174         }
175
176         $arguments = explode(',', $this->arguments);
177         foreach ($arguments as $key => $value) {
178             $arguments[$key] = explode(' ', trim($value));
179         }
180
181         return $arguments;
182     }
183     
184     /**
185      * Checks whether the method tag describes a static method or not.
186      * 
187      * @return bool TRUE if the method declaration is for a static method, FALSE
188      *     otherwise.
189      */
190     public function isStatic()
191     {
192         return $this->isStatic;
193     }
194     
195     /**
196      * Sets a new value for whether the method is static or not.
197      * 
198      * @param bool $isStatic The new value to set.
199      * 
200      * @return $this
201      */
202     public function setIsStatic($isStatic)
203     {
204         $this->isStatic = $isStatic;
205
206         $this->content = null;
207         return $this;
208     }
209 }