Completed
Push — master ( 183dcf...c5dab6 )
by Jodie
02:15
created

JsonHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A encode() 0 8 2
1
<?php
2
3
namespace Rexlabs\Smokescreen\Helpers;
4
5
use Rexlabs\Smokescreen\Exception\JsonEncodeException;
6
7
class JsonHelper
8
{
9
    /**
10
     * Encodes data as a JSON string representation.
11
     * @param mixed $data
12
     * @param int   $options
13
     *
14
     * @return string
15
     * @throws \Rexlabs\Smokescreen\Exception\JsonEncodeException
16
     */
17 2
    public static function encode($data, $options = 0): string
18
    {
19 2
        $json = json_encode($data, $options);
20 2
        if (JSON_ERROR_NONE !== json_last_error()) {
21 1
            throw new JsonEncodeException(json_last_error_msg());
22
        }
23
24 1
        return $json;
25
    }
26
}