ScalarArrayTypeAdapter::read()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\TypeAdapter;
10
11
use Tebru\Gson\Context\ReaderContext;
12
use Tebru\Gson\Context\WriterContext;
13
use Tebru\Gson\TypeAdapter;
14
15
/**
16
 * Class ScalarArrayTypeAdapter
17
 *
18
 * @author Nate Brunette <[email protected]>
19
 */
20
class ScalarArrayTypeAdapter extends TypeAdapter
21
{
22
    /**
23
     * Read the next value, convert it to its type and return it
24
     *
25
     * @param array|null $value
26
     * @param ReaderContext $context
27
     * @return array|null
28
     */
29 2
    public function read($value, ReaderContext $context): ?array
30
    {
31 2
        return $value === null ? null : (array)$value;
32
    }
33
34
    /**
35
     * Write the value to the writer for the type
36
     *
37
     * @param array|null $value
38
     * @param WriterContext $context
39
     * @return array|null
40
     */
41 2
    public function write($value, WriterContext $context): ?array
42
    {
43 2
        return $value === null ? null : (array)$value;
44
    }
45
}
46