Skip to content

Commit

Permalink
fix: fixed phpStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud217TR committed Jun 29, 2024
1 parent 5a4f99a commit 7a04f2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Commands/AutoTranslationExtractionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function handle(TranslationScanner $scanner): int

$scanner->findAndEvaluate();

app()->translator->getExtractionTranslator()->saveTranslations();
app('translator')->getExtractionTranslator()->saveTranslations();

return self::SUCCESS;
}
Expand Down
29 changes: 24 additions & 5 deletions src/TranslationScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

namespace Mahmoud217TR\AutoFilesLocalizer;

use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use SplFileInfo;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

class TranslationScanner
{
protected ?Command $command;

public function __construct(Command $command = null)
{
$this->command = $command;
}

public function findAndEvaluate(): void
{
$this->getFiles()->each(function ($file) {
Expand Down Expand Up @@ -37,10 +47,19 @@ protected function extractFunctionCalls(SplFileInfo $file, array $functions): ar
foreach ($functions as $function) {
if (preg_match_all($this->functionPattern($function), $contents, $matches)) {
$function = $matches[0][0];
if (Str::startsWith($function, '@')) {
Blade::render($function);
} else {
eval("{$function};");
try {
if (Str::startsWith($function, '@')) {
Blade::render($function);
} else {
eval("{$function};");
}
} catch (Exception $exception) {
$message = $exception->getMessage();
if (filled($this->command)) {
$this->command->error($message);
} else {
Log::error($message);
}
}
}
}
Expand Down

0 comments on commit 7a04f2d

Please sign in to comment.