| Total Complexity | 14 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class IpValidator |
||
| 6 | { |
||
| 7 | private $ipAddr; |
||
| 8 | private $payload = []; |
||
| 9 | |||
| 10 | public function __construct($ipAddr = null) |
||
| 11 | { |
||
| 12 | $this->setIp($ipAddr); |
||
| 13 | } |
||
| 14 | |||
| 15 | public function setIp($ipAddr = null) |
||
| 16 | { |
||
| 17 | $this->ipAddr = empty($ipAddr) ? 'Invalid' : $ipAddr; |
||
| 18 | |||
| 19 | return $this; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getIp() |
||
| 23 | { |
||
| 24 | return $this->ipAddr; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function getPayload() |
||
| 28 | { |
||
| 29 | return $this->payload; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function validate() |
||
| 41 | } |
||
| 42 | |||
| 43 | public function getHostName() |
||
| 44 | { |
||
| 45 | // make sure we got a valid IP otherwise gethostbyaddr() throws an error |
||
| 46 | if (! $this->getProtocolType()) { |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | $ipAddr = $this->getIp(); |
||
| 51 | $host = gethostbyaddr($ipAddr); |
||
| 52 | |||
| 53 | return $host === $ipAddr ? false : $host; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function getProtocolType() |
||
| 67 | } |
||
| 68 | } |
||
| 69 |