| Total Complexity | 9 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 17 | class Shodan |
||
| 18 | { |
||
| 19 | private $_url; |
||
| 20 | |||
| 21 | private $_results; |
||
| 22 | |||
| 23 | private $_data; |
||
| 24 | |||
| 25 | 6 | public function __construct() |
|
| 26 | { |
||
| 27 | 6 | $this->_results = null; |
|
| 28 | 6 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Add URL to be checked with Shodan API. |
||
| 32 | * |
||
| 33 | * @param string $url The URL to be checked. |
||
| 34 | * |
||
| 35 | * @return Shodan. |
||
| 36 | */ |
||
| 37 | 4 | public function setUrl(string $url) |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Checks a given URL with Shodan API. |
||
| 47 | * |
||
| 48 | * @throws ErrorException |
||
| 49 | * |
||
| 50 | * @return Shodan |
||
| 51 | */ |
||
| 52 | 2 | public function check() |
|
| 53 | { |
||
| 54 | $error = [ |
||
| 55 | 2 | 'status' => 500, |
|
| 56 | 'response' => 'URL cannot be null.', |
||
| 57 | ]; |
||
| 58 | |||
| 59 | 2 | $this->_results = empty($this->getUrl()) || empty($this->_data) ? |
|
| 60 | 2 | $error : (new Curl($this->_data))->getData(); |
|
| 61 | |||
| 62 | 2 | return $this; |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Get current URL. |
||
| 67 | * |
||
| 68 | * @return string|null |
||
| 69 | */ |
||
| 70 | 4 | public function getUrl() |
|
| 71 | { |
||
| 72 | 4 | return $this->_url; |
|
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Get results of Shodan API call. |
||
| 77 | * |
||
| 78 | * @param bool $jsonEncode Encode results as JSON, or |
||
| 79 | * return as associative array. |
||
| 80 | * |
||
| 81 | * @return mixed|null |
||
| 82 | */ |
||
| 83 | 3 | public function getResults(bool $jsonEncode = false) |
|
| 91 | } |
||
| 92 | } |
||
| 93 |