Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dmason30 committed Oct 6, 2023
1 parent f22a2d9 commit bf06754
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Collection;
use Symfony\Component\Finder\SplFileInfo;

interface Parser
interface ApplicationFileParser
{
public function execute(SplFileInfo $file): Collection;
}
16 changes: 8 additions & 8 deletions src/LaravelTranslationLinterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
});
Expand All @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions src/Parsers/Parser.php → src/Parsers/ApplicationFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/Readers/ApplicationFileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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;

class ApplicationFileReader implements ApplicationFileReaderContract
{
public function __construct(
protected ApplicationFileFinder $finder,
protected Parser $parser,
protected ApplicationFileParser $parser,
) {}

public function execute(): Collection
Expand Down

0 comments on commit bf06754

Please sign in to comment.