Passed
Pull Request — master (#19)
by André
11:58
created

Json   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A decode() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Demv\JSend;
6
7
use InvalidArgumentException;
8
9
class Json
10
{
11
    /**
12
     * Decodes the given JSON string or fails with an exception.
13
     *
14
     * @param string $json
15
     * @return array
16
     * @throws InvalidArgumentException
17
     */
18
    public static function decode(string $json): array
19
    {
20
        $data = json_decode($json, true);
21
22
        if (JSON_ERROR_NONE !== json_last_error()) {
23
            throw new InvalidArgumentException(
24
                'json_decode error: ' . json_last_error_msg()
25
            );
26
        }
27
28
        return $data;
29
    }
30
}
31