Page::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * @author: Denis Beliaev
4
 */
5
6
namespace DenisBeliaev\SitemapParser;
7
8
9
class Page
10
{
11
    public $links;
12
    public $base;
13
    private $html;
14
15
    /**
16
     * Page constructor.
17
     * @param $html
18
     * @param $address
19
     */
20
    public function __construct($html, $address)
21
    {
22
        $this->html = $html;
23
24
        preg_match_all("~<a\s.*?>.*?</a>~imus", $html, $matches);
25
        foreach ($matches[0] as &$match) {
26
            $match = str_replace(["\n", "\r\n"], ' ', $match);
27
            $match = preg_replace('~\s+~', ' ', $match);
28
        }
29
        $this->links = array_unique($matches[0]);
30
31
        preg_match('~<base[^>]+href=[\'"](.*?)[\'"]~i', $html, $matches);
32
        $this->base = !empty($matches[1]) ? Link::normalize($matches[1], $address) : $address;
33
    }
34
}