From b8081fbbe938c45b08c3181879b9aa1c4f14b2e1 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 12 Feb 2023 13:36:42 -0500 Subject: [PATCH] Refactor --- .php-cs-fixer.php | 2 +- src/Facades/TwilioClient.php | 8 ++--- src/Notifications/Channels/TwilioChannel.php | 5 +-- src/Providers/TwilioProvider.php | 36 ++++++++------------ src/Twilio/Http/LaravelHttpClient.php | 9 ++--- src/TwilioClient.php | 6 ++-- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index c23682e..13c5684 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -14,7 +14,7 @@ [ '@PHP81Migration' => true, '@PHP80Migration:risky' => true, - '@PHPUnit84Migration:risky' => true, + '@PHPUnit100Migration:risky' => true, '@PSR12' => true, '@PSR2' => true, 'align_multiline_comment' => true, diff --git a/src/Facades/TwilioClient.php b/src/Facades/TwilioClient.php index 61942a5..e803b81 100644 --- a/src/Facades/TwilioClient.php +++ b/src/Facades/TwilioClient.php @@ -10,11 +10,11 @@ use Twilio\Rest\Client; /** - * @method static ConnectionManager extend($name, \Closure $callback) + * @method static ConnectionManager extend($name, \Closure $callback) * @method static TwilioClientContract connection(string $name = null) - * @method static Client twilio() - * @method static CallInstance call(string $to, array $params = []) - * @method static MessageInstance message(string $to, string $message, array $params = []) + * @method static Client twilio() + * @method static CallInstance call(string $to, array $params = []) + * @method static MessageInstance message(string $to, string $message, array $params = []) * * @see ConnectionManager */ diff --git a/src/Notifications/Channels/TwilioChannel.php b/src/Notifications/Channels/TwilioChannel.php index d17473f..43b6ffc 100644 --- a/src/Notifications/Channels/TwilioChannel.php +++ b/src/Notifications/Channels/TwilioChannel.php @@ -9,8 +9,9 @@ final class TwilioChannel { - public function __construct(private TwilioClient $twilio) - { + public function __construct( + private readonly TwilioClient $twilio, + ) { } /** diff --git a/src/Providers/TwilioProvider.php b/src/Providers/TwilioProvider.php index 1789401..f9cb6bf 100644 --- a/src/Providers/TwilioProvider.php +++ b/src/Providers/TwilioProvider.php @@ -34,12 +34,9 @@ public function provides(): array public function boot(): void { - $this->publishes( - [ - __DIR__ . '/../../config/twilio.php' => config_path('twilio.php'), - ], - 'config' - ); + $this->publishes([ + __DIR__ . '/../../config/twilio.php' => $this->app->configPath('twilio.php'), + ], 'config'); } public function register(): void @@ -55,7 +52,7 @@ private function registerConnectionManager(): void { $this->app->singleton( ConnectionManager::class, - static fn (Application $app): ConnectionManager => new ConnectionManager($app) + static fn (Application $app): ConnectionManager => new ConnectionManager($app), ); $this->app->alias(ConnectionManager::class, TwilioClient::class); @@ -80,22 +77,19 @@ static function (Application $app): TwilioHttpClient { private function registerNotificationChannel(): void { Notification::resolved(static function (ChannelManager $manager): void { - $manager->extend( - 'twilio', - static function (Application $app): TwilioChannel { - /** @var Repository $config */ - $config = $app->make('config'); + $manager->extend('twilio', static function (Application $app): TwilioChannel { + /** @var Repository $config */ + $config = $app->make('config'); - /** @var ConnectionManager $manager */ - $manager = $app->make(ConnectionManager::class); + /** @var ConnectionManager $manager */ + $manager = $app->make(ConnectionManager::class); - return new TwilioChannel( - $manager->connection( - $config->get('twilio.notification_channel', $config->get('twilio.default', 'twilio')) - ) - ); - } - ); + return new TwilioChannel( + $manager->connection( + $config->get('twilio.notification_channel', $config->get('twilio.default', 'twilio')), + ), + ); + }); }); } } diff --git a/src/Twilio/Http/LaravelHttpClient.php b/src/Twilio/Http/LaravelHttpClient.php index 9fdc524..66118b2 100644 --- a/src/Twilio/Http/LaravelHttpClient.php +++ b/src/Twilio/Http/LaravelHttpClient.php @@ -9,8 +9,9 @@ final class LaravelHttpClient implements Client { - public function __construct(private Factory $httpFactory) - { + public function __construct( + private readonly Factory $httpFactory, + ) { } /** @@ -24,7 +25,7 @@ public function request( array $headers = [], string $user = null, string $password = null, - int $timeout = null + int $timeout = null, ): Response { $request = $this->httpFactory->asForm(); @@ -43,7 +44,7 @@ public function request( $response = $request->send( $method, $url, - $requestOptions + $requestOptions, ); } catch (\Exception $exception) { throw new HttpException('Unable to complete the HTTP request', 0, $exception); diff --git a/src/TwilioClient.php b/src/TwilioClient.php index 0b8db31..c5c1ebc 100644 --- a/src/TwilioClient.php +++ b/src/TwilioClient.php @@ -13,8 +13,10 @@ final class TwilioClient implements TwilioClientContract /** * @param string $from The default from number to use. */ - public function __construct(private Client $twilio, private string $from) - { + public function __construct( + private readonly Client $twilio, + private readonly string $from, + ) { } public function twilio(): Client