Skip to content

Commit 2a8fcfa

Browse files
authored
Merge pull request #10 from tmconsulting/develop
Next release
2 parents abbdcf9 + f94872c commit 2a8fcfa

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
vendor/
3-
.php_cs.cache
3+
.php_cs.cache
4+
scratch/

src/Method/AbstractMethod.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function getResultObject($result, $items = null, $resultClass = Result
7575
{
7676
try {
7777
if (!$items) {
78-
$items = $this->performResult($result, $needsErrors);
78+
$items = $this->performResult($result, [], $needsErrors);
7979
}
8080
return (new ReflectionClass($resultClass))->newInstanceArgs(array_merge($items, [$needsErrors]));
8181
} catch (ReflectionException $e) {

src/Method/Book.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Hotelbook\Method\Builder\Book as BookBuilder;
1515
use Hotelbook\Method\Former\Book as BookFormer;
16+
use Hotelbook\ResultProceeder;
1617
use Money\Parser\StringToUnitsParser;
1718

1819
/**
@@ -30,7 +31,7 @@ class Book extends AbstractMethod
3031
public function handle($xml)
3132
{
3233
$response = $this->connector->request('POST', 'add_order', $xml);
33-
return $this->getResultObject($response);
34+
return $this->getResultObject($response, null, ResultProceeder::class, false);
3435
}
3536

3637
/**

src/Method/Former/Detail.php

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function form($results)
4343
'builtIn' => (string)$detail->BuiltIn,
4444
'buildingType' => (string)$detail->BuildingType,
4545
'numberLifts' => (int)$detail->NumberLifts,
46+
'numberFloors' => (int)$detail->NumberFloors,
4647
'conference' => (string)$detail->Conference,
4748
'voltage' => (string)$detail->Voltage,
4849
'childAgeFrom' => (string)$detail->ChildAgeFrom,

src/ResultProceeder.php

+13-14
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,13 @@ class ResultProceeder
2020

2121
/**
2222
* ResultProceeder constructor.
23-
*
2423
* @param array $items
2524
* @param array $errors
26-
* @param bool $throwsException
2725
*/
28-
public function __construct(array $items, array $errors = [], $throwsException = true)
26+
public function __construct(array $items, array $errors = [])
2927
{
3028
$this->setItems($items);
3129
$this->setErrors($errors);
32-
33-
if ($throwsException) {
34-
$this->throwExceptionIfNeeded();
35-
}
3630
}
3731

3832
/**
@@ -92,6 +86,18 @@ public function getItems()
9286
return $this->items;
9387
}
9488

89+
/**
90+
*
91+
*/
92+
public function getItem()
93+
{
94+
if (count($this->items) === 1) {
95+
return current($this->items);
96+
} else {
97+
return $this->getItems();
98+
}
99+
}
100+
95101
/**
96102
* @param array $items
97103
* @return $this
@@ -101,11 +107,4 @@ public function setItems(array $items)
101107
$this->items = $items;
102108
return $this;
103109
}
104-
105-
protected function throwExceptionIfNeeded()
106-
{
107-
if($this->hasErrors()) {
108-
throw new ResponseException(1, 'Something went wrong with request. Run $result->getErrors() to get this data. ');
109-
}
110-
}
111110
}

0 commit comments

Comments
 (0)