Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
90.00% |
9 / 10 |
CRAP | |
94.44% |
17 / 18 |
| HEXONET\ResponseTemplate | |
0.00% |
0 / 1 |
|
90.00% |
9 / 10 |
13.03 | |
94.44% |
17 / 18 |
| __construct | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| getCode | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getDescription | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getPlain | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getQueuetime | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
| getHash | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getRuntime | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
| isError | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| isSuccess | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| isTmpError | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 1 |
|||
| <?php | |
| declare(strict_types=1); | |
| /** | |
| * HEXONET | |
| * Copyright © HEXONET | |
| */ | |
| namespace HEXONET; | |
| use \HEXONET\ResponseParser as RP; | |
| use \HEXONET\ResponseTemplateManager as RTM; | |
| /** | |
| * HEXONET ResponseTemplate | |
| * | |
| * @package HEXONET | |
| */ | |
| class ResponseTemplate | |
| { | |
| /** | |
| * plain API response | |
| * @var string | |
| */ | |
| protected $raw; | |
| /** | |
| * hash representation of plain API response | |
| * @var array[string]string | |
| */ | |
| protected $hash; | |
| /** | |
| * Constructor | |
| * @param string $raw plain API response | |
| */ | |
| public function __construct($raw) | |
| { | |
| if (!$raw) { | |
| $raw = RTM::getInstance()->getTemplate("empty")->getPlain(); | |
| } | |
| $this->raw = $raw; | |
| $this->hash = RP::parse($raw); | |
| } | |
| /** | |
| * Get API response code | |
| * @return integer API response code | |
| */ | |
| public function getCode() | |
| { | |
| return intval($this->hash["CODE"], 10); | |
| } | |
| /** | |
| * Get API response description | |
| * @return string API response description | |
| */ | |
| public function getDescription() | |
| { | |
| return $this->hash["DESCRIPTION"]; | |
| } | |
| /** | |
| * Get Plain API response | |
| * @return string Plain API response | |
| */ | |
| public function getPlain() | |
| { | |
| return $this->raw; | |
| } | |
| /** | |
| * Get Queuetime of API response | |
| * @return float Queuetime of API response | |
| */ | |
| public function getQueuetime() | |
| { | |
| if (array_key_exists("QUEUETIME", $this->hash)) { | |
| return floatval($this->hash["QUEUETIME"]); | |
| } | |
| return 0.00; | |
| } | |
| /** | |
| * Get API response as Hash | |
| * @return array[string]string API response hash | |
| */ | |
| public function getHash() | |
| { | |
| return $this->hash; | |
| } | |
| /** | |
| * Get Runtime of API response | |
| * @return float Runtime of API response | |
| */ | |
| public function getRuntime() | |
| { | |
| if (array_key_exists("RUNTIME", $this->hash)) { | |
| return floatval($this->hash["RUNTIME"]); | |
| } | |
| return 0.00; | |
| } | |
| /** | |
| * Check if current API response represents an error case | |
| * API response code is an 5xx code | |
| * @return boolean boolean result | |
| */ | |
| public function isError() | |
| { | |
| return substr($this->hash["CODE"], 0, 1) === "5"; | |
| } | |
| /** | |
| * Check if current API response represents a success case | |
| * API response code is an 2xx code | |
| * @return boolean boolean result | |
| */ | |
| public function isSuccess() | |
| { | |
| return substr($this->hash["CODE"], 0, 1) === "2"; | |
| } | |
| /** | |
| * Check if current API response represents a temporary error case | |
| * API response code is an 4xx code | |
| * @return boolean result | |
| */ | |
| public function isTmpError() | |
| { | |
| return substr($this->hash["CODE"], 0, 1) === "4"; | |
| } | |
| } |