Completed
Pull Request — master (#18)
by Steve
02:00
created

Helpers.php ➔ file_contents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace MeadSteve\DiceApi\Helpers;
3
4
use http\Exception\RuntimeException;
5
6
function file_contents(string $path): string
7
{
8
    $contents = \file_get_contents($path);
9
    if ($contents === false) {
10
        throw new \RuntimeException("Unable to load from {$path}");
11
    }
12
    return $contents;
13
}
14
15
function json_encode($data): string
16
{
17
    $encoded = \json_encode($data);
18
    if ($encoded === false) {
19
        throw new \RuntimeException("Unable to encode json data");
20
    }
21
    return $encoded;
22
}
23