Completed
Push — guzzle-5 ( 0ecdde...1d908f )
by Harry
04:32
created

Utils::jsonEncode()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
ccs 4
cts 7
cp 0.5714
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 9
nc 1
nop 2
crap 2.3149
1
<?php
2
/*
3
 * This file is part of Guzzle HTTP JSON-RPC
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE
11
 * @link http://github.com/graze/guzzle-jsonrpc
12
 */
13
namespace Graze\GuzzleHttp\JsonRpc;
14
15
class Utils
16
{
17
    /**
18
     * Wrapper for json_encode that includes character escaping by default
19
     *
20
     * @param  mixed          $data
21
     * @param  bool           $escapeChars
22
     * @return string|boolean
23
     */
24 2
    public static function jsonEncode($data, $escapeChars = true)
25
    {
26
        $options =
27
            \JSON_HEX_AMP  |
28 2
            \JSON_HEX_APOS |
29
            \JSON_HEX_QUOT |
30
            \JSON_HEX_TAG  |
31
            \JSON_UNESCAPED_UNICODE |
32 2
            \JSON_UNESCAPED_SLASHES;
33
34 2
        return \json_encode($data, $escapeChars ? $options : 0);
35
    }
36
}
37