Completed
Pull Request — master (#237)
by Benjamin
01:16
created

CrawlUrl::getAttempts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Crawler;
4
5
use Psr\Http\Message\UriInterface;
6
7
class CrawlUrl
8
{
9
    /** @var \Psr\Http\Message\UriInterface */
10
    public $url;
11
12
    /** @var \Psr\Http\Message\UriInterface */
13
    public $foundOnUrl;
14
15
    /** @var mixed */
16
    protected $id;
17
18
    /** @var int */
19
    protected $attempts = 0;
20
21
    public static function create(UriInterface $url, ?UriInterface $foundOnUrl = null, $id = null)
22
    {
23
        $static = new static($url, $foundOnUrl);
24
25
        if ($id !== null) {
26
            $static->setId($id);
27
        }
28
29
        return $static;
30
    }
31
32
    protected function __construct(UriInterface $url, $foundOnUrl = null)
33
    {
34
        $this->url = $url;
35
        $this->foundOnUrl = $foundOnUrl;
36
    }
37
38
    /**
39
     * @return mixed|null
40
     */
41
    public function getId()
42
    {
43
        return $this->id;
44
    }
45
46
    public function setId($id)
47
    {
48
        $this->id = $id;
49
    }
50
51
    /**
52
     * Returns the number of attempts to load this URL.
53
     *
54
     * @return int
55
     */
56
    public function getAttempts() : int
57
    {
58
        return $this->attempts;
59
    }
60
61
    /**
62
     * @return void
63
     */
64
    public function incrementAttempts()
65
    {
66
        $this->attempts++;
67
    }
68
}
69