diff --git a/composer.json b/composer.json index da774eb..e76f429 100644 --- a/composer.json +++ b/composer.json @@ -60,8 +60,8 @@ }, "scripts": { "fixture:download": [ - "curl -o ./tests/Fixtures/vulnerabilities.production.json https://www.wordfence.com/api/intelligence/v2/vulnerabilities/production", - "curl -o ./tests/Fixtures/vulnerabilities.scanner.json https://www.wordfence.com/api/intelligence/v2/vulnerabilities/scanner" + "curl -o ./tests/Fixtures/vulnerabilities.Production.json https://www.wordfence.com/api/intelligence/v2/vulnerabilities/production", + "curl -o ./tests/Fixtures/vulnerabilities.Scanner.json https://www.wordfence.com/api/intelligence/v2/vulnerabilities/scanner" ], "lint": [ "@composer normalize --dry-run", diff --git a/src/Client.php b/src/Client.php index 731f71b..2523b4b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -49,10 +49,7 @@ public function fetch(Feed $feed): Generator private function get(Feed $feed): ResponseInterface { try { - return $this->http->request( - 'GET', - $feed->url(), - ); + return $this->http->request('GET', $feed->value); } catch (TransferException $exception) { // Guzzle throws exceptions for non-2xx responses. throw HttpException::fromResponse($feed, $exception); diff --git a/src/Exceptions/HttpException.php b/src/Exceptions/HttpException.php index 28cf19b..2faa6eb 100644 --- a/src/Exceptions/HttpException.php +++ b/src/Exceptions/HttpException.php @@ -14,7 +14,7 @@ public static function fromResponse(Feed $feed, TransferException $original): se { $message = sprintf( 'Unable to fetch from Wordfence %s feed. %s', - $feed->label(), + $feed->name, $original->getMessage(), ); diff --git a/src/Exceptions/InvalidJsonException.php b/src/Exceptions/InvalidJsonException.php index ce0a852..456b287 100644 --- a/src/Exceptions/InvalidJsonException.php +++ b/src/Exceptions/InvalidJsonException.php @@ -14,7 +14,7 @@ public static function forFeedResponse(Feed $feed): self return new self( sprintf( 'Unable to parse Wordfence %s feed response: invalid JSON', - $feed->label(), + $feed->name, ), ); } diff --git a/src/Feed.php b/src/Feed.php index 7cd633c..f13de01 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -4,24 +4,8 @@ namespace TypistTech\WordfenceApi; -enum Feed +enum Feed: string { - case Production; - case Scanner; - - public function label(): string // TODO! - { - return match ($this) { - self::Production => 'production', - self::Scanner => 'scanner', - }; - } - - public function url(): string - { - return match ($this) { - self::Production => 'https://www.wordfence.com/api/intelligence/v2/vulnerabilities/production', - self::Scanner => 'https://www.wordfence.com/api/intelligence/v2/vulnerabilities/scanner', - }; - } + case Production = 'https://www.wordfence.com/api/intelligence/v2/vulnerabilities/production'; + case Scanner = 'https://www.wordfence.com/api/intelligence/v2/vulnerabilities/scanner'; } diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 3b4ce5e..90c3a67 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -15,7 +15,7 @@ abstract class TestCase extends BaseTestCase { public function mockHttpClient(Feed $feed): Http { - $path = fixture('vulnerabilities.'.$feed->label().'.json'); // TODO! + $path = fixture("vulnerabilities.{$feed->name}.json"); $body = file_get_contents($path); $mock = new MockHandler([ diff --git a/tests/Fixtures/vulnerabilities.production.json b/tests/Fixtures/vulnerabilities.Production.json similarity index 100% rename from tests/Fixtures/vulnerabilities.production.json rename to tests/Fixtures/vulnerabilities.Production.json diff --git a/tests/Fixtures/vulnerabilities.scanner.json b/tests/Fixtures/vulnerabilities.Scanner.json similarity index 100% rename from tests/Fixtures/vulnerabilities.scanner.json rename to tests/Fixtures/vulnerabilities.Scanner.json