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 43
43
'searchcode ' => [
44
44
'service ' => 'php-parser ' ,
45
45
46
- 'services ' => [
47
- 'php-parser ' => [
48
- 'paths ' => [
49
- app_path (),
50
- resource_path (),
51
- ],
52
- ],
46
+ 'paths ' => [
47
+ app_path (),
48
+ resource_path (),
53
49
],
50
+
51
+ 'excluded_paths ' => [],
52
+
54
53
],
55
54
56
55
];
Original file line number Diff line number Diff line change 15
15
class PhpParserService implements SearchCodeServiceInterface
16
16
{
17
17
public function __construct (
18
- public array $ paths
18
+ public array $ paths ,
19
+ public array $ excludedPaths = [],
19
20
) {
20
21
//
21
22
}
@@ -24,13 +25,16 @@ public function finder(): Finder
24
25
{
25
26
return Finder::create ()
26
27
->in ($ this ->paths )
27
- ->followLinks ()
28
+ // ->exclude($this->excludedPaths)
29
+ ->notPath ($ this ->excludedPaths )
30
+ ->exclude ('vendor ' )
31
+ ->exclude ('node_modules ' )
28
32
->ignoreDotFiles (true )
29
33
->ignoreVCS (true )
34
+ ->ignoreVCSIgnored (true )
30
35
->ignoreUnreadableDirs (true )
31
- ->exclude ('vendor ' )
32
- ->exclude ('node_modules ' )
33
36
->name ('*.php ' )
37
+ ->followLinks ()
34
38
->files ();
35
39
}
36
40
Original file line number Diff line number Diff line change @@ -91,7 +91,8 @@ public static function getSearchcodeServiceFromConfig(?string $serviceName = nul
91
91
92
92
return match ($ service ) {
93
93
'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 ' , [])
95
96
),
96
97
'' , null => null ,
97
98
default => new $ service ,
Original file line number Diff line number Diff line change 88
88
it ('finds dead translations in a namespace ' , function () {
89
89
$ translator = new Translator (
90
90
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
+ )
95
98
);
96
99
97
100
$ dead = $ translator ->getDeadTranslations (
113
116
it ('finds all dead translations ' , function () {
114
117
$ translator = new Translator (
115
118
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
+ )
120
126
);
121
127
122
128
$ deadTranslations = $ translator ->getAllDeadTranslations ();
Original file line number Diff line number Diff line change 10
10
11
11
class TestCase extends Orchestra
12
12
{
13
+ public function getExcludedPaths (): array
14
+ {
15
+ return [
16
+ 'ignored ' ,
17
+ 'ignored.blade.php ' ,
18
+ ];
19
+ }
20
+
13
21
public function getAppPath (): string
14
22
{
15
23
return __DIR__ .'/src/app ' ;
Original file line number Diff line number Diff line change 26
26
$ appPath ,
27
27
$ resourcesPath ,
28
28
],
29
+ excludedPaths: $ this ->getExcludedPaths ()
29
30
);
30
31
31
32
expect ($ service ->translationsByFiles ())->toBe ([
53
54
$ appPath ,
54
55
$ resourcesPath ,
55
56
],
57
+ excludedPaths: $ this ->getExcludedPaths ()
56
58
);
57
59
58
60
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