Completed
Push — v0.7 ( 7c9b41...5c4e91 )
by Nate
02:30
created

ScalarArrayTypeAdapter::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 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\ReaderContext;
12
use Tebru\Gson\TypeAdapter;
13
use Tebru\Gson\WriterContext;
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
    public function read($value, ReaderContext $context): ?array
30
    {
31
        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
    public function write($value, WriterContext $context): ?array
42
    {
43
        return $value === null ? null : (array)$value;
44
    }
45
}
46