File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public function addLocation(CodeLocation $location): self
30
30
{
31
31
$ snippet = $ this ->makeSnippet ($ location ->startLine ());
32
32
33
- $ this ->results [] = new SearchResult ($ location , $ snippet );
33
+ $ this ->results [] = new SearchResult ($ location , $ snippet, $ this -> file );
34
34
35
35
return $ this ;
36
36
}
Original file line number Diff line number Diff line change 5
5
use Permafrost \PhpCodeSearch \Code \CodeLocation ;
6
6
use Permafrost \PhpCodeSearch \Code \CodeSnippet ;
7
7
use Permafrost \PhpCodeSearch \Code \FunctionCallLocation ;
8
+ use Permafrost \PhpCodeSearch \Support \File ;
8
9
9
10
class SearchResult
10
11
{
@@ -14,9 +15,23 @@ class SearchResult
14
15
/** @var CodeSnippet|null */
15
16
public $ snippet ;
16
17
17
- public function __construct (CodeLocation $ location , ?CodeSnippet $ snippet )
18
+ /** @var File */
19
+ protected $ file ;
20
+
21
+ /**
22
+ * @param CodeLocation $location
23
+ * @param CodeSnippet|null $snippet
24
+ * @param File|string $file
25
+ */
26
+ public function __construct (CodeLocation $ location , ?CodeSnippet $ snippet , $ file )
18
27
{
19
28
$ this ->location = $ location ;
20
29
$ this ->snippet = $ snippet ;
30
+ $ this ->file = is_string ($ file ) ? new File ($ file ) : $ file ;
31
+ }
32
+
33
+ public function file (): File
34
+ {
35
+ return $ this ->file ;
21
36
}
22
37
}
Original file line number Diff line number Diff line change @@ -16,9 +16,10 @@ class SearchResultTest extends TestCase
16
16
/** @test */
17
17
public function it_creates_the_object_with_correct_properties ()
18
18
{
19
+ $ file = new File (tests_path ('data/file2.txt ' ));
19
20
$ location = new FunctionCallLocation ('my_func ' , 1 , 1 );
20
- $ snippet = (new CodeSnippet ())->fromFile (new File ( tests_path ( ' data/file2.txt ' )) );
21
- $ result = new SearchResult ($ location , $ snippet );
21
+ $ snippet = (new CodeSnippet ())->fromFile ($ file );
22
+ $ result = new SearchResult ($ location , $ snippet, $ file );
22
23
23
24
$ this ->assertMatchesObjectSnapshot ($ result );
24
25
}
You can’t perform that action at this time.
0 commit comments