TwitterFriendsSerializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 10 1
A unserialize() 0 6 1
A canSerialize() 0 4 1
A canUnserialize() 0 4 1
A build() 0 4 1
1
<?php
2
3
namespace Twitter\Serializer;
4
5
use Assert\Assertion;
6
use Twitter\Object\TwitterFriends;
7
use Twitter\TwitterSerializable;
8
use Twitter\TwitterSerializer;
9
10
class TwitterFriendsSerializer implements TwitterSerializer
11
{
12
    /**
13
     * @param  TwitterSerializable $object
14
     * @return \stdClass
15
     */
16 6
    public function serialize(TwitterSerializable $object)
17
    {
18
        /* @var TwitterFriends $object */
19 6
        Assertion::true($this->canSerialize($object), 'object must be an instance of TwitterFriends');
20
21 3
        $friends = new \stdClass();
22 3
        $friends->friends = $object->getFriends();
23
24 3
        return $friends;
25
    }
26
27
    /**
28
     * @param  \stdClass $obj
29
     * @param  array     $context
30
     * @return TwitterFriends
31
     */
32 6
    public function unserialize($obj, array $context = [])
33
    {
34 6
        Assertion::true($this->canUnserialize($obj), 'object is not unserializable');
35
36 3
        return TwitterFriends::create($obj->friends);
37
    }
38
39
    /**
40
     * @param  TwitterSerializable $object
41
     * @return boolean
42
     */
43 6
    public function canSerialize(TwitterSerializable $object)
44
    {
45 6
        return $object instanceof TwitterFriends;
46
    }
47
48
    /**
49
     * @param  \stdClass $object
50
     * @return boolean
51
     */
52 6
    public function canUnserialize($object)
53
    {
54 6
        return isset($object->friends);
55
    }
56
57
    /**
58
     * @return TwitterFriendsSerializer
59
     */
60 6
    public static function build()
61
    {
62 6
        return new self();
63
    }
64
}
65