Completed
Push — master ( 6551be...435af8 )
by Mario
09:41
created

serializer_test.php ➔ readJson()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
require_once __DIR__ . '/../../vendor/autoload.php';
4
5
use Marek\OpenWeatherMap\Factory\DenormalizerFactory;
6
use Marek\OpenWeatherMap\Denormalizer\UltravioletIndexDenormalizer;
7
use Marek\OpenWeatherMap\API\Value\Response\UltravioletIndex\UltravioletIndex;
8
use Marek\OpenWeatherMap\API\Value\Response\UltravioletIndex\AggregatedUltravioletIndex;
9
10
$data = readJson('uv_index', 'history');
11
12
$denormalizerFactory = new DenormalizerFactory();
13
$denormalizer = new UltravioletIndexDenormalizer($denormalizerFactory->create());
14
15
/** @var \Marek\OpenWeatherMap\API\Value\Response\UltravioletIndex\UltravioletIndex $res */
16
$res = $denormalizer->denormalize($data, new AggregatedUltravioletIndex());
17
18
dump($res);
19
20
function readJson(string $service, string $file): array
21
{
22
    $file = __DIR__ . '/responses/' . $service . '/' . $file . '.json';
23
24
    if (!file_exists($file)) {
25
        throw new InvalidArgumentException('Invalid argument provided for json file.');
26
    }
27
28
    try {
29
        return json_decode(
30
            file_get_contents($file), true, 512, JSON_THROW_ON_ERROR
31
        );
32
    } catch (JsonException $exception) {
0 ignored issues
show
Bug introduced by
The class JsonException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
33
        throw new \Exception('Invalid JSON provided.');
34
    }
35
}
36