Skip to content

Commit 0786b27

Browse files
authored
Merge pull request #5 from permafrost-dev/use-code-snippets-pkg
use code-snippets package
2 parents 259dd00 + a6a270d commit 0786b27

22 files changed

Lines changed: 47 additions & 171 deletions

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
],
1414
"require": {
1515
"php": "^7.3|^8.0",
16-
"nikic/php-parser": "^4.10"
16+
"nikic/php-parser": "^4.10",
17+
"permafrost-dev/code-snippets": "^1.0"
1718
},
1819
"require-dev": {
1920
"phpunit/phpunit": "^9.5",

src/Code/CodeSnippet.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/Results/FileSearchResults.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Permafrost\PhpCodeSearch\Results;
44

5+
use Permafrost\CodeSnippets\CodeSnippet;
56
use Permafrost\PhpCodeSearch\Code\CodeLocation;
6-
use Permafrost\PhpCodeSearch\Code\CodeSnippet;
7-
use Permafrost\PhpCodeSearch\Results\Nodes\ResultNode;
87
use Permafrost\PhpCodeSearch\Support\File;
8+
use Permafrost\PhpCodeSearch\Results\Nodes\ResultNode;
99

1010
class FileSearchResults
1111
{
@@ -21,7 +21,11 @@ class FileSearchResults
2121
/** @var bool */
2222
protected $withSnippets = true;
2323

24-
public function __construct(File $file, bool $withSnippets = true)
24+
/**
25+
* @param \Permafrost\PhpCodeSearch\Support\File|\Permafrost\CodeSnippets\File $file
26+
* @param bool $withSnippets
27+
*/
28+
public function __construct($file, bool $withSnippets = true)
2529
{
2630
$this->file = $file;
2731
$this->withSnippets = $withSnippets;
@@ -57,6 +61,6 @@ protected function makeSnippet(int $startLine, int $lineCount = 8): ?CodeSnippet
5761
return (new CodeSnippet())
5862
->surroundingLine($startLine)
5963
->snippetLineCount($lineCount)
60-
->fromFile($this->file);
64+
->fromFile($this->file->getRealPath());
6165
}
6266
}

src/Results/SearchResult.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace Permafrost\PhpCodeSearch\Results;
44

55
use Permafrost\PhpCodeSearch\Code\CodeLocation;
6-
use Permafrost\PhpCodeSearch\Code\CodeSnippet;
6+
use Permafrost\CodeSnippets\CodeSnippet;
7+
use Permafrost\CodeSnippets\File;
78
use Permafrost\PhpCodeSearch\Code\GenericCodeLocation;
89
use Permafrost\PhpCodeSearch\Results\Nodes\FunctionCallNode;
910
use Permafrost\PhpCodeSearch\Results\Nodes\ResultNode;
1011
use Permafrost\PhpCodeSearch\Results\Nodes\StaticMethodCallNode;
1112
use Permafrost\PhpCodeSearch\Results\Nodes\VariableNode;
12-
use Permafrost\PhpCodeSearch\Support\File;
1313

1414
class SearchResult
1515
{
@@ -28,8 +28,8 @@ class SearchResult
2828
/**
2929
* @param \Permafrost\PhpCodeSearch\Results\Nodes\ResultNode $node
3030
* @param \Permafrost\PhpCodeSearch\Code\CodeLocation $location
31-
* @param \Permafrost\PhpCodeSearch\Code\CodeSnippet|null $snippet
32-
* @param \Permafrost\PhpCodeSearch\Support\File|string $file
31+
* @param \Permafrost\CodeSnippets\CodeSnippet|null $snippet
32+
* @param \Permafrost\CodeSnippets\File|string $file
3333
*/
3434
public function __construct(ResultNode $node, CodeLocation $location, ?CodeSnippet $snippet, $file)
3535
{

src/Searcher.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Permafrost\PhpCodeSearch;
44

5+
use Permafrost\CodeSnippets\File;
56
use Permafrost\PhpCodeSearch\Results\FileSearchResults;
67
use Permafrost\PhpCodeSearch\Results\SearchError;
78
use Permafrost\PhpCodeSearch\Support\Arr;
8-
use Permafrost\PhpCodeSearch\Support\File;
99
use Permafrost\PhpCodeSearch\Support\VirtualFile;
1010
use Permafrost\PhpCodeSearch\Visitors\AssignmentVisitor;
1111
use Permafrost\PhpCodeSearch\Visitors\FunctionCallVisitor;
@@ -138,7 +138,12 @@ public function searchCode(string $code): FileSearchResults
138138
return $this->search($file);
139139
}
140140

141-
protected function parseFile(File $file, FileSearchResults $results): bool
141+
/**
142+
* @param \Permafrost\PhpCodeSearch\Support\File|\Permafrost\CodeSnippets\File $file
143+
* @param FileSearchResults $results
144+
* @return bool
145+
*/
146+
protected function parseFile($file, FileSearchResults $results): bool
142147
{
143148
try {
144149
/** @var array|Stmt[] $ast */

tests/Code/CodeSnippetTest.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/Code/__snapshots__/CodeSnippetTest__it_gets_a_snippet_from_a_file__1.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/Code/__snapshots__/CodeSnippetTest__it_returns_no_code_when_given_a_file_that_does_not_exist__1.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/Results/SearchResultTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Permafrost\PhpCodeSearch\Tests\Results;
44

5-
use Permafrost\PhpCodeSearch\Code\CodeSnippet;
5+
use Permafrost\CodeSnippets\CodeSnippet;
6+
use Permafrost\CodeSnippets\File;
67
use Permafrost\PhpCodeSearch\Code\GenericCodeLocation;
78
use Permafrost\PhpCodeSearch\Results\Nodes\VariableNode;
89
use Permafrost\PhpCodeSearch\Results\SearchResult;
9-
use Permafrost\PhpCodeSearch\Support\File;
1010
use PHPUnit\Framework\TestCase;
1111
use Spatie\Snapshots\MatchesSnapshots;
1212

@@ -19,7 +19,7 @@ public function it_creates_the_object_with_correct_properties()
1919
{
2020
$file = new File(tests_path('data/file2.txt'));
2121
$location = new GenericCodeLocation(1, 1);
22-
$snippet = (new CodeSnippet())->fromFile($file);
22+
$snippet = (new CodeSnippet())->surroundingLine(2)->snippetLineCount(10)->fromFile($file);
2323
$resultNode = new VariableNode('myVar');
2424
$result = new SearchResult($resultNode, $location, $snippet, $file);
2525

tests/Results/__snapshots__/SearchResultTest__it_creates_the_object_with_correct_properties__1.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ location:
55
node:
66
name: myVar
77
snippet:
8-
code: { 1: '1', 2: '2', 3: '3', 4: '4', 5: '5' }
9-
lineNumber: 1
8+
snippetLineCount: 10
9+
lines: { 1: { selected: false, lineNumber: 1, value: '1', isSelected: false }, 2: { selected: true, lineNumber: 2, value: '2', isSelected: true }, 3: { selected: false, lineNumber: 3, value: '3', isSelected: false }, 4: { selected: false, lineNumber: 4, value: '4', isSelected: false }, 5: { selected: false, lineNumber: 5, value: '5', isSelected: false } }
10+
lineNumberStart: 2
11+
lineNumberEnd: 2

0 commit comments

Comments
 (0)