XmlFeedPull::pull()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace ExternalFeedParser\Pull;
4
5
use ExternalFeedParser\Contracts\PullProcessor;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Collection;
8
use Mtownsend\XmlToArray\XmlToArray;
9
10
class XmlFeedPull implements PullProcessor
11
{
12
    use HasPendingRequest;
13
14 1
    public function __construct(
15
        protected string  $url,
16
        protected ?string $listingKey = null,
17
        array             $args = [],
18
    ) {
19 1
        $this->args = collect($args);
20 1
    }
21
22
23 1
    public function pull(): Collection
24
    {
25 1
        $response = $this->preparePendingRequest()->get($this->url);
26
27 1
        $array = XmlToArray::convert($response->body());
28
29 1
        $data = $this->listingKey ? Arr::get($array, $this->listingKey, []) : $array;
30
31 1
        return collect($data);
32
    }
33
}
34