1 | <?php |
||||
2 | |||||
3 | |||||
4 | namespace Zwarthoorn\Ping\Service; |
||||
5 | |||||
6 | |||||
7 | use Zwarthoorn\Ping\Entity\Result; |
||||
8 | use Zwarthoorn\Ping\Entity\Url; |
||||
9 | |||||
10 | class PingService |
||||
11 | { |
||||
12 | public function ping(Url $urlEntity): array { |
||||
13 | $urls = $urlEntity->getUrl(); |
||||
14 | $result = []; |
||||
15 | foreach ($urls as $iValue) { |
||||
16 | $result[] = $this->pingSingle($iValue); |
||||
17 | } |
||||
18 | |||||
19 | return $result; |
||||
20 | } |
||||
21 | |||||
22 | public function pingSingle(string $url): Result{ |
||||
23 | $result = new Result(); |
||||
24 | return $result |
||||
25 | ->setResult($this->pingHandler($url)) |
||||
26 | ->setUrl($url); |
||||
27 | } |
||||
28 | |||||
29 | private function pingHandler(string $url): bool { |
||||
30 | |||||
31 | $ch = curl_init($url); |
||||
32 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
33 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); |
||||
34 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
35 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||||
0 ignored issues
–
show
It seems like
$ch can also be of type false ; however, parameter $ch of curl_getinfo() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
36 | curl_close($ch); |
||||
0 ignored issues
–
show
It seems like
$ch can also be of type false ; however, parameter $ch of curl_close() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
37 | |||||
38 | return $httpcode >= 200 && $httpcode < 300; |
||||
39 | } |
||||
40 | } |