@@ -47,13 +47,21 @@ public function __construct(Searcher $searcher)
4747 */
4848 public function extract (&$ n , TokenCollection $ tokens )
4949 {
50+ $ start = $ n ;
51+
5052 $ declaration = $ this ->searcher ->getUnder (array (') ' ), $ n , $ tokens );
5153 if (!preg_match ('!function\s+(.*)\(\s*(.*)!is ' , $ declaration , $ matches )) {
5254 throw new \Exception (sprintf ("Closure detected instead of method \nDetails: \n%s " , $ declaration ));
5355 }
5456 list (, $ name , $ args ) = $ matches ;
5557 $ method = new ReflectedMethod ($ name );
5658
59+ // visibility
60+ $ this ->extractVisibility ($ method , $ p = $ start , $ tokens ); // please keep "p = start"
61+
62+ // state
63+ $ this ->extractState ($ method , $ p = $ start , $ tokens ); // please keep "p = start"
64+
5765 $ arguments = preg_split ('!\s*,\s*!m ' , $ args );
5866 foreach ($ arguments as $ argDecl ) {
5967
@@ -80,6 +88,8 @@ public function extract(&$n, TokenCollection $tokens)
8088 $ method ->pushArgument ($ argument );
8189 }
8290
91+
92+
8393 //
8494 // Body
8595 $ this ->extractContent ($ method , $ n , $ tokens );
@@ -100,9 +110,51 @@ public function extract(&$n, TokenCollection $tokens)
100110 // usage
101111 $ this ->extractUsage ($ method );
102112
113+
114+
103115 return $ method ;
104116 }
105117
118+ /**
119+ * Extracts visibility
120+ *
121+ * @param ReflectedMethod $method
122+ * @param $n
123+ * @param TokenCollection $tokens
124+ * @return $this
125+ */
126+ public function extractVisibility (ReflectedMethod $ method , $ n , TokenCollection $ tokens ) {
127+ switch (true ) {
128+ case $ this ->searcher ->isPrecededBy (T_PRIVATE , $ n , $ tokens , 4 ):
129+ $ visibility = ReflectedMethod::VISIBILITY_PRIVATE ;
130+ break ;
131+ case $ this ->searcher ->isPrecededBy (T_PROTECTED , $ n , $ tokens , 4 ):
132+ $ visibility = ReflectedMethod::VISIBILITY_PROTECTED ;
133+ break ;
134+ case $ this ->searcher ->isPrecededBy (T_PUBLIC , $ n , $ tokens , 4 ):
135+ default :
136+ $ visibility = ReflectedMethod::VISIBILITY_PUBLIC ;
137+ break ;
138+ }
139+ $ method ->setVisibility ($ visibility );
140+ return $ this ;
141+ }
142+
143+ /**
144+ * Extracts state
145+ *
146+ * @param ReflectedMethod $method
147+ * @param $n
148+ * @param TokenCollection $tokens
149+ * @return $this
150+ */
151+ public function extractState (ReflectedMethod $ method , $ n , TokenCollection $ tokens ) {
152+ if ($ this ->searcher ->isPrecededBy (T_STATIC , $ n , $ tokens , 4 )) {
153+ $ method ->setState (ReflectedMethod::STATE_STATIC );
154+ }
155+ return $ this ;
156+ }
157+
106158 /**
107159 * Extracts content of method
108160 *
0 commit comments