TwitterEntityIndicesSerializer::canSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Twitter\Serializer;
4
5
use Assert\Assertion;
6
use Twitter\Object\TwitterEntityIndices;
7
use Twitter\TwitterSerializable;
8
use Twitter\TwitterSerializer;
9
10
class TwitterEntityIndicesSerializer implements TwitterSerializer
11
{
12
    /**
13
     * @param  TwitterSerializable $object
14
     * @return integer[]
15
     */
16 6
    public function serialize(TwitterSerializable $object)
17
    {
18
        /* @var TwitterEntityIndices $object */
19 6
        Assertion::true($this->canSerialize($object), 'object must be an instance of TwitterEntityIndices');
20
21 3
        return [$object->getFrom(), $object->getTo()];
22
    }
23
24
    /**
25
     * @param  array $array
26
     * @param  array $context
27
     * @return TwitterEntityIndices
28
     */
29 6
    public function unserialize($array, array $context = [])
30
    {
31 6
        Assertion::true($this->canUnserialize($array), 'object is not unserializable');
32
33 3
        return TwitterEntityIndices::create($array[0], $array[1]);
34
    }
35
36
    /**
37
     * @param  TwitterSerializable $object
38
     * @return boolean
39
     */
40 6
    public function canSerialize(TwitterSerializable $object)
41
    {
42 6
        return $object instanceof TwitterEntityIndices;
43
    }
44
45
    /**
46
     * @param  array $object
47
     * @return boolean
48
     */
49 6
    public function canUnserialize($object)
50
    {
51 6
        return is_array($object) && count($object) === 2;
52
    }
53
54
    /**
55
     * @return TwitterEntityIndicesSerializer
56
     */
57 39
    public static function build()
58
    {
59 39
        return new self();
60
    }
61
}
62