CrawlSubdomains   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A shouldCrawl() 0 4 1
A isSubdomainOfHost() 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 CrawlSubdomains extends CrawlProfile
9
{
10
    protected $baseUrl;
11
12
    public function __construct($baseUrl)
13
    {
14
        if (! $baseUrl instanceof UriInterface) {
15
            $baseUrl = new Uri($baseUrl);
16
        }
17
18
        $this->baseUrl = $baseUrl;
19
    }
20
21
    public function shouldCrawl(UriInterface $url): bool
22
    {
23
        return $this->isSubdomainOfHost($url);
24
    }
25
26
    public function isSubdomainOfHost(UriInterface $url): bool
27
    {
28
        return substr($url->getHost(), -strlen($this->baseUrl->getHost())) === $this->baseUrl->getHost();
29
    }
30
}
31