1 | <?php |
||
8 | class Button implements \JsonSerializable |
||
9 | { |
||
10 | /** @var string Button Title */ |
||
11 | protected $title; |
||
12 | |||
13 | /** @var string|array Button URL, Postback Data or Phone Number */ |
||
14 | protected $data; |
||
15 | |||
16 | /** @var string Button Type */ |
||
17 | protected $type; |
||
18 | |||
19 | /** |
||
20 | * Create a button. |
||
21 | * |
||
22 | * @param string $title |
||
23 | * @param string|array $data |
||
24 | * @param string $type |
||
25 | * |
||
26 | * @return static |
||
27 | */ |
||
28 | public static function create($title = '', $data = null, $type = ButtonType::WEB_URL) |
||
32 | |||
33 | /** |
||
34 | * @param string $title |
||
35 | * @param string|array $data |
||
36 | * @param string $type |
||
37 | */ |
||
38 | public function __construct($title = '', $data = null, $type = ButtonType::WEB_URL) |
||
44 | |||
45 | /** |
||
46 | * Set Button Title. |
||
47 | * |
||
48 | * @param $title |
||
49 | * |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function title($title) |
||
58 | |||
59 | /** |
||
60 | * Set Button Data. |
||
61 | * Could be url, postback or phone number. |
||
62 | * |
||
63 | * @param mixed $data |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function data($data) |
||
73 | |||
74 | /** |
||
75 | * Set Button Type. |
||
76 | * |
||
77 | * @param $type Possible Values: "web_url", "postback" or "phone_number". Default: "web_url" |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function type($type) |
||
87 | |||
88 | /** |
||
89 | * Set button type as web_url. |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | public function isTypeWebUrl() |
||
99 | |||
100 | /** |
||
101 | * Set button type as postback. |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function isTypePostback() |
||
111 | |||
112 | /** |
||
113 | * Set button type as phone_number. |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | public function isTypePhoneNumber() |
||
123 | |||
124 | /** |
||
125 | * Determine Button Type. |
||
126 | * |
||
127 | * @param $type |
||
128 | * |
||
129 | * @return bool |
||
130 | */ |
||
131 | protected function isType($type) |
||
135 | |||
136 | /** |
||
137 | * Builds payload and returns an array. |
||
138 | * |
||
139 | * @return array |
||
140 | * @throws CouldNotCreateButton |
||
141 | */ |
||
142 | public function toArray() |
||
173 | |||
174 | /** |
||
175 | * Convert the object into something JSON serializable. |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | public function jsonSerialize() |
||
183 | |||
184 | /** |
||
185 | * Validate Title. |
||
186 | * |
||
187 | * @throws CouldNotCreateButton |
||
188 | */ |
||
189 | protected function validateTitle() |
||
195 | |||
196 | /** |
||
197 | * Validate Payload. |
||
198 | * |
||
199 | * @throws CouldNotCreateButton |
||
200 | */ |
||
201 | protected function validatePayload() |
||
207 | |||
208 | /** |
||
209 | * Validate Phone Number. |
||
210 | * |
||
211 | * @throws CouldNotCreateButton |
||
212 | */ |
||
213 | protected function validatePhoneNumber() |
||
219 | } |
||
220 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.