Skip to content

Commit 5c3e0e9

Browse files
committed
update readme
1 parent e70f574 commit 5c3e0e9

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ To search a file, use the `search` method. Its only parameter may be either a s
2727

2828
To 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

3245
To 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

4356
foreach($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

6174
foreach($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

8295
foreach($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

102115
foreach($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

120133
foreach($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

138151
foreach($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

156169
foreach($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

Comments
 (0)