Skip to content

Commit

Permalink
refactor setRange
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpilloud committed Apr 9, 2019
1 parent a0b9a5e commit c0732a2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 106 deletions.
16 changes: 0 additions & 16 deletions docs/sdk/client/setPriceRange.md

This file was deleted.

21 changes: 21 additions & 0 deletions docs/sdk/client/setRange.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### setRange(string $type, int $min, int $max)

Définit une fourchette de prix, surface ou chambres.

#### Paramètres

| Param | Type | Description |
| --- | --- | --- |
| $type | string | Type de valeur, "price", "surface" ou "room" |
| $min | int | Prix minimum désiré |
| $max | int | Prix maximum désiré |

#### Exemple

```php
$Client->setRange("price", 2000, 2900);

// définir plusieurs fourchettes
$Client->setRange("price", 2000, 2900)
->setRange("room", 3, 6);
```
16 changes: 0 additions & 16 deletions docs/sdk/client/setRoomRange.md

This file was deleted.

16 changes: 0 additions & 16 deletions docs/sdk/client/setSurfaceRange.md

This file was deleted.

16 changes: 1 addition & 15 deletions docs/sdk/recherche.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ $PublimmoClient = new Client(99999, 'key');

## Méthodes

[filename](client/setType.md ':include')

---

[filename](client/query.md ':include')

---
Expand Down Expand Up @@ -81,7 +77,7 @@ $PublimmoClient = new Client(99999, 'key');

---

[filename](client/setPriceRange.md ':include')
[filename](client/setRange.md ':include')

---

Expand All @@ -97,10 +93,6 @@ $PublimmoClient = new Client(99999, 'key');

---

[filename](client/setRoomRange.md ':include')

---

[filename](client/setSearchString.md ':include')

---
Expand All @@ -113,15 +105,9 @@ $PublimmoClient = new Client(99999, 'key');

---

[filename](client/setSurfaceRange.md ':include')

---

[filename](client/setTransaction.md ':include')

---

[filename](client/setType.md ':include')

---

45 changes: 19 additions & 26 deletions src/PublimmoPro/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,39 +211,32 @@ public function setPromotionType(int $type)
return $this;
}

public function setPriceRange(int $min, int $max)
public function setRange(string $type, int $min, int $max)
{
if ($min > $max) {
throw new \InvalidArgumentException('min value cannot be higher than max value.');
}

$this->prixMin = $min;
$this->prixMax = $max;

return $this;
}

public function setSurfaceRange(int $min, int $max)
{
if ($min > $max) {
throw new \InvalidArgumentException('min value cannot be higher than max value.');
switch ($type) {
case 'price':
$this->prixMin = $min;
$this->prixMax = $max;
break;

case 'surface':
$this->surfaceMin = $min;
$this->surfaceMax = $max;
break;

case 'room':
$this->pieceMin = $min;
$this->pieceMax = $max;
break;

default:
throw new \InvalidArgumentException('range type should be one of "price", "surface" or "room".');
}

$this->surfaceMin = $min;
$this->surfaceMax = $max;

return $this;
}

public function setRoomRange(int $min, int $max)
{
if ($min > $max) {
throw new \InvalidArgumentException('min value cannot be higher than max value.');
}

$this->pieceMin = $min;
$this->pieceMax = $max;

return $this;
}

Expand Down
28 changes: 11 additions & 17 deletions tests/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,41 +86,35 @@ public function testPromotionTypeCanBeSet(): void

public function testPriceRangeCanBeSet(): void
{
$queryUrl = $this->Client->setPriceRange(0, 3000)->getQueryURL();
$queryUrl = $this->Client->setRange('price', 0, 3000)->getQueryURL();
$this->assertTrue(strpos($queryUrl, 'prixMin=0') !== false);
$this->assertTrue(strpos($queryUrl, 'prixMax=3000') !== false);
}

public function testPriceRangeCannotHaveMaxValueHigherThanMinValue(): void
{
$this->expectException(InvalidArgumentException::class);
$queryUrl = $this->Client->setPriceRange(3000, 0)->getQueryURL();
}

public function testSurfaceRangeCanBeSet(): void
{
$queryUrl = $this->Client->setSurfaceRange(0, 300)->getQueryURL();
$queryUrl = $this->Client->setRange('surface', 0, 300)->getQueryURL();
$this->assertTrue(strpos($queryUrl, 'surfaceMin=0') !== false);
$this->assertTrue(strpos($queryUrl, 'surfaceMax=300') !== false);
}

public function testSurfaceRangeCannotHaveMaxValueHigherThanMinValue(): void
{
$this->expectException(InvalidArgumentException::class);
$queryUrl = $this->Client->setSurfaceRange(300, 0)->getQueryURL();
}

public function testRoomRangeCanBeSet(): void
{
$queryUrl = $this->Client->setRoomRange(0, 3)->getQueryURL();
$queryUrl = $this->Client->setRange('room', 0, 3)->getQueryURL();
$this->assertTrue(strpos($queryUrl, 'pieceMin=0') !== false);
$this->assertTrue(strpos($queryUrl, 'pieceMax=3') !== false);
}

public function testRoomRangeCannotHaveMaxValueHigherThanMinValue(): void
public function testRangeTypeCanOnlyBeOfPredefinedType(): void
{
$this->expectException(InvalidArgumentException::class);
$queryUrl = $this->Client->setRange('notexistingtype', 3000, 5990)->getQueryURL();
}

public function testRangeCannotHaveMaxValueHigherThanMinValue(): void
{
$this->expectException(InvalidArgumentException::class);
$queryUrl = $this->Client->setRoomRange(3, 0)->getQueryURL();
$queryUrl = $this->Client->setRange('price', 3000, 0)->getQueryURL();
}

public function testCityIdCanBeSet(): void
Expand Down

0 comments on commit c0732a2

Please sign in to comment.