Skip to content

Commit 915a62f

Browse files
authored
Allow to do numbers filtering with has_application and application_id filters (#448)
1 parent e472cad commit 915a62f

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/Numbers/Filter/AvailableNumbers.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class AvailableNumbers implements FilterInterface
7474
*/
7575
protected $type;
7676

77+
protected ?bool $hasApplication = null;
78+
79+
protected ?string $applicationId = null;
80+
7781
public function __construct(array $filter = [])
7882
{
7983
foreach ($filter as $key => $value) {
@@ -132,6 +136,14 @@ public function __construct(array $filter = [])
132136

133137
$this->setFeatures($filter['features']);
134138
}
139+
140+
if (array_key_exists('has_application', $filter)) {
141+
$this->setHasApplication((bool)$filter['has_application']);
142+
}
143+
144+
if (array_key_exists('application_id', $filter)) {
145+
$this->setApplicationId($filter['application_id']);
146+
}
135147
}
136148

137149
/**
@@ -161,6 +173,14 @@ public function getQuery(): array
161173
$data['features'] = $this->getFeatures();
162174
}
163175

176+
if ($this->getHasApplication() !== null) {
177+
$data['has_application'] = $this->getHasApplication();
178+
}
179+
180+
if ($this->getApplicationId() !== null) {
181+
$data['application_id'] = $this->getApplicationId();
182+
}
183+
164184
return $data;
165185
}
166186

@@ -282,4 +302,34 @@ public function setPageSize(int $pageSize): self
282302

283303
return $this;
284304
}
305+
306+
public function getHasApplication(): ?bool
307+
{
308+
return $this->hasApplication;
309+
}
310+
311+
/**
312+
* @return $this
313+
*/
314+
public function setHasApplication(bool $hasApplication): self
315+
{
316+
$this->hasApplication = $hasApplication;
317+
318+
return $this;
319+
}
320+
321+
public function getApplicationId(): ?string
322+
{
323+
return $this->applicationId;
324+
}
325+
326+
/**
327+
* @return $this
328+
*/
329+
public function setApplicationId(string $applicationId): self
330+
{
331+
$this->applicationId = $applicationId;
332+
333+
return $this;
334+
}
285335
}

test/Numbers/Filter/AvailableNumbersTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,26 @@ public function testInvalidTypeThrowsException()
4242
$filter = new AvailableNumbers();
4343
$filter->setType('foo-bar');
4444
}
45+
46+
public function testCanSetHasApplication(): void
47+
{
48+
$filter = new AvailableNumbers();
49+
$filter->setHasApplication(true);
50+
51+
$this->assertTrue($filter->getHasApplication());
52+
$query = $filter->getQuery();
53+
$this->assertArrayHasKey('has_application', $query);
54+
$this->assertTrue($query['has_application']);
55+
}
56+
57+
public function testCanSetApplicationId(): void
58+
{
59+
$filter = new AvailableNumbers();
60+
$filter->setApplicationId('xxxxxxxx');
61+
62+
$this->assertSame('xxxxxxxx', $filter->getApplicationId());
63+
$query = $filter->getQuery();
64+
$this->assertArrayHasKey('application_id', $query);
65+
$this->assertSame('xxxxxxxx', $query['application_id']);
66+
}
4567
}

0 commit comments

Comments
 (0)