Fetcher::fetch()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 4
nc 2
nop 1
1
<?php
2
3
namespace Fetcher;
4
5
class Fetcher
6
{
7
    public function fetch(Url $url)
8
    {
9
        if ($url->isImage()) {
10
            return new Resource(
11
                $url,
12
                '',
13
                '',
14
                $url,
15
                null,
16
                'image'
17
            );
18
        }
19
20
        $browser = new \Buzz\Browser(new \Buzz\Client\Curl());
21
        $response = $browser->get((string) $url);
22
23
        $parsedData = (new Parser())->parse($response->getContent(), $url);
24
25
        return new Resource(
26
            $url,
27
            $parsedData->title,
28
            $parsedData->description,
29
            (null !== $parsedData->imageUrl) ? new Url($parsedData->imageUrl) : null,
30
            (null !== $parsedData->videoUrl) ? new Url($parsedData->videoUrl) : null,
31
            $parsedData->type
32
        );
33
    }
34
}
35