Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
8 / 8 |
HttpStatusParser | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
8 / 8 |
parse(Response $curlResponse) | |
100.00% |
1 / 1 |
2 | |
100.00% |
6 / 6 |
|||
shouldThrowException($statusCode) | |
100.00% |
1 / 1 |
2 | |
100.00% |
2 / 2 |
<?php | |
/** | |
* @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl> | |
*/ | |
namespace Team3\PayU\Communication\HttpStatusParser; | |
use Buzz\Message\Response; | |
/** | |
* {@inheritdoc} | |
*/ | |
class HttpStatusParser implements HttpStatusParserInterface | |
{ | |
const SUCCESS_CODE = 200; | |
const REDIRECT_CODE = 302; | |
/** | |
* @param Response $curlResponse | |
* | |
* @throws HttpStatusParserException | |
*/ | |
public function parse(Response $curlResponse) | |
{ | |
$statusCode = $curlResponse->getStatusCode(); | |
if ($this->shouldThrowException($statusCode)) { | |
throw new HttpStatusParserException( | |
$curlResponse->getContent(), | |
$statusCode | |
); | |
} | |
} | |
/** | |
* @param int $statusCode | |
* | |
* @return bool | |
*/ | |
private function shouldThrowException($statusCode) | |
{ | |
return self::SUCCESS_CODE !== $statusCode | |
&& self::REDIRECT_CODE !== $statusCode; | |
} | |
} |