Failed Conditions
Push — master ( b15b87...797163 )
by Florent
03:08
created

StandardConverter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A encode() 0 4 1
A decode() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Core\Converter;
15
16
/**
17
 * Class StandardConverter.
18
 */
19
final class StandardConverter implements JsonConverter
20
{
21
    /**
22
     * @var int
23
     */
24
    private $options;
25
26
    /**
27
     * @var int
28
     */
29
    private $depth;
30
31
    /**
32
     * StandardJsonEncoder constructor.
33
     * See also json_encode and json_decode parameters.
34
     *
35
     * @param int $options
36
     * @param int $depth
37
     */
38
    public function __construct(int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE, int $depth = 512)
39
    {
40
        $this->options = $options;
41
        $this->depth = $depth;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function encode($payload): string
48
    {
49
        return json_encode($payload, $this->options, $this->depth);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function decode(string $payload, bool $associativeArray = true)
56
    {
57
        return json_decode($payload, $associativeArray, $this->depth, $this->options);
58
    }
59
}
60