Completed
Pull Request — master (#37)
by Andreas
05:11
created

Description::parse()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.2248
c 0
b 0
f 0
cc 5
nc 5
nop 2
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * Copyright Andrea Heigl <[email protected]>
6
 *
7
 * Licenses under the MIT-license. For details see the included file LICENSE.md
8
 */
9
10
namespace Callingallpapers\Subcommands\Sessionize\Parser;
11
12
use DOMDocument;
13
use DOMXPath;
14
use function preg_replace;
15
use function strip_tags;
16
17
class Description
18
{
19
    public function parse(DOMDocument $dom, DOMXPath $xpath)
20
    {
21
        $result = $xpath->query('//hr[contains(@class, "m-t-none")]');
22
        if ($result->length < 1) {
23
            return '';
24
        }
25
26
        $text = [];
27
        for ($i = 0; $i < $result->length; $i++) {
28
            $resultI = $result->item($i)->parentNode->childNodes;
29
30
            if ($resultI->length <= 0) {
31
                return '';
32
            }
33
34
            foreach ($resultI as $node) {
35
                $text[] = $dom->saveXML($node);
36
            }
37
        }
38
        $description = trim(implode('', $text));
39
        $description = preg_replace(['/\<\!\-\-.*?\-\-\>/si', '/\<script.*?\<\/script\>/si'],'', $description);
40
41
        return $description;
42
    }
43
}
44