Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Feb 12, 2023
1 parent 518be6e commit b8081fb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'@PHPUnit100Migration:risky' => true,
'@PSR12' => true,
'@PSR2' => true,
'align_multiline_comment' => true,
Expand Down
8 changes: 4 additions & 4 deletions src/Facades/TwilioClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Notifications/Channels/TwilioChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

final class TwilioChannel
{
public function __construct(private TwilioClient $twilio)
{
public function __construct(
private readonly TwilioClient $twilio,
) {
}

/**
Expand Down
36 changes: 15 additions & 21 deletions src/Providers/TwilioProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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')),
),
);
});
});
}
}
9 changes: 5 additions & 4 deletions src/Twilio/Http/LaravelHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

final class LaravelHttpClient implements Client
{
public function __construct(private Factory $httpFactory)
{
public function __construct(
private readonly Factory $httpFactory,
) {
}

/**
Expand All @@ -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();

Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/TwilioClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8081fb

Please sign in to comment.