Sitemap::setLastModificationDate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Sitemap\Tags;
4
5
use Carbon\Carbon;
6
use DateTime;
7
8
class Sitemap extends Tag
9
{
10
    /** @var string */
11
    public $url = '';
12
13
    /** @var \Carbon\Carbon */
14
    public $lastModificationDate;
15
16
    public static function create(string $url): self
17
    {
18
        return new static($url);
19
    }
20
21
    public function __construct(string $url)
22
    {
23
        $this->url = $url;
24
25
        $this->lastModificationDate = Carbon::now();
26
    }
27
28
    /**
29
     * @param string $url
30
     *
31
     * @return $this
32
     */
33
    public function setUrl(string $url = '')
34
    {
35
        $this->url = $url;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param \DateTime $lastModificationDate
42
     *
43
     * @return $this
44
     */
45
    public function setLastModificationDate(DateTime $lastModificationDate)
46
    {
47
        $this->lastModificationDate = $lastModificationDate;
0 ignored issues
show
Documentation Bug introduced by
$lastModificationDate is of type object<DateTime>, but the property $lastModificationDate was declared to be of type object<Carbon\Carbon>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function path(): string
56
    {
57
        return parse_url($this->url)['path'] ?? '';
58
    }
59
}
60