In this branch, the function will implicitly return null which is incompatible with the type-hinted return Zwarthoorn\Ping\Entity\Url. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type.
Let?s take a look at an example:
interfaceReturnsInt{publicfunctionreturnsIntHinted():int;}classMyClassimplementsReturnsInt{publicfunctionreturnsIntHinted():int{if(foo()){return123;}// here: null is implicitly returned}}
Loading history...
34
}
35
36
public function addUrl(string $url): self {
37
38
if ($this->chekcIfValidUrl($url) === false) {
39
throw new \RuntimeException('Not a good url.');
40
}
41
42
$this->urlEntity->addUrl($url);
43
return $this;
44
}
45
46
public function addMultipleUrls(array $urlArray): self {
47
foreach ($urlArray as $url){
48
$this->addUrl($url);
49
}
50
51
return $this;
52
}
53
54
public function removeUrl($url): self {
55
if ($url === null)
56
{
57
throw new RuntimeException('There is no url supplied');
58
}
59
60
$this->urlEntity->removeUrl($url);
61
62
return $this;
63
}
64
65
private function chekcIfValidUrl(string $url) :bool {
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: