Completed
Pull Request — master (#223)
by Andrzej
06:09 queued 04:56
created

CrawlProfile::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Crawler;
4
5
use GuzzleHttp\Psr7\Uri;
6
use Psr\Http\Message\UriInterface;
7
8
abstract class CrawlProfile
9
{
10
    /**
11
     * @var \Psr\Http\Message\UriInterface
12
     */
13
    protected $baseUrl;
14
15
    /**
16
     * @param \Psr\Http\Message\UriInterface|string|null $baseUrl
17
     */
18
    public function __construct($baseUrl = '')
19
    {
20
        if (! $baseUrl instanceof UriInterface) {
21
            $baseUrl = new Uri($baseUrl);
22
        }
23
24
        $this->baseUrl = $baseUrl;
25
    }
26
27
    /**
28
     * Return url associated with the profile.
29
     *
30
     * @return \Psr\Http\Message\UriInterface
31
     */
32
    public function getBaseUrl(): UriInterface
33
    {
34
        return $this->baseUrl;
35
    }
36
37
    /**
38
     * Determine if the given url should be crawled.
39
     *
40
     * @param \Psr\Http\Message\UriInterface $url
41
     *
42
     * @return bool
43
     */
44
    abstract public function shouldCrawl(UriInterface $url): bool;
45
}
46