From 915a62fdc0bcfde8755ab6bf975430f3bbc0ab64 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 24 Oct 2023 11:52:36 +0200 Subject: [PATCH] Allow to do numbers filtering with has_application and application_id filters (#448) --- src/Numbers/Filter/AvailableNumbers.php | 50 ++++++++++++++++++++ test/Numbers/Filter/AvailableNumbersTest.php | 22 +++++++++ 2 files changed, 72 insertions(+) diff --git a/src/Numbers/Filter/AvailableNumbers.php b/src/Numbers/Filter/AvailableNumbers.php index a892ec7e..cd8af2f9 100644 --- a/src/Numbers/Filter/AvailableNumbers.php +++ b/src/Numbers/Filter/AvailableNumbers.php @@ -74,6 +74,10 @@ class AvailableNumbers implements FilterInterface */ protected $type; + protected ?bool $hasApplication = null; + + protected ?string $applicationId = null; + public function __construct(array $filter = []) { foreach ($filter as $key => $value) { @@ -132,6 +136,14 @@ public function __construct(array $filter = []) $this->setFeatures($filter['features']); } + + if (array_key_exists('has_application', $filter)) { + $this->setHasApplication((bool)$filter['has_application']); + } + + if (array_key_exists('application_id', $filter)) { + $this->setApplicationId($filter['application_id']); + } } /** @@ -161,6 +173,14 @@ public function getQuery(): array $data['features'] = $this->getFeatures(); } + if ($this->getHasApplication() !== null) { + $data['has_application'] = $this->getHasApplication(); + } + + if ($this->getApplicationId() !== null) { + $data['application_id'] = $this->getApplicationId(); + } + return $data; } @@ -282,4 +302,34 @@ public function setPageSize(int $pageSize): self return $this; } + + public function getHasApplication(): ?bool + { + return $this->hasApplication; + } + + /** + * @return $this + */ + public function setHasApplication(bool $hasApplication): self + { + $this->hasApplication = $hasApplication; + + return $this; + } + + public function getApplicationId(): ?string + { + return $this->applicationId; + } + + /** + * @return $this + */ + public function setApplicationId(string $applicationId): self + { + $this->applicationId = $applicationId; + + return $this; + } } diff --git a/test/Numbers/Filter/AvailableNumbersTest.php b/test/Numbers/Filter/AvailableNumbersTest.php index b241115f..53eb0ee5 100644 --- a/test/Numbers/Filter/AvailableNumbersTest.php +++ b/test/Numbers/Filter/AvailableNumbersTest.php @@ -42,4 +42,26 @@ public function testInvalidTypeThrowsException() $filter = new AvailableNumbers(); $filter->setType('foo-bar'); } + + public function testCanSetHasApplication(): void + { + $filter = new AvailableNumbers(); + $filter->setHasApplication(true); + + $this->assertTrue($filter->getHasApplication()); + $query = $filter->getQuery(); + $this->assertArrayHasKey('has_application', $query); + $this->assertTrue($query['has_application']); + } + + public function testCanSetApplicationId(): void + { + $filter = new AvailableNumbers(); + $filter->setApplicationId('xxxxxxxx'); + + $this->assertSame('xxxxxxxx', $filter->getApplicationId()); + $query = $filter->getQuery(); + $this->assertArrayHasKey('application_id', $query); + $this->assertSame('xxxxxxxx', $query['application_id']); + } }