Parser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 9
dl 0
loc 39
rs 10
c 0
b 0
f 0
ccs 23
cts 23
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 36 3
1
<?php
2
3
namespace Fetcher;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
7
class Parser
8
{
9 3
    public function parse($content, Url $url)
10
    {
11 3
        $data = (object) array();
12
13 3
        $crawler = new Crawler($content);
14
15 3
        $data->title = (new Parser\TitleParser())->find($crawler);
16
17 3
        $imageParser = new Parser\ChainParser(
18
            array(
19 3
                new Parser\OpenGraphImageParser(),
20 3
                new Parser\ImageTagParser(),
21
            )
22 3
        );
23 3
        $data->imageUrl = $imageParser->find($crawler);
24 3
        if (null !== $data->imageUrl) {
25 2
            $data->imageUrl = (string) (new Uri($imageParser->find($crawler)))->toAbsoluteUrl($url);
26 2
        }
27
28 3
        $data->videoUrl = (new Parser\OpenGraphVideoParser())->find($crawler);
29
30 3
        $descriptionParser = new Parser\ChainParser(
31
            array(
32 3
                new Parser\OpenGraphDescriptionParser(),
33 3
                new Parser\MetaDescriptionParser(),
34
            )
35 3
        );
36 3
        $data->description = $descriptionParser->find($crawler);
37
38 3
        $data->type = (new Parser\OpenGraphTypeParser())->find($crawler);
39 3
        if (null === $data->type) {
40 2
            $data->type = 'unknown';
41 2
        }
42
43 3
        return $data;
44
    }
45
}
46