WriteCsv   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 13 1
1
<?php
2
3
namespace LWS\ExportActions\Jobs;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Http\Request;
7
use Illuminate\Bus\Queueable;
8
use SoapBox\Formatter\Formatter;
9
use Illuminate\Queue\SerializesModels;
10
use Illuminate\Support\Facades\Storage;
11
use Illuminate\Queue\InteractsWithQueue;
12
use Illuminate\Contracts\Queue\ShouldQueue;
13
use Illuminate\Foundation\Bus\Dispatchable;
14
15
class WriteCsv implements ShouldQueue
16
{
17
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by LWS\ExportActions\Jobs\WriteCsv: $id, $relations, $class, $keyBy
Loading history...
18
19
    protected $request;
20
21
    public $timeout = 120;
22
23
    /**
24
     * Create a new job instance.
25
     *
26
     * @return void
27
     */
28
    public function __construct(Request $request)
29
    {
30
        $this->requestData = $request->all();
0 ignored issues
show
Bug Best Practice introduced by
The property requestData does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
    }
32
33
    /**
34
     * Execute the job.
35
     *
36
     * @return void
37
     */
38
    public function handle()
39
    {
40
        $client = new Client();
41
42
        $request = new \GuzzleHttp\Psr7\Request('GET', $this->requestData->url);
43
        $promise = $client->sendAsync($request)->then(function ($responseData) {
44
            $formatter = Formatter::make($responseData->getBody(), Formatter::JSON);
45
            $csv = $formatter->toCsv();
46
47
            Storage::disk('local')->put('csvfile.csv', $csv);
48
        });
49
50
        $promise->wait();
51
    }
52
}
53