From 963379d8b2c372635d13246ac6d8897cba6cdbfe Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Rizk Date: Thu, 26 Oct 2023 22:41:17 +0300 Subject: [PATCH] Adding php8 constructor property promotion support --- src/Component/Currency.php | 13 ++++--------- src/Component/DateTime.php | 10 ++-------- src/Component/Image.php | 8 +++----- src/Component/Text.php | 7 ++----- src/Component/Video.php | 7 +++---- src/WhatsAppChannel.php | 6 ++---- 6 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/Component/Currency.php b/src/Component/Currency.php index 13bcae7..746beb5 100644 --- a/src/Component/Currency.php +++ b/src/Component/Currency.php @@ -4,17 +4,12 @@ class Currency extends Component { - protected float $amount; - /** - * Currency code as defined in ISO 4217. + * @param float $amount + * @param string $code Currency code as defined in ISO 4217. */ - protected string $code; - - public function __construct(float $amount, string $code = 'EUR') + public function __construct(protected float $amount,protected string $code = 'EUR') { - $this->amount = $amount; - $this->code = $code; } public function toArray(): array @@ -27,4 +22,4 @@ public function toArray(): array ], ]; } -} +} \ No newline at end of file diff --git a/src/Component/DateTime.php b/src/Component/DateTime.php index d67d23c..1434ceb 100644 --- a/src/Component/DateTime.php +++ b/src/Component/DateTime.php @@ -4,14 +4,8 @@ class DateTime extends Component { - protected \DateTimeImmutable $dateTime; - - protected string $format; - - public function __construct(\DateTimeImmutable $dateTime, string $format = 'Y-m-d H:i:s') + public function __construct(protected \DateTimeImmutable $dateTime,protected string $format = 'Y-m-d H:i:s') { - $this->dateTime = $dateTime; - $this->format = $format; } public function toArray(): array @@ -23,4 +17,4 @@ public function toArray(): array ], ]; } -} +} \ No newline at end of file diff --git a/src/Component/Image.php b/src/Component/Image.php index 4712a74..f350879 100644 --- a/src/Component/Image.php +++ b/src/Component/Image.php @@ -5,13 +5,11 @@ class Image extends Component { /** + * @param string $link * Link to the image; e.g. https://URL. */ - protected string $link; - - public function __construct(string $link) + public function __construct(protected string $link) { - $this->link = $link; } public function toArray(): array @@ -23,4 +21,4 @@ public function toArray(): array ], ]; } -} +} \ No newline at end of file diff --git a/src/Component/Text.php b/src/Component/Text.php index e8c20ee..b1c8406 100644 --- a/src/Component/Text.php +++ b/src/Component/Text.php @@ -4,11 +4,8 @@ class Text extends Component { - protected string $text; - - public function __construct(string $text) + public function __construct(protected string $text) { - $this->text = $text; } public function toArray(): array @@ -18,4 +15,4 @@ public function toArray(): array 'text' => $this->text, ]; } -} +} \ No newline at end of file diff --git a/src/Component/Video.php b/src/Component/Video.php index 2e6537a..11c9baa 100644 --- a/src/Component/Video.php +++ b/src/Component/Video.php @@ -5,13 +5,12 @@ class Video extends Component { /** + * @param string $link * Link to the video; e.g. https://URL. */ - protected string $link; - public function __construct(string $link) + public function __construct(protected string $link) { - $this->link = $link; } public function toArray(): array @@ -23,4 +22,4 @@ public function toArray(): array ], ]; } -} +} \ No newline at end of file diff --git a/src/WhatsAppChannel.php b/src/WhatsAppChannel.php index e18fdb1..3380f98 100644 --- a/src/WhatsAppChannel.php +++ b/src/WhatsAppChannel.php @@ -13,11 +13,9 @@ class WhatsAppChannel /* * HTTP WhatsApp Cloud API wrapper */ - private WhatsAppCloudApi $whatsapp; - public function __construct(WhatsAppCloudApi $whatsapp) + public function __construct(private WhatsAppCloudApi $whatsapp) { - $this->whatsapp = $whatsapp; } /** @@ -50,4 +48,4 @@ public function send($notifiable, Notification $notification): ?Response throw CouldNotSendNotification::serviceRespondedWithAnError($e->response()->body()); } } -} +} \ No newline at end of file