| Conditions | 3 |
| Paths | 4 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |