Completed
Pull Request — master (#102)
by Brent
01:20
created

CrawlUrl   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 22 6
A __construct() 0 5 1
A getId() 0 4 1
A setId() 0 4 1
1
<?php
2
3
namespace Spatie\Crawler;
4
5
use GuzzleHttp\Psr7\Uri;
6
use Psr\Http\Message\UriInterface;
7
8
class CrawlUrl
9
{
10
    /** @var \Psr\Http\Message\UriInterface */
11
    public $url;
12
13
    /** @var \Psr\Http\Message\UriInterface */
14
    public $foundOnUrl;
15
16
    /** @var int */
17
    protected $id;
18
19
    public static function create($url, $foundOnUrl = null, int $id = null)
20
    {
21
        if (! $url instanceof UriInterface) {
22
            $url = new Uri($url);
23
        }
24
25
        if ($url->getScheme() === '') {
26
            $url = $url->withScheme('http');
27
        }
28
29
        if ($foundOnUrl !== null && ! $foundOnUrl instanceof UriInterface) {
30
            $foundOnUrl = new Uri($foundOnUrl);
31
        }
32
33
        $static = new static($url, $foundOnUrl);
34
35
        if ($id !== null) {
36
            $static->setId($id);
37
        }
38
39
        return $static;
40
    }
41
42
    protected function __construct(UriInterface $url, $foundOnUrl = null)
43
    {
44
        $this->url = $url;
45
        $this->foundOnUrl = $foundOnUrl;
46
    }
47
48
    public function getId(): int
49
    {
50
        return $this->id;
51
    }
52
53
    public function setId(int $id)
54
    {
55
        $this->id = $id;
56
    }
57
}
58