@@ -27,6 +27,19 @@ To search a file, use the `search` method. Its only parameter may be either a s
27
27
28
28
To search a string instead, use the ` searchCode ` method.
29
29
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
+
30
43
### Variable names
31
44
32
45
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
41
54
->searchCode('<?php $oneA = "1a"; $oneB = "1b"; $oneC = "1c"; $twoA = "2a"; $twoB = "2b";');
42
55
43
56
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;
45
58
}
46
59
```
47
60
@@ -59,7 +72,7 @@ $results = $searcher
59
72
->search('./file1.php');
60
73
61
74
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;
63
76
}
64
77
```
65
78
@@ -80,7 +93,7 @@ $results = $searcher
80
93
'');
81
94
82
95
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;
84
97
}
85
98
```
86
99
@@ -100,7 +113,7 @@ $results = $searcher
100
113
->search('./app/Http/Controllers/MyController.php');
101
114
102
115
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;
104
117
}
105
118
```
106
119
@@ -118,7 +131,7 @@ $results = $searcher
118
131
->search('./app/Http/Controllers/MyController.php');
119
132
120
133
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;
122
135
}
123
136
```
124
137
@@ -136,7 +149,7 @@ $results = $searcher
136
149
->search('./app/Http/Controllers/MyController.php');
137
150
138
151
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;
140
153
}
141
154
```
142
155
@@ -154,7 +167,7 @@ $results = $searcher
154
167
->searchCode('<?php $str = strtolower("TEST");');
155
168
156
169
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;
158
171
}
159
172
```
160
173
0 commit comments