GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c16a9a...6a0503 )
by Ema
02:24 queued 51s
created

ArrayHydrator::hydrate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 3
Ratio 21.43 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 3
loc 14
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 2
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient\Hydrator;
6
7
use Pnz\MattermostClient\Exception\HydrationException;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * Hydrate an HTTP response to array.
12
 *
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
final class ArrayHydrator implements Hydrator
16
{
17
    /**
18
     * {@inheritdoc}
19
     *
20
     * @return array
21
     */
22
    public function hydrate(ResponseInterface $response, string $class): array
23
    {
24
        $body = $response->getBody()->__toString();
25 View Code Duplication
        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type'));
27
        }
28
29
        $content = json_decode($body, true);
30
        if (JSON_ERROR_NONE !== json_last_error()) {
31
            throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error()));
32
        }
33
34
        return $content;
35
    }
36
}
37