diff --git a/.gitignore b/.gitignore index da6bcd7..f363432 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.idea /.*.cache /.env.local +/build /composer.lock /tmp /vendor diff --git a/src/Akismet.php b/src/Akismet.php index bd762db..5c509aa 100644 --- a/src/Akismet.php +++ b/src/Akismet.php @@ -33,18 +33,18 @@ class Akismet implements LoggerAwareInterface private ?string $instance; private bool $isTesting; - public function __construct(HttpClientInterface $client, string $apiKey = null, string $instance = null, bool $isTesting = false) + public function __construct(HttpClientInterface $client, ?string $apiKey = null, ?string $instance = null, bool $isTesting = false) { $this->apiKey = $apiKey; $this->instance = $instance; $this->isTesting = $isTesting; $this->client = $client->withOptions([ - 'base_uri' => self::API_BASE_URI, + 'base_uri' => self::API_BASE_URI, ]); } - public function activity(string $month = null, string $order = null, int $limit = null, int $offset = 0): ActivityResponse + public function activity(?string $month = null, ?string $order = null, ?int $limit = null, int $offset = 0): ActivityResponse { if (null !== $month && !preg_match('#^2[0-1][0-9]{2}\-[0-1][0-9]$#', $month)) { throw new \RuntimeException('Month must be null or in the format YYYY-MM'); diff --git a/src/AkismetMessage.php b/src/AkismetMessage.php index 7cc43bf..856e342 100644 --- a/src/AkismetMessage.php +++ b/src/AkismetMessage.php @@ -166,11 +166,21 @@ public function getType(): ?MessageType return MessageType::tryFrom($this->get('comment_type') ?? ''); } + public function getTypeAsString(): ?string + { + return $this->get('comment_type'); + } + public function setType(?MessageType $type): static { return $this->set('comment_type', $type?->value); } + public function setTypeAsString(?string $type): static + { + return $this->set('comment_type', $type); + } + public function getUserAgent(): ?string { return $this->get('user_agent'); diff --git a/tests/AkismetTest.php b/tests/AkismetTest.php index 607040c..e500d1c 100644 --- a/tests/AkismetTest.php +++ b/tests/AkismetTest.php @@ -90,6 +90,7 @@ public function testMessageAccessors(): void $this->assertSame('edit', $message->getRecheckReason()); $this->assertSame('https://www.google.com', $message->getReferrer()); $this->assertSame(MessageType::BLOG_POST, $message->getType()); + $this->assertSame(MessageType::BLOG_POST->value, $message->getTypeAsString()); $this->assertSame('Custom Browser 684', $message->getUserAgent()); $this->assertSame('guest', $message->getUserRole()); $this->assertSame('12.34.56.78', $message->getUserIP()); @@ -106,6 +107,9 @@ public function testMessageAccessors(): void $message->setReferrer(null); $this->assertNull($message->getReferrer()); + + $message->setTypeAsString('foo'); + $this->assertSame('foo', $message->getTypeAsString()); } public function testPSR7Integration(): void