Skip to content

Commit 1889547

Browse files
committed
update README and phpstan configuration for clarity and consistency
1 parent 43f879c commit 1889547

File tree

2 files changed

+100
-144
lines changed

2 files changed

+100
-144
lines changed

README.md

Lines changed: 99 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,68 @@
11
# Laravel SmsApi Notification Channel
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/webxscripts/laravel-smsapi-notification-channel.svg?style=flat-square)](https://packagist.org/packages/webxscripts/laravel-smsapi-notification-channel)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/webxscripts/laravel-smsapi-notification-channel/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/webxscripts/laravel-smsapi-notification-channel/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/webxscripts/laravel-smsapi-notification-channel/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/webxscripts/laravel-smsapi-notification-channel/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
3+
[![Latest Version](https://img.shields.io/packagist/v/webxscripts/laravel-smsapi-notification-channel.svg?style=flat-square)](https://packagist.org/packages/webxscripts/laravel-smsapi-notification-channel)
4+
[![Tests](https://img.shields.io/github/actions/workflow/status/webxscripts/laravel-smsapi-notification-channel/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/webxscripts/laravel-smsapi-notification-channel/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![Code Style](https://img.shields.io/github/actions/workflow/status/webxscripts/laravel-smsapi-notification-channel/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/webxscripts/laravel-smsapi-notification-channel/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/webxscripts/laravel-smsapi-notification-channel.svg?style=flat-square)](https://packagist.org/packages/webxscripts/laravel-smsapi-notification-channel)
77

8-
Modern Laravel Notification Channel for SmsApi PHP Client with support for Laravel 11+ and PHP 8.2+.
8+
A Laravel 11+ notification channel for [SmsApi](https://www.smsapi.com/) with PHP 8.2+ support.
99

10-
## Features
10+
---
1111

12-
- 🚀 **Modern PHP 8.2+ features** - Readonly classes, named arguments, match expressions
13-
- 📱 **Full SmsApi support** - All SmsApi features including templates, parameters, and delivery options
14-
- 🔧 **Type-safe** - Full type hints and PHPStan level 8 compliance
15-
- 🧪 **Well tested** - Comprehensive test suite with Pest PHP
16-
- 🎯 **Laravel 11+ optimized** - Built specifically for modern Laravel versions
17-
- 🔒 **Immutable messages** - Thread-safe message building with fluent interface
18-
- 📋 **Multiple phone resolution methods** - Flexible ways to get phone numbers from notifiables
12+
## Requirements
1913

20-
## Installation
14+
- PHP 8.2 or higher
15+
- Laravel 11 or newer
16+
- SmsApi account and API token
2117

22-
```bash
23-
composer require webxscripts/laravel-smsapi-notification-channel
24-
```
18+
---
2519

26-
Publish the configuration file:
20+
## Installation
2721

2822
```bash
23+
composer require webxscripts/laravel-smsapi-notification-channel
2924
php artisan vendor:publish --tag=smsapi-config
3025
```
3126

27+
---
28+
3229
## Configuration
3330

34-
Add these environment variables to your `.env` file:
31+
Add the following to your `.env` file:
3532

3633
```env
3734
SMSAPI_TOKEN=your_api_token_here
3835
SMSAPI_SERVICE=com
3936
SMSAPI_FROM=YourApp
4037
```
4138

42-
### Available Services
43-
44-
- `com` - SMSAPI.COM (international, default)
45-
- `pl` - SMSAPI.PL (Poland)
46-
47-
For SMSAPI.SE or SMSAPI.BG, use:
48-
```env
49-
SMSAPI_SERVICE=com
50-
SMSAPI_URI=https://api.smsapi.se/
51-
```
39+
Supported services:
40+
- `com` (default)
41+
- `pl`
42+
- For other regions, use:
43+
```env
44+
SMSAPI_URI=https://api.smsapi.se/
45+
```
5246

53-
## Usage
47+
---
5448

55-
### Basic Usage
49+
## Basic Usage
5650

5751
Create a notification:
5852

5953
```bash
6054
php artisan make:notification OrderConfirmation
6155
```
6256

63-
Implement the `toSmsApi` method:
57+
Example implementation:
6458

6559
```php
66-
<?php
67-
68-
namespace App\Notifications;
69-
7060
use Illuminate\Notifications\Notification;
7161
use WebXScripts\SmsApiNotification\SmsApiMessage;
7262

7363
class OrderConfirmation extends Notification
7464
{
75-
public function __construct(
76-
private readonly string $orderNumber
77-
) {}
65+
public function __construct(private string $orderNumber) {}
7866

7967
public function via($notifiable): array
8068
{
@@ -83,150 +71,121 @@ class OrderConfirmation extends Notification
8371

8472
public function toSmsApi($notifiable): SmsApiMessage
8573
{
86-
return SmsApiMessage::create("Your order #{$this->orderNumber} has been confirmed!")
74+
return SmsApiMessage::create("Order #{$this->orderNumber} confirmed.")
8775
->from('MyShop');
8876
}
8977
}
9078
```
9179

92-
### Advanced Usage with All Options
80+
---
81+
82+
## Advanced Example
9383

9484
```php
95-
public function toSmsApi($notifiable): SmsApiMessage
96-
{
97-
return SmsApiMessage::create('Your verification code: 123456')
98-
->from('MyApp')
99-
->encoding('utf-8')
100-
->test(app()->environment('testing'))
101-
->fast(true)
102-
->normalize(true)
103-
->single(false)
104-
->expirationDate(now()->addMinutes(5))
105-
->notifyUrl('https://example.com/sms-delivery-report')
106-
->template('verification_code')
107-
->param1($this->code)
108-
->param2($notifiable->name);
109-
}
85+
SmsApiMessage::create('Code: 123456')
86+
->from('MyApp')
87+
->encoding('utf-8')
88+
->test(app()->environment('testing'))
89+
->fast(true)
90+
->normalize(true)
91+
->single(false)
92+
->expirationDate(now()->addMinutes(5))
93+
->notifyUrl('https://example.com/sms-delivery')
94+
->template('verification_code')
95+
->param1($this->code)
96+
->param2($notifiable->name);
11097
```
11198

112-
### Phone Number Resolution
113-
114-
The channel resolves phone numbers in this priority order:
99+
---
115100

116-
1. **SmsApiNotifiable interface** (recommended):
117-
```php
118-
use WebXScripts\SmsApiNotification\Contracts\SmsApiNotifiable;
119-
120-
class User extends Model implements SmsApiNotifiable
121-
{
122-
public function getSmsApiPhoneNumber(): string
123-
{
124-
return $this->phone_number;
125-
}
126-
}
127-
```
101+
## Phone Number Resolution Order
128102

129-
2. **Notification routing method**:
130-
```php
131-
class User extends Model
132-
{
133-
public function routeNotificationForSmsApi(): string
134-
{
135-
return $this->phone_number;
136-
}
137-
}
138-
```
103+
1. `SmsApiNotifiable` interface:
104+
```php
105+
public function getSmsApiPhoneNumber(): string
106+
{
107+
return $this->phone_number;
108+
}
109+
```
139110

140-
3. **Generic SMS routing method**:
141-
```php
142-
public function routeNotificationForSms(): string
143-
{
144-
return $this->phone;
145-
}
146-
```
111+
2. `routeNotificationForSmsApi()` method
112+
3. `routeNotificationForSms()` method
113+
4. Model attributes: `phone` or `phone_number`
147114

148-
4. **Model attributes**: `phone` or `phone_number`
115+
---
149116

150-
### Sending Notifications
117+
## Sending Notifications
151118

152119
```php
153-
use App\Notifications\OrderConfirmation;
154-
155-
// Single user
156-
$user = User::find(1);
157120
$user->notify(new OrderConfirmation('ORD-12345'));
158121

159-
// Multiple users
160-
$users = User::whereNotNull('phone')->get();
161122
Notification::send($users, new OrderConfirmation('ORD-12345'));
162123

163-
// On-demand notifications
164124
Notification::route('smsapi', '+48123456789')
165125
->notify(new OrderConfirmation('ORD-12345'));
166126
```
167127

168-
## Available Message Methods
128+
---
169129

170-
All methods return a new immutable instance:
130+
## Available Message Methods
171131

172132
```php
173-
SmsApiMessage::create('content')
174-
->from(string $sender) // Sender name/number
175-
->encoding(string $encoding) // Message encoding (default: utf-8)
176-
->test(bool $test) // Test mode
177-
->fast(bool $fast) // Fast delivery
178-
->normalize(bool $normalize) // Normalize phone numbers
179-
->noUnicode(bool $noUnicode) // Disable unicode
180-
->single(bool $single) // Send as single message
181-
->notifyUrl(string $url) // Delivery report webhook URL
182-
->expirationDate(DateTimeInterface $date) // Message expiration
183-
->timeRestriction(string $restriction) // Time-based delivery restrictions
184-
->partnerId(string $partnerId) // Partner ID
185-
->checkIdx(bool $checkIdx) // Validate IDX
186-
->idx(array $idx) // IDX array for external tracking
187-
->template(string $template) // Template name
188-
->param1(string $param) // Template parameter 1
189-
->param2(string $param) // Template parameter 2
190-
->param3(string $param) // Template parameter 3
191-
->param4(string $param); // Template parameter 4
133+
SmsApiMessage::create('...')
134+
->from(string)
135+
->encoding(string)
136+
->test(bool)
137+
->fast(bool)
138+
->normalize(bool)
139+
->noUnicode(bool)
140+
->single(bool)
141+
->notifyUrl(string)
142+
->expirationDate(DateTimeInterface)
143+
->timeRestriction(string)
144+
->partnerId(string)
145+
->checkIdx(bool)
146+
->idx(array)
147+
->template(string)
148+
->param1(string)
149+
->param2(string)
150+
->param3(string)
151+
->param4(string);
192152
```
193153

154+
All methods return an immutable instance.
155+
156+
---
157+
194158
## Error Handling
195159

196-
The package includes specific exceptions:
160+
Custom exceptions provided:
197161

198-
```php
199-
use WebXScripts\SmsApiNotification\Exceptions\{
200-
InvalidNotificationException,
201-
MissingApiTokenException,
202-
MissingPhoneNumberException
203-
};
162+
- `MissingPhoneNumberException`
163+
- `MissingApiTokenException`
164+
- `InvalidNotificationException`
165+
166+
Example:
204167

168+
```php
205169
try {
206170
$user->notify(new OrderConfirmation('ORD-12345'));
207171
} catch (MissingPhoneNumberException $e) {
208-
Log::warning('User has no phone number', ['user' => $user->id]);
209-
} catch (MissingApiTokenException $e) {
210-
Log::error('SmsApi token not configured');
172+
Log::warning('User has no phone number');
211173
}
212174
```
213175

214-
## Testing
215-
216-
```bash
217-
# Run tests
218-
composer test
219-
220-
# Run tests with coverage
221-
composer test-coverage
176+
---
222177

223-
# Format code
224-
composer format
178+
## Testing & Code Quality
225179

226-
# Analyze code
227-
composer analyse
180+
```bash
181+
composer test # Run tests
182+
composer test-coverage # Run with coverage
183+
composer format # Format code
184+
composer analyse # Static analysis
228185
```
229186

187+
---
188+
230189
## License
231190

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

phpstan.neon

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@ parameters:
33
paths:
44
- src
55
- tests
6-
tmpDir: build/phpstan
7-
checkOctaneCompatibility: true
8-
checkModelProperties: true
9-
checkMissingIterableValueType: false
6+
tmpDir: build/phpstan

0 commit comments

Comments
 (0)