Skip to content

Commit 6e86ea0

Browse files
committed
PHP Type hints
1 parent 58f1434 commit 6e86ea0

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

src/FluentEntity.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public function __construct(array $data = [])
1616
$this->data = $data + $this->data;
1717
}
1818

19-
public static function make()
19+
public static function make(): static
2020
{
2121
return new static;
2222
}
2323

24-
public function __call($name, $arguments)
24+
public function __call($name, $arguments): self
2525
{
2626
$key = snake_case($name);
2727

@@ -30,13 +30,12 @@ public function __call($name, $arguments)
3030
return $this;
3131
}
3232

33-
#[\ReturnTypeWillChange]
34-
public function jsonSerialize()
33+
public function jsonSerialize(): mixed
3534
{
3635
return (object) $this->data;
3736
}
3837

39-
private function getDefault($key)
38+
private function getDefault($key): mixed
4039
{
4140
return $this->defaults[$key] ?? null;
4241
}

src/InlineKeyboard/InlineKeyboardButton.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/**
88
* @method self text(string $text)
99
* @method self url(string $url)
10-
* @method self loginUrl(array $login_url)
1110
* @method self callbackData(string $callback_data)
1211
* @method self switchInlineQuery(string $switch_inline_query)
1312
* @method self switchInlineQueryCurrentChat(string $switch_inline_query_current_chat)
@@ -21,7 +20,7 @@ class InlineKeyboardButton extends Button
2120
'pay' => true,
2221
];
2322

24-
public static function make(string $text = null)
23+
public static function make(string $text = null): static
2524
{
2625
$data = [];
2726

@@ -32,4 +31,17 @@ public static function make(string $text = null)
3231
return new static($data);
3332
}
3433

34+
public function loginUrl(array|string $login_url): self
35+
{
36+
if (! is_array($login_url)) {
37+
$login_url = [
38+
'url' => $login_url
39+
];
40+
}
41+
42+
$this->data['login_url'] = $login_url;
43+
44+
return $this;
45+
}
46+
3547
}

src/KeyboardMarkup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(array $data = [])
2828
* @param Button[] $buttons
2929
* @return $this
3030
*/
31-
public function row(array $buttons = [])
31+
public function row(array $buttons = []): self
3232
{
3333
$keyboard = &$this->data[static::$keyboardFieldName];
3434

@@ -53,7 +53,7 @@ public function row(array $buttons = [])
5353
* @param Button[] $buttons
5454
* @return $this
5555
*/
56-
public function stack(array $buttons)
56+
public function stack(array $buttons): self
5757
{
5858
// Every button gets its own row
5959
foreach ($buttons as $button) {
@@ -69,7 +69,7 @@ public function stack(array $buttons)
6969
* @param Button $button
7070
* @return $this
7171
*/
72-
public function button(Button $button)
72+
public function button(Button $button): self
7373
{
7474
$keyboard = &$this->data[static::$keyboardFieldName];
7575

src/ReplyKeyboard/KeyboardButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class KeyboardButton extends Button
1818
'request_poll' => [],
1919
];
2020

21-
public static function make(string $text = null)
21+
public static function make(string $text = null): static
2222
{
2323
$data = [];
2424

src/ReplyKeyboard/KeyboardButtonPollType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ class KeyboardButtonPollType extends Button
1212

1313
protected $data = [];
1414

15-
public static function any()
15+
public static function any(): static
1616
{
1717
return new static();
1818
}
1919

20-
public static function quiz()
20+
public static function quiz(): static
2121
{
2222
return new static([
2323
'type' => 'quiz'
2424
]);
2525
}
2626

27-
public static function regular()
27+
public static function regular(): static
2828
{
2929
return new static([
3030
'type' => 'regular'

0 commit comments

Comments
 (0)