GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( a93cc2...4d85e3 )
by Gabor
02:13
created

GenerateCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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 LokaliseClient */
14
    private $lokaliseClient;
15
16
    public function __construct(LokaliseClient $lokaliseClient)
17
    {
18
        parent::__construct();
19
        $this->lokaliseClient = $lokaliseClient;
20
    }
21
22
    public function handle(): void
23
    {
24
        $translatables = (new SearchService())->getTranslatableStrings(config('translation.generator.patterns'));
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $translatables = (new SearchService())->getTranslatableStrings(/** @scrutinizer ignore-call */ config('translation.generator.patterns'));
Loading history...
25
26
        $lang = $this->argument('lang');
27
        $fileName = 'resources/lang/'.$lang.'.json';
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

27
        $fileName = 'resources/lang/'./** @scrutinizer ignore-type */ $lang.'.json';
Loading history...
28
        $jsonFile = file_get_contents($fileName);
29
        $translations = json_decode($jsonFile, true);
30
31
        foreach ($translatables as $translatable) {
32
            $translatable = str_replace('\\', '', $translatable);
33
            if (!array_key_exists($translatable, $translations)) {
34
                $translations[$translatable] = $translatable;
35
            }
36
        }
37
38
        $content = json_encode($translations, JSON_PRETTY_PRINT + JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
39
        file_put_contents($fileName, $content);
40
41
        $isUpload = $this->option('upload');
42
        if ($isUpload && $this->lokaliseClient->isReady()) {
43
            $this->lokaliseClient->uploadFile($content, $fileName, $lang);
0 ignored issues
show
Bug introduced by
It seems like $lang can also be of type null and string[]; however, parameter $langIso of ProcyonWeb\TranslationGe...iseClient::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 ignore-type  annotation

43
            $this->lokaliseClient->uploadFile($content, $fileName, /** @scrutinizer ignore-type */ $lang);
Loading history...
44
        }
45
    }
46
}