Skip to content

Commit

Permalink
Add support for arbitraty messages types
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
curry684 committed Oct 25, 2024
1 parent 7a5464c commit f31d697
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.idea
/.*.cache
/.env.local
/build
/composer.lock
/tmp
/vendor
Expand Down
6 changes: 3 additions & 3 deletions src/Akismet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 10 additions & 0 deletions src/AkismetMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions tests/AkismetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down

0 comments on commit f31d697

Please sign in to comment.