Completed
Push — master ( 8bcfe7...12792b )
by Rémi
03:26
created

TwitterPlaceSerializer::serialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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