diff --git a/README.md b/README.md index dd95e6a..b83345e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# InterFAX notification channel for Laravel 9.x, 10.x +# InterFAX notification channel for Laravel 10.x, 11.x [![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/interfax.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/interfax) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://img.shields.io/travis/laravel-notification-channels/interfax/main.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/interfax) [![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/interfax.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/interfax) -This package makes it easy to send notifications using [InterFAX](https://interfax.net) with Laravel 9.x and 10.x. +This package makes it easy to send notifications using [InterFAX](https://interfax.net) with Laravel 10.x and 11.x. ## Contents @@ -140,4 +140,4 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## License -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 4747eab..97f7eaa 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,4 +3,12 @@ parameters: paths: - src/ - level: 5 + level: 8 + + ignoreErrors: + - + identifier: ternary.alwaysTrue + path: src/InterfaxChannel.php + + stubFiles: + - stubs/Resource.stub diff --git a/src/Contracts/InterfaxNotificationContract.php b/src/Contracts/InterfaxNotificationContract.php index dc232e3..72e577e 100644 --- a/src/Contracts/InterfaxNotificationContract.php +++ b/src/Contracts/InterfaxNotificationContract.php @@ -6,5 +6,9 @@ interface InterfaxNotificationContract { + /** + * @param mixed $notifiable + * @return InterfaxMessage + */ public function toInterfax($notifiable): InterfaxMessage; } diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php index aa15bc6..3931a3e 100644 --- a/src/Exceptions/CouldNotSendNotification.php +++ b/src/Exceptions/CouldNotSendNotification.php @@ -7,9 +7,18 @@ class CouldNotSendNotification extends Exception { - protected $interfaxMessage; - protected $responseAttributes; + protected InterfaxMessage $interfaxMessage; + /** @var array */ + protected array $responseAttributes; + + /** + * @param string $message + * @param int $code + * @param Exception|null $previous + * @param InterfaxMessage $interfaxMessage + * @param array $responseAttributes + */ final public function __construct(string $message, int $code, Exception $previous = null, InterfaxMessage $interfaxMessage, array $responseAttributes) { parent::__construct($message, $code, $previous); @@ -18,22 +27,37 @@ final public function __construct(string $message, int $code, Exception $previou $this->responseAttributes = $responseAttributes; } - public static function serviceRespondedWithAnError($message, $responseAttributes, string $exceptionMessage = 'The fax failed to send via InterFAX.') + /** + * @param InterfaxMessage $message + * @param array $responseAttributes + * @param string $exceptionMessage + * @return CouldNotSendNotification + */ + public static function serviceRespondedWithAnError(InterfaxMessage $message, array $responseAttributes, string $exceptionMessage = 'The fax failed to send via InterFAX.') { return new static($exceptionMessage, $responseAttributes['status'], null, $message, $responseAttributes); } + /** + * @return mixed + */ public function getUser() { return $this->interfaxMessage->user; } - public function getMetadata() + /** + * @return array + */ + public function getMetadata(): array { return $this->interfaxMessage->metadata; } - public function getAttributes() + /** + * @return array + */ + public function getAttributes(): array { return $this->responseAttributes; } diff --git a/src/InterfaxChannel.php b/src/InterfaxChannel.php index 0e971a9..439fce0 100644 --- a/src/InterfaxChannel.php +++ b/src/InterfaxChannel.php @@ -8,13 +8,10 @@ class InterfaxChannel { - protected $client; + /** @var \Interfax\Outbound\Fax $fax */ protected $fax; - public function __construct(Client $client) - { - $this->client = $client; - } + public function __construct(protected Client $client) {} /** * Send the given notification. @@ -24,7 +21,7 @@ public function __construct(Client $client) * * @throws \NotificationChannels\Interfax\Exceptions\CouldNotSendNotification */ - public function send($notifiable, InterfaxNotificationContract $notification) + public function send($notifiable, InterfaxNotificationContract $notification): void { if (! $faxNumber = $notifiable->routeNotificationFor('interfax')) { return; @@ -41,11 +38,11 @@ public function send($notifiable, InterfaxNotificationContract $notification) if ($message->shouldCheckStatus()) { $message->sleep(); - while ($this->fax->refresh()->status < 0) { + while ($this->getStatus() < 0) { $message->sleep(); } - if ($this->fax->refresh()->status > 0) { + if ($this->getStatus() > 0) { throw CouldNotSendNotification::serviceRespondedWithAnError($message, $this->fax->attributes()); } } @@ -56,4 +53,10 @@ public function send($notifiable, InterfaxNotificationContract $notification) throw CouldNotSendNotification::serviceRespondedWithAnError($message, $attributes, $exceptionMessage); } } + + protected function getStatus(): int + { + $fax = $this->fax->refresh(); + return $fax->status; + } } diff --git a/src/InterfaxFile.php b/src/InterfaxFile.php index c8e045f..75e1112 100644 --- a/src/InterfaxFile.php +++ b/src/InterfaxFile.php @@ -7,8 +7,8 @@ class InterfaxFile extends \Interfax\File /** * File constructor. * - * @param $location - * @param array $params + * @param resource|string $location + * @param array $params * * @throws \InvalidArgumentException */ diff --git a/src/InterfaxMessage.php b/src/InterfaxMessage.php index a2edfc3..52f9b8d 100644 --- a/src/InterfaxMessage.php +++ b/src/InterfaxMessage.php @@ -6,12 +6,17 @@ class InterfaxMessage { + /** @var array> */ protected array $files; + + /** @var resource|false $stream */ protected $stream; protected string $filename; protected string $method; - protected $statusCheck = false; - public $user; + protected bool $statusCheck = false; + public mixed $user; + + /** @var array */ public array $metadata = []; const FILES = 'files'; @@ -20,9 +25,9 @@ class InterfaxMessage const POLLING_INTERVAL_DEFAULT = 15; const POLLING_INTERVAL_MINIMUM = 10; - protected static $DEFAULT_CHUNK_SIZE = 1048576; + protected static int $DEFAULT_CHUNK_SIZE = 1048576; - public function file(string $file) + public function file(string $file): InterfaxMessage { $this->files = Arr::wrap($file); $this->method = static::FILES; @@ -30,6 +35,10 @@ public function file(string $file) return $this; } + /** + * @param array> $files + * @return InterfaxMessage + */ public function files(array $files): InterfaxMessage { $this->files = $files; @@ -38,6 +47,11 @@ public function files(array $files): InterfaxMessage return $this; } + /** + * @param resource|false $stream + * @param string $filename + * @return InterfaxMessage + */ public function stream($stream, string $filename): InterfaxMessage { $this->stream = $stream; @@ -47,10 +61,9 @@ public function stream($stream, string $filename): InterfaxMessage return $this; } - public function checkStatus(bool $shouldCheck = true) + public function checkStatus(bool $shouldCheck = true): InterfaxMessage { $this->statusCheck = $shouldCheck; - return $this; } @@ -68,14 +81,13 @@ public function shouldCheckStatus(): bool public function user($notifiable): InterfaxMessage { $this->user = $notifiable; - return $this; } /** * Add metadata to the message for logging purposes. * - * @param array $data The data to add to the metadata array + * @param array $data The data to add to the metadata array * @return InterfaxMessage */ public function addMetadata(array $data): InterfaxMessage @@ -87,6 +99,9 @@ public function addMetadata(array $data): InterfaxMessage return $this; } + /** + * @return array>|array> + */ public function makeFiles(): array { if ($this->method === static::STREAM) { @@ -102,7 +117,7 @@ public function makeFiles(): array ]; } - return array_map('static::setChunkSize', $this->files); + return array_map(fn ($file) => static::setChunkSize($file), $this->files); } public function sleep(): void @@ -111,7 +126,11 @@ public function sleep(): void sleep(max($interval, static::POLLING_INTERVAL_MINIMUM)); } - protected static function setChunkSize($file) + /** + * @param InterfaxFile|string|array $file + * @return InterfaxFile|array + */ + protected static function setChunkSize(InterfaxFile|string|array $file): InterfaxFile|array { $chunk_size = config('services.interfax.chunk_size', static::$DEFAULT_CHUNK_SIZE); diff --git a/src/InterfaxServiceProvider.php b/src/InterfaxServiceProvider.php index f8dcb05..5fadd23 100644 --- a/src/InterfaxServiceProvider.php +++ b/src/InterfaxServiceProvider.php @@ -7,7 +7,7 @@ class InterfaxServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { $this->app->when(InterfaxChannel::class) ->needs(Client::class) diff --git a/stubs/Resource.stub b/stubs/Resource.stub new file mode 100644 index 0000000..7023f8e --- /dev/null +++ b/stubs/Resource.stub @@ -0,0 +1,23 @@ + + * @author Mike Smith + * @copyright Copyright (c) 2016, InterFAX + * @license MIT + */ + +namespace Interfax; + +/** + * @property-read int $status + */ +abstract class Resource +{ + +}