| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class Data |
||
| 16 | { |
||
| 17 | private $_ip; |
||
| 18 | private $_url; |
||
| 19 | |||
| 20 | public function __construct(string $url) |
||
| 21 | { |
||
| 22 | $this->_url = $url; |
||
| 23 | $this->_ip = $this->getIp($this->_url); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Get Shodan API URL with key. |
||
| 28 | * |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | public function shodanApiUrl() |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get IPv4 address from a URL. |
||
| 39 | * |
||
| 40 | * @param string $url |
||
| 41 | * |
||
| 42 | * @return string|null |
||
| 43 | */ |
||
| 44 | public function getIp(string $url): string |
||
| 45 | { |
||
| 46 | $domain = parse_url($url)['host']; |
||
| 47 | $ip = gethostbyname($domain); |
||
| 48 | |||
| 49 | return filter_var($ip, FILTER_VALIDATE_IP) ? $ip : null; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Returns URL set when initialising Data object. |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | public function getUrl() |
||
| 60 | } |
||
| 61 | } |
||
| 62 |