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   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 10 3
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