Completed
Pull Request — master (#37)
by Andreas
01:31
created

Description   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 1
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php

declare(strict_types=1);
/**
 * Copyright Andrea Heigl <[email protected]>
 *
 * Licenses under the MIT-license. For details see the included file LICENSE.md
 */

namespace Callingallpapers\Subcommands\Sessionize\Parser;

use DOMDocument;
use DOMXPath;
use function preg_replace;
use function strip_tags;
use function strpos;
use function var_dump;

class Description
{
    public function parse(DOMDocument $dom, DOMXPath $xpath)
    {
        $result = $xpath->query('//hr[contains(@class, "m-t-none")]');
        if ($result->length < 1) {
            return '';
        }

        $text = [];
        for ($i = 0; $i < $result->length; $i++) {
            $resultI = $result->item($i)->parentNode->childNodes;

            if ($resultI->length <= 0) {
                continue;
            }

            foreach ($resultI as $node) {
                $nodeText = trim($dom->saveXML($node));

                if (0 !== strpos($nodeText,'<hr class="m-t-none">')) {
                    continue;
                }

                $text[] = str_replace('<hr class="m-t-none">', '', $nodeText);
            }
        }
        $description = trim(implode('', $text));
        $description = preg_replace(['/\<\!\-\-.*?\-\-\>/si', '/\<script.*?\<\/script\>/si'], '', $description);

        return $description;
    }
}