|
2 | 2 |
|
3 | 3 | namespace Fidum\LaravelTranslationLinter\Parsers; |
4 | 4 |
|
5 | | -use Fidum\LaravelTranslationLinter\Contracts\Collections\ApplicationFileCollection as ApplicationFileCollectionContract; |
6 | 5 | use Fidum\LaravelTranslationLinter\Contracts\Parsers\ApplicationFileParser as ApplicationFileParserContract; |
7 | | -use Fidum\LaravelTranslationLinter\Data\ApplicationFileObject; |
8 | | -use Illuminate\Support\Str; |
| 6 | +use Illuminate\Support\Collection; |
9 | 7 | use Symfony\Component\Finder\SplFileInfo; |
10 | 8 |
|
11 | 9 | readonly class ApplicationFileParser implements ApplicationFileParserContract |
|
14 | 12 |
|
15 | 13 | protected string $pattern; |
16 | 14 |
|
17 | | - public function __construct( |
18 | | - protected ApplicationFileCollectionContract $collection, |
19 | | - array $functions |
20 | | - ) { |
| 15 | + public function __construct(array $functions) |
| 16 | + { |
21 | 17 | $this->pattern = str_replace('[FUNCTIONS]', implode('|', $functions), static::REGEX); |
22 | 18 | } |
23 | 19 |
|
24 | | - public function execute(SplFileInfo $file): ApplicationFileCollectionContract |
| 20 | + public function execute(SplFileInfo $file): Collection |
25 | 21 | { |
26 | 22 | $data = $file->getContents(); |
| 23 | + $collection = new Collection(); |
27 | 24 |
|
28 | 25 | if (! preg_match_all($this->pattern, $data, $matches, PREG_OFFSET_CAPTURE)) { |
29 | 26 | // If pattern not found return |
30 | | - return $this->collection; |
| 27 | + return $collection; |
31 | 28 | } |
32 | 29 |
|
33 | 30 | foreach (current($matches) as $match) { |
34 | 31 | preg_match($this->pattern, $match[0], $string); |
35 | 32 |
|
36 | | - $namespaceHintedKey = $string[2]; |
37 | | - |
38 | | - $this->collection->push(new ApplicationFileObject( |
39 | | - file: $file, |
40 | | - key: Str::after($namespaceHintedKey, '::') ?: null, |
41 | | - namespaceHint: Str::before($namespaceHintedKey, '::') ?: null, |
42 | | - namespaceHintedKey: $namespaceHintedKey, |
43 | | - )); |
| 33 | + $collection->push($string[2]); |
44 | 34 | } |
45 | 35 |
|
46 | 36 | // Remove duplicates. |
47 | | - return $this->collection->unique(function (ApplicationFileObject $object) { |
48 | | - return $object->namespaceHintedKey; |
49 | | - }); |
| 37 | + return $collection->unique(); |
50 | 38 | } |
51 | 39 | } |
0 commit comments