Completed
Push — develop ( c8d2e9...9b1d71 )
by Adam
03:00
created

ResponseParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isResponseJson() 0 4 1
A getBody() 0 4 1
1
<?php
2
3
namespace IBM\Watson\Common\Util;
4
5
use Psr\Http\Message\ResponseInterface;
6
7
/**
8
 * Utility class to parse instances of ResponseInterface
9
 */
10
trait ResponseParser
11
{
12
    /**
13
     * @param \Psr\Http\Message\ResponseInterface $response
14
     *
15
     * @return boolean
16
     */
17
    public function isResponseJson(ResponseInterface $response)
18
    {
19
        return \strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0;
20
    }
21
22
    /**
23
     * @param \Psr\Http\Message\ResponseInterface $response
24
     *
25
     * @return string
26
     */
27
    public function getBody(ResponseInterface $response)
28
    {
29
        return $response->getBody()->__toString();
30
    }
31
}
32