From bf0675413035023cbf9098868c553993888faadc Mon Sep 17 00:00:00 2001 From: dmason30 Date: Fri, 6 Oct 2023 11:46:34 +0100 Subject: [PATCH] wip --- .../{Parser.php => ApplicationFileParser.php} | 2 +- src/LaravelTranslationLinterServiceProvider.php | 16 ++++++++-------- .../{Parser.php => ApplicationFileParser.php} | 11 +++++------ src/Readers/ApplicationFileReader.php | 4 ++-- 4 files changed, 16 insertions(+), 17 deletions(-) rename src/Contracts/Parsers/{Parser.php => ApplicationFileParser.php} (86%) rename src/Parsers/{Parser.php => ApplicationFileParser.php} (70%) diff --git a/src/Contracts/Parsers/Parser.php b/src/Contracts/Parsers/ApplicationFileParser.php similarity index 86% rename from src/Contracts/Parsers/Parser.php rename to src/Contracts/Parsers/ApplicationFileParser.php index 004bd50..cca4003 100644 --- a/src/Contracts/Parsers/Parser.php +++ b/src/Contracts/Parsers/ApplicationFileParser.php @@ -5,7 +5,7 @@ use Illuminate\Support\Collection; use Symfony\Component\Finder\SplFileInfo; -interface Parser +interface ApplicationFileParser { public function execute(SplFileInfo $file): Collection; } diff --git a/src/LaravelTranslationLinterServiceProvider.php b/src/LaravelTranslationLinterServiceProvider.php index e904912..d78975f 100644 --- a/src/LaravelTranslationLinterServiceProvider.php +++ b/src/LaravelTranslationLinterServiceProvider.php @@ -13,14 +13,14 @@ use Fidum\LaravelTranslationLinter\Contracts\Finders\LanguageFileFinder as LanguageFileFinderContract; use Fidum\LaravelTranslationLinter\Contracts\Finders\LanguageNamespaceFinder as LanguageNamespaceFinderContract; use Fidum\LaravelTranslationLinter\Contracts\Linters\UnusedTranslationLinter as UnusedTranslationLinterContract; -use Fidum\LaravelTranslationLinter\Contracts\Parsers\Parser as ParserContract; +use Fidum\LaravelTranslationLinter\Contracts\Parsers\ApplicationFileParser as ApplicationFileParserContract; use Fidum\LaravelTranslationLinter\Contracts\Readers\ApplicationFileReader as ApplicationFileReaderContract; use Fidum\LaravelTranslationLinter\Contracts\Readers\LanguageFileReader as LanguageFileReaderContract; use Fidum\LaravelTranslationLinter\Finders\ApplicationFileFinder; use Fidum\LaravelTranslationLinter\Finders\LanguageFileFinder; use Fidum\LaravelTranslationLinter\Finders\LanguageNamespaceFinder; use Fidum\LaravelTranslationLinter\Linters\UnusedTranslationLinter; -use Fidum\LaravelTranslationLinter\Parsers\Parser; +use Fidum\LaravelTranslationLinter\Parsers\ApplicationFileParser; use Fidum\LaravelTranslationLinter\Readers\ApplicationFileReader; use Fidum\LaravelTranslationLinter\Readers\LanguageFileReader; use Illuminate\Contracts\Support\DeferrableProvider; @@ -50,16 +50,16 @@ public function registeringPackage() ->needs('$extensions') ->giveConfig('translation-linter.application.extensions'); + $this->app->bind(ApplicationFileParserContract::class, ApplicationFileParser::class); + $this->app->when(ApplicationFileParser::class) + ->needs('$functions') + ->giveConfig('translation-linter.lang.functions'); + $this->app->bind(ApplicationFileReaderContract::class, ApplicationFileReader::class); $this->app->bind(LanguageFileFinderContract::class, LanguageFileFinder::class); $this->app->bind(LanguageFileReaderContract::class, LanguageFileReader::class); $this->app->bind(LanguageNamespaceFinderContract::class, LanguageNamespaceFinder::class); - $this->app->bind(ParserContract::class, Parser::class); - $this->app->when(Parser::class) - ->needs('$functions') - ->giveConfig('translation-linter.lang.functions'); - $this->app->bind(UnusedFieldCollectionContract::class, function (Application $app) { return UnusedFieldCollection::wrap($app->make('config')->get('translation-linter.unused.fields')); }); @@ -79,11 +79,11 @@ public function provides() { return [ ApplicationFileFinderContract::class, + ApplicationFileParserContract::class, ApplicationFileReaderContract::class, LanguageFileFinderContract::class, LanguageFileReaderContract::class, LanguageNamespaceFinderContract::class, - ParserContract::class, UnusedFieldCollectionContract::class, UnusedFilterCollectionContract::class, UnusedResultCollectionContract::class, diff --git a/src/Parsers/Parser.php b/src/Parsers/ApplicationFileParser.php similarity index 70% rename from src/Parsers/Parser.php rename to src/Parsers/ApplicationFileParser.php index caa0e8b..316b059 100644 --- a/src/Parsers/Parser.php +++ b/src/Parsers/ApplicationFileParser.php @@ -2,25 +2,24 @@ namespace Fidum\LaravelTranslationLinter\Parsers; -use Fidum\LaravelTranslationLinter\Contracts\Parsers\Parser as ParserContract; +use Fidum\LaravelTranslationLinter\Contracts\Parsers\ApplicationFileParser as ApplicationFileParserContract; use Illuminate\Support\Collection; use Symfony\Component\Finder\SplFileInfo; -readonly class Parser implements ParserContract +readonly class ApplicationFileParser implements ApplicationFileParserContract { - protected string $regex; + protected const REGEX = '/([FUNCTIONS])\([\t\r\n\s]*[\'"](.+)[\'"][\),\t\r\n\s]/U'; protected string $pattern; public function __construct(array $functions) { - $this->regex = '/([FUNCTIONS])\([\t\r\n\s]*[\'"](.+)[\'"][\),\t\r\n\s]/U'; - $this->pattern = str_replace('[FUNCTIONS]', implode('|', $functions), $this->regex); + $this->pattern = str_replace('[FUNCTIONS]', implode('|', $functions), static::REGEX); } public function execute(SplFileInfo $file): Collection { - $strings = collect(); + $strings = new Collection(); $data = $file->getContents(); diff --git a/src/Readers/ApplicationFileReader.php b/src/Readers/ApplicationFileReader.php index 62b07d0..c5301ab 100644 --- a/src/Readers/ApplicationFileReader.php +++ b/src/Readers/ApplicationFileReader.php @@ -3,7 +3,7 @@ namespace Fidum\LaravelTranslationLinter\Readers; use Fidum\LaravelTranslationLinter\Contracts\Finders\ApplicationFileFinder; -use Fidum\LaravelTranslationLinter\Contracts\Parsers\Parser; +use Fidum\LaravelTranslationLinter\Contracts\Parsers\ApplicationFileParser; use Fidum\LaravelTranslationLinter\Contracts\Readers\ApplicationFileReader as ApplicationFileReaderContract; use Illuminate\Support\Collection; @@ -11,7 +11,7 @@ class ApplicationFileReader implements ApplicationFileReaderContract { public function __construct( protected ApplicationFileFinder $finder, - protected Parser $parser, + protected ApplicationFileParser $parser, ) {} public function execute(): Collection