File tree Expand file tree Collapse file tree 8 files changed +54
-20
lines changed Expand file tree Collapse file tree 8 files changed +54
-20
lines changed Original file line number Diff line number Diff line change 4343 'searchcode ' => [
4444 'service ' => 'php-parser ' ,
4545
46- 'services ' => [
47- 'php-parser ' => [
48- 'paths ' => [
49- app_path (),
50- resource_path (),
51- ],
52- ],
46+ 'paths ' => [
47+ app_path (),
48+ resource_path (),
5349 ],
50+
51+ 'excluded_paths ' => [],
52+
5453 ],
5554
5655];
Original file line number Diff line number Diff line change 1515class PhpParserService implements SearchCodeServiceInterface
1616{
1717 public function __construct (
18- public array $ paths
18+ public array $ paths ,
19+ public array $ excludedPaths = [],
1920 ) {
2021 //
2122 }
@@ -24,13 +25,16 @@ public function finder(): Finder
2425 {
2526 return Finder::create ()
2627 ->in ($ this ->paths )
27- ->followLinks ()
28+ // ->exclude($this->excludedPaths)
29+ ->notPath ($ this ->excludedPaths )
30+ ->exclude ('vendor ' )
31+ ->exclude ('node_modules ' )
2832 ->ignoreDotFiles (true )
2933 ->ignoreVCS (true )
34+ ->ignoreVCSIgnored (true )
3035 ->ignoreUnreadableDirs (true )
31- ->exclude ('vendor ' )
32- ->exclude ('node_modules ' )
3336 ->name ('*.php ' )
37+ ->followLinks ()
3438 ->files ();
3539 }
3640
Original file line number Diff line number Diff line change @@ -91,7 +91,8 @@ public static function getSearchcodeServiceFromConfig(?string $serviceName = nul
9191
9292 return match ($ service ) {
9393 'php-parser ' , PhpParserService::class => new PhpParserService (
94- config ('translator.searchcode.services.php-parser.paths ' )
94+ paths: config ('translator.searchcode.paths ' ),
95+ excludedPaths: config ('translator.searchcode.excluded_paths ' , [])
9596 ),
9697 '' , null => null ,
9798 default => new $ service ,
Original file line number Diff line number Diff line change 8888it ('finds dead translations in a namespace ' , function () {
8989 $ translator = new Translator (
9090 storage: $ this ->getStorage (),
91- searchcodeService: new PhpParserService ([
92- $ this ->getAppPath (),
93- $ this ->getResourcesPath (),
94- ])
91+ searchcodeService: new PhpParserService (
92+ paths: [
93+ $ this ->getAppPath (),
94+ $ this ->getResourcesPath (),
95+ ],
96+ excludedPaths: $ this ->getExcludedPaths ()
97+ )
9598 );
9699
97100 $ dead = $ translator ->getDeadTranslations (
113116it ('finds all dead translations ' , function () {
114117 $ translator = new Translator (
115118 storage: $ this ->getStorage (),
116- searchcodeService: new PhpParserService ([
117- $ this ->getAppPath (),
118- $ this ->getResourcesPath (),
119- ])
119+ searchcodeService: new PhpParserService (
120+ paths: [
121+ $ this ->getAppPath (),
122+ $ this ->getResourcesPath (),
123+ ],
124+ excludedPaths: $ this ->getExcludedPaths ()
125+ )
120126 );
121127
122128 $ deadTranslations = $ translator ->getAllDeadTranslations ();
Original file line number Diff line number Diff line change 1010
1111class TestCase extends Orchestra
1212{
13+ public function getExcludedPaths (): array
14+ {
15+ return [
16+ 'ignored ' ,
17+ 'ignored.blade.php ' ,
18+ ];
19+ }
20+
1321 public function getAppPath (): string
1422 {
1523 return __DIR__ .'/src/app ' ;
Original file line number Diff line number Diff line change 2626 $ appPath ,
2727 $ resourcesPath ,
2828 ],
29+ excludedPaths: $ this ->getExcludedPaths ()
2930 );
3031
3132 expect ($ service ->translationsByFiles ())->toBe ([
5354 $ appPath ,
5455 $ resourcesPath ,
5556 ],
57+ excludedPaths: $ this ->getExcludedPaths ()
5658 );
5759
5860 expect ($ service ->filesByTranslations ())->toBe ([
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Elegantly \Translator \Tests \Src \App \Ignored ;
4+
5+ class IgnoredDummyClass
6+ {
7+ public function getLabel ()
8+ {
9+ return __ (key: 'messages.hello ' );
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ <div >
2+ {{ __ (' messages.hello' ) } }
3+ </div >
You can’t perform that action at this time.
0 commit comments