Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace docs with types #142

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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