SourcesPull::handle()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 4
nop 0
dl 0
loc 14
ccs 0
cts 11
cp 0
crap 30
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace IproSync\Jobs\Settings;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Foundation\Bus\Dispatchable;
8
use Illuminate\Queue\InteractsWithQueue;
9
use Illuminate\Queue\SerializesModels;
10
use IproSync\Models\Source;
11
use LaravelIproSoftwareApi\IproSoftwareFacade;
12
13
class SourcesPull implements ShouldQueue
14
{
15
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by IproSync\Jobs\Settings\SourcesPull: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
16
17
    public function handle()
18
    {
19
        $response = IproSoftwareFacade::getSourcesList()->onlySuccessful();
20
21
        $items = $response->json();
22
        if (is_array($items) && !empty($items)) {
23
            foreach ($items as $item) {
24
                if (!isset($item['Id'])) {
25
                    continue;
26
                }
27
                Source::firstOrNew(['id' => $item['Id']], )
28
                      ->fill(['name' => $item['Name']])
29
                      ->fillPulled()
30
                      ->save();
31
            }
32
        }
33
    }
34
}
35