diff --git a/config/config.php b/config/config.php index eb9f565b64c77b7590a6097735d844e1246bbef8..13ad357a276c9eb79f065e66c40acc4291a6967d 100644 --- a/config/config.php +++ b/config/config.php @@ -5,5 +5,5 @@ */ return [ 'DNSDumpster_API_KEY' => env('DNSDumpster_API_KEY', ''), - 'DNSDumpster_API_URL' => env('DNSDumpster_API_URL', 'https://api.DNSDumpster.com/') -]; \ No newline at end of file + 'DNSDumpster_API_URL' => env('DNSDumpster_API_URL', 'https://api.DNSDumpster.com/'), +]; diff --git a/src/DNSDumpster.php b/src/DNSDumpster.php index 0f06b00a494275de33850e66ae9749c473e1f920..592b761cbf6c196dbe17aac6a4d9d6ae26bae306 100644 --- a/src/DNSDumpster.php +++ b/src/DNSDumpster.php @@ -1,20 +1,22 @@ apiKey = trim($options['DNSDumpster_API_KEY']); @@ -69,11 +70,12 @@ class DNSDumpster } /** - * Retrieve domain information from DNSDumpster API + * Retrieve domain information from DNSDumpster API. * - * @param string $domain The domain to lookup - * @param int $page Page number for paginated results (default: 1) + * @param string $domain The domain to lookup + * @param int $page Page number for paginated results (default: 1) * @return array The domain information + * * @throws InvalidArgumentException If domain is invalid * @throws Exception If API request fails or rate limit is exceeded */ @@ -88,7 +90,7 @@ class DNSDumpster $data = $this->makeApiRequest($domain, $page); $this->updateRateLimit(); - + return $data; } @@ -98,17 +100,17 @@ class DNSDumpster * This private method checks if the given domain string is not empty and is a valid domain name. * If the domain is invalid, an InvalidArgumentException is thrown. * - * @param string $domain The domain to validate. + * @param string $domain The domain to validate. + * * @throws InvalidArgumentException If the domain is invalid. */ private function validateDomain(string $domain): void { - if (empty($domain) || !filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) { + if (empty($domain) || ! filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) { throw new InvalidArgumentException('Invalid domain provided'); } } - /** * Makes an API request to the DNSDumpster service to retrieve domain information. * @@ -116,9 +118,10 @@ class DNSDumpster * and handles any errors that may occur during the request. If the request is successful, the * response data is returned as an array. * - * @param string $domain The domain to look up. - * @param int $page The page number for paginated results. + * @param string $domain The domain to look up. + * @param int $page The page number for paginated results. * @return array The domain information retrieved from the API. + * * @throws Exception If the API request fails or the rate limit is exceeded. */ private function makeApiRequest(string $domain, int $page): array @@ -128,11 +131,11 @@ class DNSDumpster $response = Http::withHeaders([ 'X-API-Key' => $this->apiKey, - 'Accept' => 'application/json' + 'Accept' => 'application/json', ]) ->timeout(self::REQUEST_TIMEOUT) ->retry(self::RETRY_ATTEMPTS, self::RETRY_DELAY, function ($exception) { - return $exception instanceof ConnectionException || + return $exception instanceof ConnectionException || $exception instanceof RequestException; }) ->get($url); @@ -145,8 +148,8 @@ class DNSDumpster throw new Exception('Rate limit exceeded'); } - throw new Exception(sprintf('API request failed with status %d: %s', - $statusCode, + throw new Exception(sprintf('API request failed with status %d: %s', + $statusCode, $errorMessage )); } diff --git a/src/DNSDumpsterFacade.php b/src/DNSDumpsterFacade.php index 75afe3f549173fc7c61181c8f15dc67cbcbf7e14..aecec2758726c4f744fb6385a3668cb1967125a3 100644 --- a/src/DNSDumpsterFacade.php +++ b/src/DNSDumpsterFacade.php @@ -1,4 +1,5 @@ Http::response([ 'domain' => 'google.com', - 'data' => ['mocked data'] - ], 200) + 'data' => ['mocked data'], + ], 200), ]); $dnsDumpster = new DNSDumpster(config('DNSDumpster')); @@ -78,8 +77,8 @@ class DNSDumpsterTest extends TestCase // Mock the API failure (e.g., rate limit exceeded) Http::fake([ 'https://api.dnsdumpster.com/domain/google.com*' => Http::response([ - 'error' => 'Rate limit exceeded' - ], 429) + 'error' => 'Rate limit exceeded', + ], 429), ]); $dnsDumpster = new DNSDumpster(config('DNSDumpster')); diff --git a/tests/TestCase.php b/tests/TestCase.php index 61220ff5941f5b671a9ca73ef42d4b048c86172e..ee946b3984d5e859fbc55b32690a236c134b15ca 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,12 +2,11 @@ namespace Ngfw\DNSDumpster\Tests; -use Orchestra\Testbench\TestCase as BaseTestCase; use Ngfw\DNSDumpster\DNSDumpsterServiceProvider; +use Orchestra\Testbench\TestCase as BaseTestCase; /** - * Class TestCase - * @package Ngfw\DNSDumpster\Tests + * Class TestCase. */ class TestCase extends BaseTestCase {