Completed
Push — master ( 257c19...712c83 )
by Rémi
04:23
created

TweetParameters   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 104
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 1
F toArray() 0 30 10
1
<?php
2
3
namespace Twitter\API\REST\DTO;
4
5
use Twitter\API\REST\ApiParameters;
6
7
class TweetParameters implements ApiParameters
8
{
9
    /** @var string */
10
    private $text;
11
12
    /** @var int */
13
    private $replyToId;
14
15
    /** @var bool */
16
    private $sensitive;
17
18
    /** @var Coordinates */
19
    private $coordinates;
20
21
    /** @var string */
22
    private $placeId;
23
24
    /** @var bool */
25
    private $displayCoordinates;
26
27
    /** @var bool */
28
    private $trimUser;
29
30
    /** @var int[] */
31
    private $mediaIds;
32
33
    /** @var bool */
34
    private $enableDirectMessageCommands;
35
36
    /** @var bool */
37
    private $failDirectMessageCommands;
38
39
    /**
40
     * TweetParameters constructor.
41
     *
42
     * @param string      $text
43
     * @param int         $replyToId
44
     * @param bool        $sensitive
45
     * @param Coordinates $coordinates
46
     * @param string      $placeId
47
     * @param bool        $displayCoordinates
48
     * @param bool        $trimUser
49
     * @param int[]       $mediaIds
50
     * @param bool        $enableDirectMessageCommands
51
     * @param bool        $failDirectMessageCommands
52
     */
53 51
    public function __construct(
54
        $text,
55
        $replyToId = null,
56
        $sensitive = false,
57
        Coordinates $coordinates = null,
58
        $placeId = null,
59
        $displayCoordinates = false,
60
        $trimUser = false,
61
        array $mediaIds = [],
62
        $enableDirectMessageCommands = true,
63
        $failDirectMessageCommands = false
64
    ) {
65 51
        $this->text = $text;
66 51
        $this->replyToId = $replyToId;
67 51
        $this->sensitive = $sensitive;
68 51
        $this->coordinates = $coordinates;
69 51
        $this->placeId = $placeId;
70 51
        $this->displayCoordinates = $displayCoordinates;
71 51
        $this->trimUser = $trimUser;
72 51
        $this->mediaIds = $mediaIds;
73 51
        $this->enableDirectMessageCommands = $enableDirectMessageCommands;
74 51
        $this->failDirectMessageCommands = $failDirectMessageCommands;
75 51
    }
76
77
    /**
78
     * @return array
79
     */
80 15
    public function toArray()
81
    {
82
        $parameters = [
83 15
            'status' => $this->text,
84 15
            'possibly_sensitive' => $this->sensitive ? 'true' : 'false',
85 15
            'trim_user' => $this->trimUser ? 'true' : 'false',
86 15
            'enable_dm_commands' => $this->enableDirectMessageCommands ? 'true' : 'false',
87 15
            'fail_dm_commands' => $this->failDirectMessageCommands ? 'true' : 'false'
88 10
        ];
89
90 15
        if ($this->replyToId !== null) {
91 6
            $parameters['in_reply_to_status_id'] = $this->replyToId;
92 4
        }
93
94 15
        if ($this->coordinates !== null) {
95 6
            $parameters = array_merge($parameters, $this->coordinates->toArray());
96
97 6
            $parameters['display_coordinates'] = $this->displayCoordinates ? 'true' : 'false';
98 4
        }
99
100 15
        if ($this->placeId !== null) {
101 6
            $parameters['place_id'] = $this->placeId;
102 4
        }
103
104 15
        if (!empty($this->mediaIds)) {
105 6
            $parameters['media_ids'] = implode(',', $this->mediaIds);
106 4
        }
107
108 15
        return $parameters;
109
    }
110
}
111