JsonEncoder::canProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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