Test Failed
Push — master ( 2a75d8...e4b8e4 )
by Julien
12:49
created

Json   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonEncode() 0 3 2
A jsonDecode() 0 3 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Model;
13
14
trait Json
15
{
16
    /**
17
     * JSON Encode or fallback to value
18
     * @return string|false
19
     */
20
    public function jsonEncode($value, int $flags = JSON_UNESCAPED_SLASHES, int $depth = 512)
21
    {
22
        return json_encode($value, $flags, $depth) ?: $value;
23
    }
24
    
25
    /**
26
     * JSON Decode or fallback to value
27
     * @return mixed|string
28
     */
29
    public function jsonDecode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0)
30
    {
31
        return json_decode($json, $associative, $depth, $flags) ?: $json;
32
    }
33
}
34