JsonHelper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
eloc 5
c 2
b 1
f 0
dl 0
loc 20
ccs 5
cts 5
cp 1
rs 10

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
     *
12
     * @param mixed $data
13
     * @param int   $options
14
     *
15
     * @throws \Rexlabs\Smokescreen\Exception\JsonEncodeException
16
     *
17
     * @return string
18
     */
19 2
    public static function encode($data, $options = 0): string
20
    {
21 2
        $json = json_encode($data, $options);
22 2
        if (JSON_ERROR_NONE !== json_last_error()) {
23 1
            throw new JsonEncodeException(json_last_error_msg());
24
        }
25
26 1
        return $json;
27
    }
28
}
29