Completed
Pull Request — master (#77)
by
unknown
01:25
created

CrawlInternalWithSubdomainUrls::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Crawler;
4
5
class CrawlInternalWithSubdomainUrls implements CrawlProfile
6
{
7
    protected $host = '';
8
9
    public function __construct(string $baseUrl)
10
    {
11
        $this->host = parse_url($baseUrl, PHP_URL_HOST);
0 ignored issues
show
Documentation Bug introduced by
It seems like parse_url($baseUrl, PHP_URL_HOST) can also be of type false. However, the property $host is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
12
    }
13
14
    public function shouldCrawl(Url $url): bool
15
    {
16
        return substr($url->host, -strlen($this->host)) === $this->host;
17
    }
18
}
19