Skip to content

Commit 15714ee

Browse files
irazasyedactions-user
authored andcommitted
Apply PHP CS Fixer changes
1 parent 29280b6 commit 15714ee

File tree

11 files changed

+116
-179
lines changed

11 files changed

+116
-179
lines changed

src/Components/Button.php

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,41 @@ class Button implements JsonSerializable
1818
/** @var string Button Type */
1919
protected $type;
2020

21-
/** @var string|array Button URL, Postback Data or Phone Number */
21+
/** @var array|string Button URL, Postback Data or Phone Number */
2222
protected $data;
2323

2424
/** @var array Payload */
2525
protected $payload = [];
2626

2727
/**
28-
* Create a button.
29-
*
30-
* @param string $title
31-
* @param string|array $data
32-
* @param string $type
28+
* Button Constructor.
3329
*
34-
* @return static
30+
* @param array|string $data
3531
*/
36-
public static function create(string $title = '', $data = null, string $type = ButtonType::WEB_URL): self
32+
public function __construct(string $title = '', $data = null, string $type = ButtonType::WEB_URL)
3733
{
38-
return new static($title, $data, $type);
34+
$this->title = $title;
35+
$this->data = $data;
36+
$this->payload['type'] = $type;
3937
}
4038

4139
/**
42-
* Button Constructor.
40+
* Create a button.
41+
*
42+
* @param array|string $data
4343
*
44-
* @param string $title
45-
* @param string|array $data
46-
* @param string $type
44+
* @return static
4745
*/
48-
public function __construct(string $title = '', $data = null, string $type = ButtonType::WEB_URL)
46+
public static function create(string $title = '', $data = null, string $type = ButtonType::WEB_URL): self
4947
{
50-
$this->title = $title;
51-
$this->data = $data;
52-
$this->payload['type'] = $type;
48+
return new static($title, $data, $type);
5349
}
5450

5551
/**
5652
* Set Button Title.
5753
*
58-
* @param string $title
59-
*
6054
* @throws CouldNotCreateButton
55+
*
6156
* @return $this
6257
*/
6358
public function title(string $title): self
@@ -78,9 +73,8 @@ public function title(string $title): self
7873
/**
7974
* Set a URL for the button.
8075
*
81-
* @param string $url
82-
*
8376
* @throws CouldNotCreateButton
77+
*
8478
* @return $this
8579
*/
8680
public function url(string $url): self
@@ -89,7 +83,7 @@ public function url(string $url): self
8983
throw CouldNotCreateButton::urlNotProvided();
9084
}
9185

92-
if (! filter_var($url, FILTER_VALIDATE_URL)) {
86+
if (!filter_var($url, FILTER_VALIDATE_URL)) {
9387
throw CouldNotCreateButton::invalidUrlProvided($url);
9488
}
9589

@@ -100,9 +94,8 @@ public function url(string $url): self
10094
}
10195

10296
/**
103-
* @param string $phone
104-
*
10597
* @throws CouldNotCreateButton
98+
*
10699
* @return $this
107100
*/
108101
public function phone(string $phone): self
@@ -111,7 +104,7 @@ public function phone(string $phone): self
111104
throw CouldNotCreateButton::phoneNumberNotProvided();
112105
}
113106

114-
if (is_string($phone) && ! Str::startsWith($phone, '+')) {
107+
if (is_string($phone) && !Str::startsWith($phone, '+')) {
115108
throw CouldNotCreateButton::invalidPhoneNumberProvided($phone);
116109
}
117110

@@ -122,10 +115,11 @@ public function phone(string $phone): self
122115
}
123116

124117
/**
125-
* @param $postback
118+
* @param $postback
126119
*
127-
* @return $this
128120
* @throws CouldNotCreateButton|\JsonException
121+
*
122+
* @return $this
129123
*/
130124
public function postback($postback): self
131125
{
@@ -142,7 +136,7 @@ public function postback($postback): self
142136
/**
143137
* Set Button Type.
144138
*
145-
* @param string $type Possible Values: "web_url", "postback" or "phone_number". Default: "web_url"
139+
* @param string $type Possible Values: "web_url", "postback" or "phone_number". Default: "web_url"
146140
*
147141
* @return $this
148142
*/
@@ -190,11 +184,32 @@ public function isTypePhoneNumber(): self
190184
}
191185

192186
/**
193-
* Determine Button Type.
187+
* Builds payload and returns an array.
188+
*
189+
* @throws CouldNotCreateButton
190+
*/
191+
public function toArray(): array
192+
{
193+
$this->title($this->title);
194+
$this->makePayload($this->data);
195+
196+
return $this->payload;
197+
}
198+
199+
/**
200+
* Convert the object into something JSON serializable.
194201
*
195-
* @param string $type
202+
* @throws CouldNotCreateButton
196203
*
197-
* @return bool
204+
* @return mixed
205+
*/
206+
public function jsonSerialize()
207+
{
208+
return $this->toArray();
209+
}
210+
211+
/**
212+
* Determine Button Type.
198213
*/
199214
protected function isType(string $type): bool
200215
{
@@ -204,9 +219,10 @@ protected function isType(string $type): bool
204219
/**
205220
* Make payload by data and type.
206221
*
207-
* @param mixed $data
222+
* @param mixed $data
208223
*
209224
* @throws CouldNotCreateButton
225+
*
210226
* @return $this
211227
*/
212228
protected function makePayload($data): self
@@ -218,12 +234,17 @@ protected function makePayload($data): self
218234
switch ($this->payload['type']) {
219235
case ButtonType::WEB_URL:
220236
$this->url($data);
237+
221238
break;
239+
222240
case ButtonType::PHONE_NUMBER:
223241
$this->phone($data);
242+
224243
break;
244+
225245
case ButtonType::POSTBACK:
226246
$this->postback($data);
247+
227248
break;
228249
}
229250

@@ -233,29 +254,4 @@ protected function makePayload($data): self
233254

234255
return $this;
235256
}
236-
237-
/**
238-
* Builds payload and returns an array.
239-
*
240-
* @throws CouldNotCreateButton
241-
* @return array
242-
*/
243-
public function toArray(): array
244-
{
245-
$this->title($this->title);
246-
$this->makePayload($this->data);
247-
248-
return $this->payload;
249-
}
250-
251-
/**
252-
* Convert the object into something JSON serializable.
253-
*
254-
* @throws CouldNotCreateButton
255-
* @return mixed
256-
*/
257-
public function jsonSerialize()
258-
{
259-
return $this->toArray();
260-
}
261257
}

src/Components/Card.php

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,34 @@ class Card implements JsonSerializable
1717
protected $payload = [];
1818

1919
/**
20-
* Create a Card.
21-
*
22-
* @param string $title
20+
* Create Card constructor.
2321
*
2422
* @throws CouldNotCreateCard
25-
* @return static
2623
*/
27-
public static function create(string $title = ''): self
24+
public function __construct(string $title = '')
2825
{
29-
return new static($title);
26+
if ('' !== $title) {
27+
$this->title($title);
28+
}
3029
}
3130

3231
/**
33-
* Create Card constructor.
34-
*
35-
* @param string $title
32+
* Create a Card.
3633
*
3734
* @throws CouldNotCreateCard
35+
*
36+
* @return static
3837
*/
39-
public function __construct(string $title = '')
38+
public static function create(string $title = ''): self
4039
{
41-
if ($title !== '') {
42-
$this->title($title);
43-
}
40+
return new static($title);
4441
}
4542

4643
/**
4744
* Set Button Title.
4845
*
49-
* @param string $title
50-
*
5146
* @throws CouldNotCreateCard
47+
*
5248
* @return $this
5349
*/
5450
public function title(string $title): self
@@ -65,8 +61,6 @@ public function title(string $title): self
6561
/**
6662
* Set Card Item Url.
6763
*
68-
* @param string $itemUrl
69-
*
7064
* @return $this
7165
*/
7266
public function url(string $itemUrl): self
@@ -79,7 +73,7 @@ public function url(string $itemUrl): self
7973
/**
8074
* Set Card Image Url.
8175
*
82-
* @param string $imageUrl Default image ratio is 1.91:1
76+
* @param string $imageUrl Default image ratio is 1.91:1
8377
*
8478
* @return $this
8579
*/
@@ -93,9 +87,8 @@ public function image(string $imageUrl): self
9387
/**
9488
* Set Card Subtitle.
9589
*
96-
* @param string $subtitle
97-
*
9890
* @throws CouldNotCreateCard
91+
*
9992
* @return $this
10093
*/
10194
public function subtitle(string $subtitle): self
@@ -113,11 +106,10 @@ public function subtitle(string $subtitle): self
113106
* Returns a payload for API request.
114107
*
115108
* @throws CouldNotCreateCard
116-
* @return array
117109
*/
118110
public function toArray(): array
119111
{
120-
if (! isset($this->payload['title'])) {
112+
if (!isset($this->payload['title'])) {
121113
throw CouldNotCreateCard::titleNotProvided();
122114
}
123115

@@ -132,6 +124,7 @@ public function toArray(): array
132124
* Convert the object into something JSON serializable.
133125
*
134126
* @throws CouldNotCreateCard
127+
*
135128
* @return mixed
136129
*/
137130
public function jsonSerialize()

src/Exceptions/CouldNotCreateButton.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public static function postbackNotProvided(): self
5252
/**
5353
* Thrown when the title characters limit is exceeded.
5454
*
55-
* @param string $title
56-
*
5755
* @return static
5856
*/
5957
public static function titleLimitExceeded(string $title): self
@@ -68,7 +66,7 @@ public static function titleLimitExceeded(string $title): self
6866
/**
6967
* Thrown when the payload characters limit is exceeded.
7068
*
71-
* @param mixed $data
69+
* @param mixed $data
7270
*
7371
* @return static
7472
*/
@@ -84,8 +82,6 @@ public static function payloadLimitExceeded($data): self
8482
/**
8583
* Thrown when the URL provided is not valid.
8684
*
87-
* @param string $url
88-
*
8985
* @return static
9086
*/
9187
public static function invalidUrlProvided(string $url): self
@@ -96,8 +92,6 @@ public static function invalidUrlProvided(string $url): self
9692
/**
9793
* Thrown when the phone number provided is of invalid format.
9894
*
99-
* @param string $phoneNumber
100-
*
10195
* @return static
10296
*/
10397
public static function invalidPhoneNumberProvided(string $phoneNumber): self

src/Exceptions/CouldNotCreateCard.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public static function titleNotProvided(): self
2222
/**
2323
* Thrown when the title characters limit is exceeded.
2424
*
25-
* @param string $title
26-
*
2725
* @return static
2826
*/
2927
public static function titleLimitExceeded(string $title): self
@@ -38,8 +36,6 @@ public static function titleLimitExceeded(string $title): self
3836
/**
3937
* Thrown when the subtitle characters limit is exceeded.
4038
*
41-
* @param string $title
42-
*
4339
* @return static
4440
*/
4541
public static function subtitleLimitExceeded(string $title): self

0 commit comments

Comments
 (0)