Completed
Pull Request — master (#18)
by Steve
05:29
created

Helpers.php ➔ file_contents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
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($path) {
7
    $contents = \file_get_contents($path);
8
    if ($contents === false) {
9
        throw new \RuntimeException("Unable to load from {$path}");
10
    }
11
    return $contents;
12
}
13
14
function json_encode($data) {
15
    $encoded = \json_encode($data);
16
    if ($encoded === false) {
17
        throw new \RuntimeException("Unable to encode json data");
18
    }
19
    return $encoded;
20
}