Skip to content

Commit

Permalink
Allow to do numbers filtering with has_application and application_id…
Browse files Browse the repository at this point in the history
… filters (#448)
  • Loading branch information
erickskrauch committed Oct 24, 2023
1 parent e472cad commit 915a62f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Numbers/Filter/AvailableNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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']);
}
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
22 changes: 22 additions & 0 deletions test/Numbers/Filter/AvailableNumbersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

0 comments on commit 915a62f

Please sign in to comment.