Skip to content

Commit 9ec4ad5

Browse files
authored
Merge pull request #17 from ivinteractive/main
Bump PHPStan to level 8; Add more parameter/return typing; README update
2 parents 3e793a3 + fcf6888 commit 9ec4ad5

File tree

9 files changed

+111
-30
lines changed

9 files changed

+111
-30
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# InterFAX notification channel for Laravel 9.x, 10.x
1+
# InterFAX notification channel for Laravel 10.x, 11.x
22

33
[![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)
44
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
55
[![Build Status](https://img.shields.io/travis/laravel-notification-channels/interfax/main.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/interfax)
66
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/interfax.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/interfax)
77

8-
This package makes it easy to send notifications using [InterFAX](https://interfax.net) with Laravel 9.x and 10.x.
8+
This package makes it easy to send notifications using [InterFAX](https://interfax.net) with Laravel 10.x and 11.x.
99

1010
## Contents
1111

@@ -140,4 +140,4 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
140140

141141
## License
142142

143-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
143+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

phpstan.neon

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ parameters:
33
paths:
44
- src/
55

6-
level: 5
6+
level: 8
7+
8+
ignoreErrors:
9+
-
10+
identifier: ternary.alwaysTrue
11+
path: src/InterfaxChannel.php
12+
13+
stubFiles:
14+
- stubs/Resource.stub

src/Contracts/InterfaxNotificationContract.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66

77
interface InterfaxNotificationContract
88
{
9+
/**
10+
* @param mixed $notifiable
11+
* @return InterfaxMessage
12+
*/
913
public function toInterfax($notifiable): InterfaxMessage;
1014
}

src/Exceptions/CouldNotSendNotification.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77

88
class CouldNotSendNotification extends Exception
99
{
10-
protected $interfaxMessage;
11-
protected $responseAttributes;
10+
protected InterfaxMessage $interfaxMessage;
1211

12+
/** @var array<string, mixed> */
13+
protected array $responseAttributes;
14+
15+
/**
16+
* @param string $message
17+
* @param int $code
18+
* @param Exception|null $previous
19+
* @param InterfaxMessage $interfaxMessage
20+
* @param array<string, mixed> $responseAttributes
21+
*/
1322
final public function __construct(string $message, int $code, Exception $previous = null, InterfaxMessage $interfaxMessage, array $responseAttributes)
1423
{
1524
parent::__construct($message, $code, $previous);
@@ -18,22 +27,37 @@ final public function __construct(string $message, int $code, Exception $previou
1827
$this->responseAttributes = $responseAttributes;
1928
}
2029

21-
public static function serviceRespondedWithAnError($message, $responseAttributes, string $exceptionMessage = 'The fax failed to send via InterFAX.')
30+
/**
31+
* @param InterfaxMessage $message
32+
* @param array<string, mixed> $responseAttributes
33+
* @param string $exceptionMessage
34+
* @return CouldNotSendNotification
35+
*/
36+
public static function serviceRespondedWithAnError(InterfaxMessage $message, array $responseAttributes, string $exceptionMessage = 'The fax failed to send via InterFAX.')
2237
{
2338
return new static($exceptionMessage, $responseAttributes['status'], null, $message, $responseAttributes);
2439
}
2540

41+
/**
42+
* @return mixed
43+
*/
2644
public function getUser()
2745
{
2846
return $this->interfaxMessage->user;
2947
}
3048

31-
public function getMetadata()
49+
/**
50+
* @return array<string, mixed>
51+
*/
52+
public function getMetadata(): array
3253
{
3354
return $this->interfaxMessage->metadata;
3455
}
3556

36-
public function getAttributes()
57+
/**
58+
* @return array<string, mixed>
59+
*/
60+
public function getAttributes(): array
3761
{
3862
return $this->responseAttributes;
3963
}

src/InterfaxChannel.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88

99
class InterfaxChannel
1010
{
11-
protected $client;
11+
/** @var \Interfax\Outbound\Fax $fax */
1212
protected $fax;
1313

14-
public function __construct(Client $client)
15-
{
16-
$this->client = $client;
17-
}
14+
public function __construct(protected Client $client) {}
1815

1916
/**
2017
* Send the given notification.
@@ -24,7 +21,7 @@ public function __construct(Client $client)
2421
*
2522
* @throws \NotificationChannels\Interfax\Exceptions\CouldNotSendNotification
2623
*/
27-
public function send($notifiable, InterfaxNotificationContract $notification)
24+
public function send($notifiable, InterfaxNotificationContract $notification): void
2825
{
2926
if (! $faxNumber = $notifiable->routeNotificationFor('interfax')) {
3027
return;
@@ -41,11 +38,11 @@ public function send($notifiable, InterfaxNotificationContract $notification)
4138
if ($message->shouldCheckStatus()) {
4239
$message->sleep();
4340

44-
while ($this->fax->refresh()->status < 0) {
41+
while ($this->getStatus() < 0) {
4542
$message->sleep();
4643
}
4744

48-
if ($this->fax->refresh()->status > 0) {
45+
if ($this->getStatus() > 0) {
4946
throw CouldNotSendNotification::serviceRespondedWithAnError($message, $this->fax->attributes());
5047
}
5148
}
@@ -56,4 +53,10 @@ public function send($notifiable, InterfaxNotificationContract $notification)
5653
throw CouldNotSendNotification::serviceRespondedWithAnError($message, $attributes, $exceptionMessage);
5754
}
5855
}
56+
57+
protected function getStatus(): int
58+
{
59+
$fax = $this->fax->refresh();
60+
return $fax->status;
61+
}
5962
}

src/InterfaxFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class InterfaxFile extends \Interfax\File
77
/**
88
* File constructor.
99
*
10-
* @param $location
11-
* @param array $params
10+
* @param resource|string $location
11+
* @param array<string, mixed> $params
1212
*
1313
* @throws \InvalidArgumentException
1414
*/

src/InterfaxMessage.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66

77
class InterfaxMessage
88
{
9+
/** @var array<int, InterfaxFile|string|array<string, mixed>> */
910
protected array $files;
11+
12+
/** @var resource|false $stream */
1013
protected $stream;
1114
protected string $filename;
1215
protected string $method;
13-
protected $statusCheck = false;
14-
public $user;
16+
protected bool $statusCheck = false;
17+
public mixed $user;
18+
19+
/** @var array<string, mixed> */
1520
public array $metadata = [];
1621

1722
const FILES = 'files';
@@ -20,16 +25,20 @@ class InterfaxMessage
2025
const POLLING_INTERVAL_DEFAULT = 15;
2126
const POLLING_INTERVAL_MINIMUM = 10;
2227

23-
protected static $DEFAULT_CHUNK_SIZE = 1048576;
28+
protected static int $DEFAULT_CHUNK_SIZE = 1048576;
2429

25-
public function file(string $file)
30+
public function file(string $file): InterfaxMessage
2631
{
2732
$this->files = Arr::wrap($file);
2833
$this->method = static::FILES;
2934

3035
return $this;
3136
}
3237

38+
/**
39+
* @param array<int, array<string, mixed>> $files
40+
* @return InterfaxMessage
41+
*/
3342
public function files(array $files): InterfaxMessage
3443
{
3544
$this->files = $files;
@@ -38,6 +47,11 @@ public function files(array $files): InterfaxMessage
3847
return $this;
3948
}
4049

50+
/**
51+
* @param resource|false $stream
52+
* @param string $filename
53+
* @return InterfaxMessage
54+
*/
4155
public function stream($stream, string $filename): InterfaxMessage
4256
{
4357
$this->stream = $stream;
@@ -47,10 +61,9 @@ public function stream($stream, string $filename): InterfaxMessage
4761
return $this;
4862
}
4963

50-
public function checkStatus(bool $shouldCheck = true)
64+
public function checkStatus(bool $shouldCheck = true): InterfaxMessage
5165
{
5266
$this->statusCheck = $shouldCheck;
53-
5467
return $this;
5568
}
5669

@@ -68,14 +81,13 @@ public function shouldCheckStatus(): bool
6881
public function user($notifiable): InterfaxMessage
6982
{
7083
$this->user = $notifiable;
71-
7284
return $this;
7385
}
7486

7587
/**
7688
* Add metadata to the message for logging purposes.
7789
*
78-
* @param array $data The data to add to the metadata array
90+
* @param array<string, mixed> $data The data to add to the metadata array
7991
* @return InterfaxMessage
8092
*/
8193
public function addMetadata(array $data): InterfaxMessage
@@ -87,6 +99,9 @@ public function addMetadata(array $data): InterfaxMessage
8799
return $this;
88100
}
89101

102+
/**
103+
* @return array<int, InterfaxFile|array<string, mixed>>|array<int, array<int, mixed>>
104+
*/
90105
public function makeFiles(): array
91106
{
92107
if ($this->method === static::STREAM) {
@@ -102,7 +117,7 @@ public function makeFiles(): array
102117
];
103118
}
104119

105-
return array_map('static::setChunkSize', $this->files);
120+
return array_map(fn ($file) => static::setChunkSize($file), $this->files);
106121
}
107122

108123
public function sleep(): void
@@ -111,7 +126,11 @@ public function sleep(): void
111126
sleep(max($interval, static::POLLING_INTERVAL_MINIMUM));
112127
}
113128

114-
protected static function setChunkSize($file)
129+
/**
130+
* @param InterfaxFile|string|array<string, mixed> $file
131+
* @return InterfaxFile|array<string, mixed>
132+
*/
133+
protected static function setChunkSize(InterfaxFile|string|array $file): InterfaxFile|array
115134
{
116135
$chunk_size = config('services.interfax.chunk_size', static::$DEFAULT_CHUNK_SIZE);
117136

src/InterfaxServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class InterfaxServiceProvider extends ServiceProvider
99
{
10-
public function boot()
10+
public function boot(): void
1111
{
1212
$this->app->when(InterfaxChannel::class)
1313
->needs(Client::class)

stubs/Resource.stub

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Interfax
5+
*
6+
* (C) InterFAX, 2016
7+
*
8+
* @package interfax/interfax
9+
* @author Interfax <[email protected]>
10+
* @author Mike Smith <[email protected]>
11+
* @copyright Copyright (c) 2016, InterFAX
12+
* @license MIT
13+
*/
14+
15+
namespace Interfax;
16+
17+
/**
18+
* @property-read int $status
19+
*/
20+
abstract class Resource
21+
{
22+
23+
}

0 commit comments

Comments
 (0)