JsonEncoder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
c 1
b 0
f 0
dl 0
loc 25
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 2 1
A canProcess() 0 2 1
A encode() 0 2 1
1
<?php
2
/**
3
 * @copyright  Daniel Król <[email protected]>
4
 * @license MIT
5
 * @package Mleko\Alchemist
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
12
namespace Mleko\Alchemist\Encoder;
13
14
15
use Mleko\Alchemist\Encoder;
16
17
class JsonEncoder implements Encoder
18
{
19
20
    /**
21
     * @param array|int|string|float|bool $scalar
22
     * @param string $format
23
     * @param array $context
24
     * @return string
25
     */
26 3
    public function encode($scalar, string $format, array $context = []) {
27 3
        return \json_encode($scalar);
28
    }
29
30
    /**
31
     * @param string $data
32
     * @param string $format
33
     * @param array $context
34
     * @return array|bool|float|int|string
35
     */
36 3
    public function decode(string $data, string $format, array $context = []) {
37 3
        return \json_decode($data, true);
38
    }
39
40 1
    public function canProcess(string $format): bool {
41 1
        return 0 === \strcasecmp("json", $format);
42
    }
43
}
44