Passed
Pull Request — master (#1856)
by
unknown
11:54
created

BaseInterface::fromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace MySociety\TheyWorkForYou\DataClass;
4
5
use function Rutek\Dataclass\transform;
6
7
trait BaseInterface {
8
    public static function fromJson(string $json): self {
9
        $data = json_decode($json, true);
10
        try {
11
            return transform(static::class, $data);
12
        } catch (\Exception $transformException) {
13
            echo json_encode($transformException, JSON_PRETTY_PRINT);
14
            throw $transformException;
15
        }
16
    }
17
18
    public static function fromArray(array $data): self {
19
        try {
20
            return transform(static::class, $data);
21
        } catch (\Exception $transformException) {
22
            echo json_encode($transformException, JSON_PRETTY_PRINT);
23
            throw $transformException;
24
        }
25
    }
26
}
27