Total Complexity | 13 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | class Ping |
||
12 | { |
||
13 | /** |
||
14 | * @var Url $urlEntity |
||
15 | */ |
||
16 | private $urlEntity; |
||
17 | |||
18 | /** |
||
19 | * @var PingService |
||
20 | */ |
||
21 | private $pingService; |
||
22 | |||
23 | public function __construct($url = '') |
||
24 | { |
||
25 | $this->createUrlEntity(); |
||
26 | if ($url !== '' && filter_var($url, FILTER_VALIDATE_URL)) { |
||
27 | $this->urlEntity->addUrl($url); |
||
28 | } |
||
29 | $this->pingService = new PingService(); |
||
30 | } |
||
31 | |||
32 | private function createUrlEntity(): Url { |
||
33 | $this->urlEntity = new Url(); |
||
|
|||
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 { |
||
63 | } |
||
64 | |||
65 | private function chekcIfValidUrl(string $url) :bool { |
||
67 | } |
||
68 | |||
69 | public function ping(string $url = null) { |
||
75 | } |
||
76 | |||
77 | } |
||
78 |
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: