1818use Permafrost \PhpCodeSearch \Visitors \VariableReferenceVisitor ;
1919use PhpParser \Error ;
2020use PhpParser \Node ;
21- use PhpParser \Node \Expr \FuncCall ;
2221use PhpParser \Node \Stmt ;
2322use PhpParser \NodeFinder ;
2423use PhpParser \NodeTraverser ;
@@ -33,19 +32,19 @@ class Searcher
3332 protected $ ast = [];
3433
3534 /** @var array */
36- protected $ functions = [];
35+ protected $ assignments = [];
3736
3837 /** @var array */
39- protected $ methods = [];
38+ protected $ classes = [];
4039
4140 /** @var array */
42- protected $ classes = [];
41+ protected $ functions = [];
4342
4443 /** @var array */
45- protected $ static = [];
44+ protected $ methods = [];
4645
4746 /** @var array */
48- protected $ assignments = [];
47+ protected $ static = [];
4948
5049 /** @var array */
5150 protected $ variables = [];
@@ -58,48 +57,44 @@ public function __construct($parser = null)
5857 $ this ->parser = $ parser ?? (new ParserFactory ())->create (ParserFactory::PREFER_PHP7 );
5958 }
6059
61- public function functions (array $ names ): self
60+ public function assignments (array $ varNames ): self
6261 {
63- $ this ->functions = array_merge ($ this ->functions , $ names );
62+ $ this ->assignments = array_merge ($ this ->assignments , $ varNames );
6463
6564 return $ this ;
6665 }
6766
68- public function methods (array $ names ): self
67+ public function classes (array $ names ): self
6968 {
70- $ this ->methods = array_merge ($ this ->methods , $ names );
69+ $ this ->classes = array_merge ($ this ->classes , $ names );
7170
7271 return $ this ;
7372 }
7473
75- public function variables (array $ names ): self
74+ public function functions (array $ names ): self
7675 {
77- $ this ->variables = array_merge ($ this ->variables , $ names );
76+ $ this ->functions = array_merge ($ this ->functions , $ names );
7877
7978 return $ this ;
8079 }
8180
82- public function static (array $ names ): self
81+ public function methods (array $ names ): self
8382 {
84- $ this ->static = array_merge ($ this ->static , $ names );
83+ $ this ->methods = array_merge ($ this ->methods , $ names );
8584
8685 return $ this ;
8786 }
8887
89- public function assignments (array $ varNames ): self
88+ public function static (array $ names ): self
9089 {
91- $ varNames = array_map (function ($ item ) {
92- return ltrim ($ item , '$ ' );
93- }, $ varNames );
94-
95- $ this ->assignments = array_merge ($ this ->assignments , $ varNames );
90+ $ this ->static = array_merge ($ this ->static , $ names );
9691
9792 return $ this ;
9893 }
9994
100- public function classes (array $ names ): self
95+ public function variables (array $ names ): self
10196 {
102- $ this ->classes = array_merge ($ this ->classes , $ names );
97+ $ this ->variables = array_merge ($ this ->variables , $ names );
10398
10499 return $ this ;
105100 }
@@ -117,19 +112,18 @@ public function withoutSnippets(): self
117112 */
118113 public function search ($ file ): FileSearchResults
119114 {
120- if (is_string ($ file )) {
121- $ file = new File ($ file );
122- }
115+ $ file = is_string ($ file ) ? new File ($ file ) : $ file ;
123116
124117 $ results = new FileSearchResults ($ file , $ this ->withSnippets );
125118
126119 if (! $ this ->parseFile ($ file , $ results )) {
127120 return $ results ;
128121 }
129122
130- $ calls = $ this ->findAllReferences ($ this ->ast );
131-
132- $ this ->traverseNodes ($ results , $ calls );
123+ $ this ->traverseNodes (
124+ $ results ,
125+ $ this ->findAllReferences ($ this ->ast )
126+ );
133127
134128 return $ results ;
135129 }
0 commit comments