Completed
Push — master ( d83f32...d4821e )
by Rémi
04:29
created

UserTimelineQuery::toArray()   C

Complexity

Conditions 7
Paths 64

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
ccs 0
cts 15
cp 0
rs 6.9811
cc 7
eloc 12
nc 64
nop 0
crap 56
1
<?php
2
3
namespace Twitter\API\REST\Query\Tweet;
4
5
use Twitter\API\REST\ApiParameters;
6
use Twitter\API\REST\DTO\UserIdentifier;
7
8
class UserTimelineQuery implements ApiParameters
9
{
10
    /** @var UserIdentifier */
11
    private $userIdentifier;
12
13
    /** @var int */
14
    private $count;
15
16
    /** @var int */
17
    private $fromId;
18
19
    /** @var int */
20
    private $toId;
21
22
    /** @var bool */
23
    private $includeRetweets;
24
25
    /** @var bool */
26
    private $trimUser;
27
28
    /** @var bool */
29
    private $excludeReplies;
30
31
    /**
32
     * MentionsTimelineQuery constructor.
33
     *
34
     * @param UserIdentifier $userIdentifier
35
     * @param int            $count
36
     * @param int            $fromId
37
     * @param int            $toId
38
     * @param bool           $includeRetweets
39
     * @param bool           $trimUser
40
     * @param bool           $excludeReplies
41
     */
42
    public function __construct(
43
        UserIdentifier $userIdentifier,
44
        $count = 20,
45
        $fromId = null,
46
        $toId = null,
47
        $includeRetweets = true,
48
        $trimUser = false,
49
        $excludeReplies = true
50
    ) {
51
        $this->userIdentifier = $userIdentifier;
52
        $this->count = $count;
53
        $this->fromId = $fromId;
54
        $this->toId = $toId;
55
        $this->includeRetweets = $includeRetweets;
56
        $this->trimUser = $trimUser;
57
        $this->excludeReplies = $excludeReplies;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function toArray()
64
    {
65
        $request = $this->userIdentifier->toArray();
66
67
        $request['include_rts'] = $this->includeRetweets ? 'true' : 'false';
68
        $request['trim_user'] = $this->trimUser ? 'true' : 'false';
69
        $request['exclude_replies'] = $this->excludeReplies ? 'true' : 'false';
70
71
        if ($this->count !== null) {
72
            $request['count'] = $this->count;
73
        }
74
75
        if ($this->fromId !== null) {
76
            $request['since_id'] = $this->fromId;
77
        }
78
79
        if ($this->toId !== null) {
80
            $request['max_id'] = $this->toId;
81
        }
82
83
        return $request;
84
    }
85
}
86