1 | <?php declare(strict_types=1); |
||||
2 | |||||
3 | namespace ProcyonWeb\TranslationGenerator; |
||||
4 | |||||
5 | use Illuminate\Console\Command; |
||||
6 | |||||
7 | class GenerateCommand extends Command |
||||
8 | { |
||||
9 | protected $signature = 'translation:generate {lang=en} {--upload}'; |
||||
10 | |||||
11 | protected $description = 'Generate missing translation strings in php and Vue files'; |
||||
12 | |||||
13 | /** @var PhraseClient */ |
||||
14 | private $client; |
||||
15 | |||||
16 | public function __construct(PhraseClient $client) |
||||
17 | { |
||||
18 | parent::__construct(); |
||||
19 | $this->client = $client; |
||||
20 | } |
||||
21 | |||||
22 | public function handle(): void |
||||
23 | { |
||||
24 | $translatables = (new SearchService())->getTranslatableStrings(config('translation.generator.patterns')); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
25 | $this->client->downloadFiles(); |
||||
26 | |||||
27 | $lang = $this->argument('lang'); |
||||
28 | $fileName = 'resources/lang/' . $lang . '.json'; |
||||
0 ignored issues
–
show
Are you sure
$lang of type null|string|string[] can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
29 | $jsonFile = file_get_contents($fileName); |
||||
30 | $translations = json_decode($jsonFile, true); |
||||
31 | |||||
32 | foreach ($translatables as $translatable) { |
||||
33 | $translatable = str_replace('\\', '', $translatable); |
||||
34 | if (!array_key_exists($translatable, $translations)) { |
||||
35 | $translations[$translatable] = $translatable; |
||||
36 | } |
||||
37 | } |
||||
38 | |||||
39 | $content = json_encode($translations, JSON_PRETTY_PRINT + JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES); |
||||
40 | file_put_contents($fileName, $content); |
||||
41 | |||||
42 | $isUpload = $this->option('upload'); |
||||
43 | if ($isUpload && $this->client->isReady()) { |
||||
44 | $this->client->uploadFile($content, $fileName, $lang); |
||||
0 ignored issues
–
show
It seems like
$lang can also be of type null and string[] ; however, parameter $langIso of ProcyonWeb\TranslationGe...aseClient::uploadFile() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
45 | } |
||||
46 | } |
||||
47 | } |