1 | <?php |
||
19 | class ServersArePingable extends BaseServersArePingable implements Check |
||
20 | { |
||
21 | /** |
||
22 | * Perform the actual verification of this check. |
||
23 | * |
||
24 | * @param array $config |
||
25 | * @return bool |
||
26 | * @throws \BeyondCode\SelfDiagnosis\Exceptions\InvalidConfigurationException |
||
27 | */ |
||
28 | public function check(array $config): bool |
||
29 | { |
||
30 | $this->notReachableServers = $this->parseConfiguredServers(Arr::get($config, 'servers', [])); |
||
31 | if ($this->notReachableServers->isEmpty()) { |
||
32 | return true; |
||
33 | } |
||
34 | |||
35 | $this->notReachableServers = $this->notReachableServers->reject(static function (Server $server) { |
||
36 | $ping = new Ping($server->getHost()); |
||
37 | $ping->setPort($server->getPort()); |
||
38 | $ping->setTimeout($server->getTimeout()); |
||
39 | |||
40 | if ($ping->getPort() === null) { |
||
41 | $latency = $ping->ping('exec'); |
||
42 | } else { |
||
43 | $latency = $ping->ping('fsockopen'); |
||
44 | } |
||
45 | |||
46 | return $latency !== false; |
||
47 | }); |
||
48 | |||
49 | return $this->notReachableServers->isEmpty(); |
||
50 | } |
||
51 | |||
52 | private function parseConfiguredServers(array $servers): Collection |
||
84 | } |
||
85 |
Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.