@@ -27,6 +27,19 @@ To search a file, use the `search` method. Its only parameter may be either a s
2727
2828To search a string instead, use the ` searchCode ` method.
2929
30+ The search methods return an instance of ` Permafrost\PhpCodeSearch\Results\FileSearchResults ` , which has a ` results ` property.
31+
32+ Each ` result ` is an instance of ` Permafrost\PhpCodeSearch\Results\SearchResult ` with the following properties:
33+
34+ - ` node ` - the specific item that was found
35+ - ` node->name(): string `
36+ - ` location ` - the location in the file that the item was found
37+ - ` location->startLine(): int `
38+ - ` location->endLine(): int `
39+ - ` snippet ` - a snippet of code lines from the file with the result line in the middle
40+ - ` snippet->getCode(): string `
41+ - ` file() ` _ (method)_ - provides access to the file that was searched
42+
3043### Variable names
3144
3245To search for variables by name, use the ` variables ` method before calling ` search ` . To use regular expressions, surround the values with ` / ` .
@@ -41,7 +54,7 @@ $results = $searcher
4154 ->searchCode('<?php $oneA = "1a"; $oneB = "1b"; $oneC = "1c"; $twoA = "2a"; $twoB = "2b";');
4255
4356foreach($results as $result) {
44- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
57+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
4558}
4659```
4760
@@ -59,7 +72,7 @@ $results = $searcher
5972 ->search('./file1.php');
6073
6174foreach($results as $result) {
62- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
75+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
6376}
6477```
6578
@@ -80,7 +93,7 @@ $results = $searcher
8093 '');
8194
8295foreach($results as $result) {
83- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
96+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
8497}
8598```
8699
@@ -100,7 +113,7 @@ $results = $searcher
100113 ->search('./app/Http/Controllers/MyController.php');
101114
102115foreach($results as $result) {
103- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
116+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
104117}
105118```
106119
@@ -118,7 +131,7 @@ $results = $searcher
118131 ->search('./app/Http/Controllers/MyController.php');
119132
120133foreach($results as $result) {
121- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
134+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
122135}
123136```
124137
@@ -136,7 +149,7 @@ $results = $searcher
136149 ->search('./app/Http/Controllers/MyController.php');
137150
138151foreach($results as $result) {
139- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
152+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
140153}
141154```
142155
@@ -154,7 +167,7 @@ $results = $searcher
154167 ->searchCode('<?php $str = strtolower("TEST");');
155168
156169foreach($results as $result) {
157- echo "Found '{$result->location ->name}' on line {$result->location->startLine}" . PHP_EOL;
170+ echo "Found '{$result->node ->name() }' on line {$result->location->startLine}" . PHP_EOL;
158171}
159172```
160173
0 commit comments