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.

ArrayHydrator::hydrate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient\Hydrator;
6
7
use Pnz\JsonException\Json;
8
use Pnz\MattermostClient\Exception\HydrationException;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * Hydrate an HTTP response to array.
13
 */
14
final class ArrayHydrator implements Hydrator
15
{
16
    public function hydrate(ResponseInterface $response, string $class): array
17
    {
18
        if (0 !== strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
19
            throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type'));
20
        }
21
22
        try {
23
            return Json::decode((string) $response->getBody(), true);
24
        } catch (\JsonException $exception) {
25
            throw new HydrationException(sprintf('Error when trying to decoding the JSON response: %s', $exception->getMessage()), 0, $exception);
26
        }
27
    }
28
}
29