LangPush   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 26.32%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 67
ccs 5
cts 19
cp 0.2632
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 31 1
A __construct() 0 5 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Console\Command;
7
8
class LangPush extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'lang:push';
16
17
    protected $apikey;
18
    protected $project;
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Send translations to lokalise.co';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32 52
    public function __construct()
33
    {
34 52
        parent::__construct();
35 52
        $this->apikey = env('LOCALISE_API_KEY');
36 52
        $this->project = env('LOCALISE_PROJECT');
37 52
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @return mixed
43
     */
44
    public function handle()
45
    {
46
        $client = new Client(['verify' => false]);
47
        $file = file_get_contents('./resources/lang/en/app.php');
48
        $response = $client->request('POST', 'https://api.lokalise.co/api/project/import', [
49
            'multipart' => [
50
                [
51
                    'name' => 'api_token',
52
                    'contents' => $this->apikey
53
                ],
54
                [
55
                    'name' => 'id',
56
                    'contents' => $this->project
57
                ],
58
                [
59
                    'name' => 'replace',
60
                    'contents' => '1'
61
                ],
62
                [
63
                    'name' => 'lang_iso',
64
                    'contents' => 'en'
65
                ],
66
                [
67
                    'name' => 'file',
68
                    'contents' => $file,
69
                    'filename' => 'app.php',
70
                ]
71
            ]]);
72
        $body = $response->getBody();
73
74
        echo $body;
75
76
    }
77
}
78