Failed Conditions
Push — v7 ( 84f8b9...722dd5 )
by Florent
02:35
created

StandardJsonEncoder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
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\Encoder;
15
16
/**
17
 * Class StandardJsonEncoder
18
 */
19
final class StandardJsonEncoder implements PayloadEncoderInterface
20
{
21
    /**
22
     * @var int
23
     */
24
    private $options;
25
26
    /**
27
     * @var bool
28
     */
29
    private $associative;
30
31
    /**
32
     * @var int
33
     */
34
    private $depth;
35
36
    /**
37
     * StandardJsonEncoder constructor.
38
     * See also json_encode and json_decode parameters.
39
     *
40
     * @param int  $options
41
     * @param bool $associative
42
     * @param int  $depth
43
     */
44
    public function __construct(int $options = 0, bool $associative = false, int $depth = 512)
45
    {
46
        $this->options = $options;
47
        $this->associative = $associative;
48
        $this->depth = $depth;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function encode($payload): string
55
    {
56
        return json_encode($payload, $this->options, $this->depth);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function decode(string $payload)
63
    {
64
        return json_decode($payload,$this->associative, $this->depth, $this->options);
65
    }
66
}
67