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

CrawlUrl::create()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 8.8571
cc 5
eloc 9
nc 8
nop 3
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 ($foundOnUrl !== null && ! $foundOnUrl instanceof UriInterface) {
26
            $foundOnUrl = new Uri($foundOnUrl);
27
        }
28
29
        $static = new static($url, $foundOnUrl);
30
31
        if ($id !== null) {
32
            $static->setId($id);
33
        }
34
35
        return $static;
36
    }
37
38
    protected function __construct(UriInterface $url, $foundOnUrl = null)
39
    {
40
        $this->url = $url;
41
        $this->foundOnUrl = $foundOnUrl;
42
    }
43
44
    public function getId(): int
45
    {
46
        return $this->id;
47
    }
48
49
    public function setId(int $id)
50
    {
51
        $this->id = $id;
52
    }
53
}
54