Skip to content

Commit

Permalink
Merge pull request #142 from laravel-notification-channels/types
Browse files Browse the repository at this point in the history
Replace docs with types
  • Loading branch information
dwightwatson authored Oct 29, 2023
2 parents b3b1fd7 + cf81393 commit a423a1b
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 267 deletions.
6 changes: 1 addition & 5 deletions src/ApnAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ class ApnAdapter
{
/**
* Convert an ApnMessage instance into a Zend Apns Message.
*
* @param \NotificationChannels\Apn\ApnMessage $message
* @param string $token
* @return \Pushok\Notification
*/
public function adapt(ApnMessage $message, string $token)
public function adapt(ApnMessage $message, string $token): Notification
{
$alert = null;

Expand Down
44 changes: 6 additions & 38 deletions src/ApnChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,23 @@

class ApnChannel
{
/**
* The Pushok\Client factory.
*
* @var \NotificationChannels\Apn\ClientFactory
*/
protected $factory;

/**
* The event dispatcher.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;

/**
* Create a new channel instance.
*
* @param \NotificationChannels\Apn\ClientFactory $factory
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function __construct(ClientFactory $factory, Dispatcher $events)
public function __construct(protected ClientFactory $factory, protected Dispatcher $events)
{
$this->factory = $factory;
$this->events = $events;
//
}

/**
* Send the notification to Apple Push Notification Service.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return array|void
*/
public function send($notifiable, Notification $notification)
public function send(mixed $notifiable, Notification $notification): ?array
{
$tokens = (array) $notifiable->routeNotificationFor('apn', $notification);

if (empty($tokens)) {
return;
return null;
}

$message = $notification->toApn($notifiable);
Expand All @@ -64,13 +42,8 @@ public function send($notifiable, Notification $notification)

/**
* Send the message to the given tokens through the given client.
*
* @param \Pushok\Client $client
* @param \NotificationChannels\Apn\ApnMessage $message
* @param array $tokens
* @return array
*/
protected function sendNotifications(Client $client, ApnMessage $message, array $tokens)
protected function sendNotifications(Client $client, ApnMessage $message, array $tokens): array
{
foreach ($tokens as $token) {
$client->addNotification((new ApnAdapter)->adapt($message, $token));
Expand All @@ -81,13 +54,8 @@ protected function sendNotifications(Client $client, ApnMessage $message, array

/**
* Dispatch failed events for notifications that weren't delivered.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @param array $responses
* @return void
*/
protected function dispatchEvents($notifiable, $notification, array $responses)
protected function dispatchEvents(mixed $notifiable, Notification $notification, array $responses): void
{
foreach ($responses as $response) {
if ($response->getStatusCode() === Response::APNS_SUCCESS) {
Expand Down
Loading

0 comments on commit a423a1b

Please sign in to comment.