Skip to content

Commit f540cf7

Browse files
authored
Update README.md
1 parent 88ef7dc commit f540cf7

1 file changed

Lines changed: 25 additions & 31 deletions

File tree

README.md

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,28 @@ $searcher = new Searcher();
5353
To search a file, use the `search` method, and the `searchCode` method to search a string of code.
5454

5555
```php
56-
$results = $searcher
56+
$searcher
5757
->functions(['strtolower', 'strtoupper'])
5858
->search('./file1.php');
5959

60-
$results = $searcher
61-
->variables(['twoA', '/^one[AB]$/'])
62-
->searchCode('<?php $oneA = "1a"; $oneB = "1b"; $oneC = "1c"; $twoA = "2a"; $twoB = "2b";');
60+
$searcher
61+
->variables(['/^one[A-Z]$/'])
62+
->searchCode('<?php $oneA = "1a";');
6363
```
6464

6565
### Variable names
6666

67-
To search for variables by name, use the `variables` method before calling `search`. To use regular expressions, surround the values with `/`.
67+
To search for variables by name, use the `variables` method. To use regular expressions, surround the values with `/`.
6868

6969
```php
7070
$results = $searcher
71-
->variables(['twoA', '/^one[AB]$/'])
72-
->searchCode('<?php $oneA = "1a"; $oneB = "1b"; $oneC = "1c"; $twoA = "2a"; $twoB = "2b";');
71+
->variables(['twoA', '/^one.$/'])
72+
->searchCode('<?php '.
73+
' $oneA = "1a";'.
74+
' $oneB = "1b";'.
75+
' $twoA = "2a";'.
76+
' $twoB = "2b";'.
77+
'');
7378

7479
foreach($results->results as $result) {
7580
echo "Found '{$result->node->name()}' on line {$result->location->startLine}" . PHP_EOL;
@@ -81,14 +86,10 @@ foreach($results->results as $result) {
8186
To search for function calls or definitions, use the `functions` method. Regular expressions can be used by surrounding the name with slashes `/`, i.e. `/test\d+/`.
8287

8388
```php
84-
// this will search for references AND definitions for 'strtolower' and 'myfunc'
85-
$results = $searcher
89+
// search for references AND definitions for 'strtolower' and/or 'myfunc'
90+
$searcher
8691
->functions(['strtolower', 'myfunc'])
87-
->search('./file1.php');
88-
89-
foreach($results->results as $result) {
90-
echo "Found '{$result->node->name()}' on line {$result->location->startLine}" . PHP_EOL;
91-
}
92+
->search('file1.php');
9293
```
9394

9495
### Method calls
@@ -101,9 +102,10 @@ Method call nodes have an `args` property that can be looped through to retrieve
101102
$results = $searcher
102103
->methods(['/test(One|Two)/'])
103104
->searchCode('<?php '.
104-
' $obj->testOne("hello world 1"); '.
105-
' $obj->testTwo("hello world", 2); '.
106-
'');
105+
' $obj->testOne("hello world 1"); '.
106+
' $obj->testTwo("hello world", 2); '.
107+
''
108+
);
107109

108110
foreach($results->results as $result) {
109111
echo "Found '{$result->node->name()}' on line {$result->location->startLine}" . PHP_EOL;
@@ -121,21 +123,17 @@ To search for static method or property calls, use the `static` method before ca
121123
Valid search terms are either a class name like `Cache`, or a class name and a method name like `Cache::remember`.
122124

123125
```php
124-
$results = $searcher
126+
$searcher
125127
->static(['Ray', 'Cache::has', 'Request::$myProperty'])
126128
->search('./app/Http/Controllers/MyController.php');
127-
128-
foreach($results->results as $result) {
129-
echo "Found '{$result->node->name()}' on line {$result->location->startLine}" . PHP_EOL;
130-
}
131129
```
132130

133131
### Classes
134132

135133
To search for either a class definition or a class created by the `new` keyword, use the `classes`. Regular expression patterns are supported by surrounding a value with slashes `/`.
136134

137135
```php
138-
$results = $searcher
136+
$searcher
139137
->classes(['MyController'])
140138
->search('./app/Http/Controllers/MyController.php');
141139
```
@@ -145,24 +143,20 @@ $results = $searcher
145143
To search for a variable assignment by variable name, use the `assignments` method before calling `search`. _Note: The `$` should be omitted._
146144

147145
```php
148-
$results = $searcher
146+
$searcher
149147
->assignments(['myVar'])
150148
->search('./app/Http/Controllers/MyController.php');
151-
152-
foreach($results->results as $result) {
153-
echo "Found '{$result->node->name()}' on line {$result->location->startLine}" . PHP_EOL;
154-
}
155149
```
156150

157151
### Results without code snippets
158152

159153
To return search results without associated code snippets, use the `withoutSnippets` method:
160154

161155
```php
162-
$results = $searcher
163-
->functions(['strtolower'])
156+
$searcher
164157
->withoutSnippets()
165-
->searchCode('<?php $str = strtolower("TEST");');
158+
->functions(['strtolower'])
159+
->search('file1.php');
166160
```
167161

168162

0 commit comments

Comments
 (0)