From c0732a26771b1a9177bc4532ff59da7a2ae6b92a Mon Sep 17 00:00:00 2001 From: alanpilloud Date: Tue, 9 Apr 2019 14:20:22 +0200 Subject: [PATCH] refactor setRange --- docs/sdk/client/setPriceRange.md | 16 ----------- docs/sdk/client/setRange.md | 21 ++++++++++++++ docs/sdk/client/setRoomRange.md | 16 ----------- docs/sdk/client/setSurfaceRange.md | 16 ----------- docs/sdk/recherche.md | 16 +---------- src/PublimmoPro/Client.php | 45 +++++++++++++----------------- tests/Client.php | 28 ++++++++----------- 7 files changed, 52 insertions(+), 106 deletions(-) delete mode 100644 docs/sdk/client/setPriceRange.md create mode 100644 docs/sdk/client/setRange.md delete mode 100644 docs/sdk/client/setRoomRange.md delete mode 100644 docs/sdk/client/setSurfaceRange.md diff --git a/docs/sdk/client/setPriceRange.md b/docs/sdk/client/setPriceRange.md deleted file mode 100644 index d8ecc65..0000000 --- a/docs/sdk/client/setPriceRange.md +++ /dev/null @@ -1,16 +0,0 @@ -### setPriceRange(int $min, int $max) - -Définit une fourchette de prix. - -#### Paramètres - -| Param | Type | Description | -| --- | --- | --- | -| $min | int | Prix minimum désiré | -| $max | int | Prix maximum désiré | - -#### Exemple - -```php -$Client->setPriceRange(2000, 2900); -``` diff --git a/docs/sdk/client/setRange.md b/docs/sdk/client/setRange.md new file mode 100644 index 0000000..3294af9 --- /dev/null +++ b/docs/sdk/client/setRange.md @@ -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); +``` diff --git a/docs/sdk/client/setRoomRange.md b/docs/sdk/client/setRoomRange.md deleted file mode 100644 index ba97820..0000000 --- a/docs/sdk/client/setRoomRange.md +++ /dev/null @@ -1,16 +0,0 @@ -### setRoomRange(int $min, int $max) - -Définit une fourchette de nombre de pièces. - -#### Paramètres - -| Param | Type | Description | -| --- | --- | --- | -| $min | int | Nombre de pièces minimum désiré | -| $max | int | Nombre de pièces maximum désiré | - -#### Exemple - -```php -$Client->setRoomRange(3, 6); -``` diff --git a/docs/sdk/client/setSurfaceRange.md b/docs/sdk/client/setSurfaceRange.md deleted file mode 100644 index a1027ed..0000000 --- a/docs/sdk/client/setSurfaceRange.md +++ /dev/null @@ -1,16 +0,0 @@ -### setSurfaceRange(int $min, int $max) - -Définit une fourchette de surface. - -#### Paramètres - -| Param | Type | Description | -| --- | --- | --- | -| $min | int | Surface minimum désirée | -| $max | int | Surface maximum désirée | - -#### Exemple - -```php -$Client->setSurfaceRange(80, 120); -``` diff --git a/docs/sdk/recherche.md b/docs/sdk/recherche.md index 714b9d8..607e7af 100644 --- a/docs/sdk/recherche.md +++ b/docs/sdk/recherche.md @@ -21,10 +21,6 @@ $PublimmoClient = new Client(99999, 'key'); ## Méthodes -[filename](client/setType.md ':include') - ---- - [filename](client/query.md ':include') --- @@ -81,7 +77,7 @@ $PublimmoClient = new Client(99999, 'key'); --- -[filename](client/setPriceRange.md ':include') +[filename](client/setRange.md ':include') --- @@ -97,10 +93,6 @@ $PublimmoClient = new Client(99999, 'key'); --- -[filename](client/setRoomRange.md ':include') - ---- - [filename](client/setSearchString.md ':include') --- @@ -113,15 +105,9 @@ $PublimmoClient = new Client(99999, 'key'); --- -[filename](client/setSurfaceRange.md ':include') - ---- - [filename](client/setTransaction.md ':include') --- [filename](client/setType.md ':include') ---- - diff --git a/src/PublimmoPro/Client.php b/src/PublimmoPro/Client.php index c3259c1..1b9379b 100644 --- a/src/PublimmoPro/Client.php +++ b/src/PublimmoPro/Client.php @@ -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; } diff --git a/tests/Client.php b/tests/Client.php index 2063b04..9617c5e 100644 --- a/tests/Client.php +++ b/tests/Client.php @@ -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