@@ -7,117 +7,117 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Response |
| 9 | 9 | { |
| 10 | - private $method; |
|
| 11 | - private $response; |
|
| 10 | + private $method; |
|
| 11 | + private $response; |
|
| 12 | 12 | |
| 13 | - public function __construct(string $method, $response) |
|
| 14 | - { |
|
| 15 | - $this->method = $method; |
|
| 13 | + public function __construct(string $method, $response) |
|
| 14 | + { |
|
| 15 | + $this->method = $method; |
|
| 16 | 16 | |
| 17 | - $body = $response->getBody()->getContents(); |
|
| 18 | - $this->response = new \SimpleXMLElement($body); |
|
| 17 | + $body = $response->getBody()->getContents(); |
|
| 18 | + $this->response = new \SimpleXMLElement($body); |
|
| 19 | 19 | |
| 20 | - } |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Checks if the response contains an Error |
|
| 24 | - * @method hasError |
|
| 25 | - * @author PA |
|
| 26 | - * @date 2017-01-10 |
|
| 27 | - * @return bool hasError |
|
| 28 | - */ |
|
| 29 | - public function hasError() : bool |
|
| 30 | - { |
|
| 31 | - return ($this->getErrorCode() != 0); |
|
| 32 | - } |
|
| 22 | + /** |
|
| 23 | + * Checks if the response contains an Error |
|
| 24 | + * @method hasError |
|
| 25 | + * @author PA |
|
| 26 | + * @date 2017-01-10 |
|
| 27 | + * @return bool hasError |
|
| 28 | + */ |
|
| 29 | + public function hasError() : bool |
|
| 30 | + { |
|
| 31 | + return ($this->getErrorCode() != 0); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Fetches the Error Code from the Response |
|
| 36 | - * @method getErrorCode |
|
| 37 | - * @author PA |
|
| 38 | - * @date 2017-01-10 |
|
| 39 | - * @return int Error Code |
|
| 40 | - */ |
|
| 41 | - public function getErrorCode() : int |
|
| 42 | - { |
|
| 43 | - return (int) $this->response->ErrCode; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Fetches the Error Code from the Response |
|
| 36 | + * @method getErrorCode |
|
| 37 | + * @author PA |
|
| 38 | + * @date 2017-01-10 |
|
| 39 | + * @return int Error Code |
|
| 40 | + */ |
|
| 41 | + public function getErrorCode() : int |
|
| 42 | + { |
|
| 43 | + return (int) $this->response->ErrCode; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Fetches the Error Message From Response |
|
| 48 | - * @method getError |
|
| 49 | - * @author PA |
|
| 50 | - * @date 2017-01-10 |
|
| 51 | - * @return string Error Message |
|
| 52 | - */ |
|
| 53 | - public function getError() : string |
|
| 54 | - { |
|
| 55 | - return (string)$this->response->ErrDesc; |
|
| 56 | - } |
|
| 46 | + /** |
|
| 47 | + * Fetches the Error Message From Response |
|
| 48 | + * @method getError |
|
| 49 | + * @author PA |
|
| 50 | + * @date 2017-01-10 |
|
| 51 | + * @return string Error Message |
|
| 52 | + */ |
|
| 53 | + public function getError() : string |
|
| 54 | + { |
|
| 55 | + return (string)$this->response->ErrDesc; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Converts the response to an Array |
|
| 60 | - * @method toArray |
|
| 61 | - * @throws YourMembershipException |
|
| 62 | - * @author PA |
|
| 63 | - * @date 2017-01-10 |
|
| 64 | - * @return array Response |
|
| 65 | - */ |
|
| 66 | - public function toArray() : array |
|
| 67 | - { |
|
| 68 | - return $this->unwrapXMLObject(true); |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * Converts the response to an Array |
|
| 60 | + * @method toArray |
|
| 61 | + * @throws YourMembershipException |
|
| 62 | + * @author PA |
|
| 63 | + * @date 2017-01-10 |
|
| 64 | + * @return array Response |
|
| 65 | + */ |
|
| 66 | + public function toArray() : array |
|
| 67 | + { |
|
| 68 | + return $this->unwrapXMLObject(true); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Converts the response to an Object |
|
| 73 | - * @method toObject |
|
| 74 | - * @throws YourMembershipException |
|
| 75 | - * @author PA |
|
| 76 | - * @date 2017-01-11 |
|
| 77 | - * @return stdClass Response |
|
| 78 | - */ |
|
| 79 | - public function toObject() : \stdClass |
|
| 80 | - { |
|
| 81 | - return $this->unwrapXMLObject(false); |
|
| 82 | - } |
|
| 71 | + /** |
|
| 72 | + * Converts the response to an Object |
|
| 73 | + * @method toObject |
|
| 74 | + * @throws YourMembershipException |
|
| 75 | + * @author PA |
|
| 76 | + * @date 2017-01-11 |
|
| 77 | + * @return stdClass Response |
|
| 78 | + */ |
|
| 79 | + public function toObject() : \stdClass |
|
| 80 | + { |
|
| 81 | + return $this->unwrapXMLObject(false); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Unwraps XML Object into either StdClass or Array |
|
| 86 | - * Lossy conversion, attributes are lost from XML |
|
| 87 | - * |
|
| 88 | - * @method unwrapXMLObject |
|
| 89 | - * @throws YourMembershipException |
|
| 90 | - * @author PA |
|
| 91 | - * @date 2017-01-11 |
|
| 92 | - * @param bool $asArray unwrap the object into an array instead of object |
|
| 93 | - * @return mixed|null Unwrapped Response |
|
| 94 | - */ |
|
| 95 | - private function unwrapXMLObject(bool $asArray) |
|
| 96 | - { |
|
| 97 | - //We cannot unwrap objects that have errors, so throw an exception |
|
| 98 | - if ($this->hasError()) { |
|
| 99 | - throw new YourMembershipException($this->getError(), $this->getErrorCode(), $this->method); |
|
| 100 | - } |
|
| 84 | + /** |
|
| 85 | + * Unwraps XML Object into either StdClass or Array |
|
| 86 | + * Lossy conversion, attributes are lost from XML |
|
| 87 | + * |
|
| 88 | + * @method unwrapXMLObject |
|
| 89 | + * @throws YourMembershipException |
|
| 90 | + * @author PA |
|
| 91 | + * @date 2017-01-11 |
|
| 92 | + * @param bool $asArray unwrap the object into an array instead of object |
|
| 93 | + * @return mixed|null Unwrapped Response |
|
| 94 | + */ |
|
| 95 | + private function unwrapXMLObject(bool $asArray) |
|
| 96 | + { |
|
| 97 | + //We cannot unwrap objects that have errors, so throw an exception |
|
| 98 | + if ($this->hasError()) { |
|
| 99 | + throw new YourMembershipException($this->getError(), $this->getErrorCode(), $this->method); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return json_decode(json_encode($this->response->{$this->method}), $asArray); |
|
| 103 | - } |
|
| 104 | - /** |
|
| 105 | - * Returns the Result Count |
|
| 106 | - * @method getResultCount |
|
| 107 | - * @author PA |
|
| 108 | - * @date 2017-01-10 |
|
| 109 | - * @return int|false false if no ResultCount is present |
|
| 110 | - */ |
|
| 111 | - public function getResultCount() : int |
|
| 112 | - { |
|
| 113 | - $count = false; |
|
| 102 | + return json_decode(json_encode($this->response->{$this->method}), $asArray); |
|
| 103 | + } |
|
| 104 | + /** |
|
| 105 | + * Returns the Result Count |
|
| 106 | + * @method getResultCount |
|
| 107 | + * @author PA |
|
| 108 | + * @date 2017-01-10 |
|
| 109 | + * @return int|false false if no ResultCount is present |
|
| 110 | + */ |
|
| 111 | + public function getResultCount() : int |
|
| 112 | + { |
|
| 113 | + $count = false; |
|
| 114 | 114 | |
| 115 | - if (isset($this->response->{$this->method}->Results)) { |
|
| 116 | - $attributes = $this->response->{$this->method}->Results->attributes(); |
|
| 117 | - $count = (int) $attributes['ResultTotal'] ?? false; |
|
| 118 | - } |
|
| 115 | + if (isset($this->response->{$this->method}->Results)) { |
|
| 116 | + $attributes = $this->response->{$this->method}->Results->attributes(); |
|
| 117 | + $count = (int) $attributes['ResultTotal'] ?? false; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $count; |
|
| 121 | - } |
|
| 120 | + return $count; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | } |