diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index adbcbe3..05e4db9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,16 +22,17 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] php: [8.4, 8.3] - laravel: [12.*, 11.*, 10.*] + laravel: [12.*, 11.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 12.* testbench: 10.* - laravel: 11.* testbench: 9.* + exclude: - laravel: 10.* - testbench: 8.* - + php: 8.4 + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/README.md b/README.md index 028ec06..092c6ca 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/coderflexx/laravel-sendy.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravel-sendy) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/coderflexx/laravel-sendy/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/coderflexx/laravel-sendy/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/coderflexx/laravel-sendy/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/coderflexx/laravel-sendy/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) -[![Total Downloads](https://img.shields.io/packagist/dt/coderflexx/laravel-sendy.svg?style=flat-square)](https://packagist.org/packages/coderflexx/laravel-sendy) --- diff --git a/composer.json b/composer.json index b24cf97..81afbf5 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^8.4", + "php": "^8.3", "ext-curl": "*", "ext-json": "*", "illuminate/contracts": "^10.0||^11.0||^12.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ab1b4c3..d8fd46c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,8 +5,6 @@ parameters: level: 5 paths: - src - - config - - database tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true diff --git a/src/Concerns/InteractsWithHttpRequests.php b/src/Concerns/InteractsWithHttpRequests.php index 8469568..0553138 100644 --- a/src/Concerns/InteractsWithHttpRequests.php +++ b/src/Concerns/InteractsWithHttpRequests.php @@ -5,6 +5,7 @@ use Coderflex\LaravelSendy\Exceptions\InvalidApiKeyException; use Coderflex\LaravelSendy\Exceptions\InvalidApiUrlException; use Exception; +use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Http; /** @@ -16,7 +17,7 @@ */ trait InteractsWithHttpRequests { - public function __call(string $function, array $args): mixed + public function __call(string $function, array $args): Response { $options = ['get', 'post', 'put', 'delete', 'patch']; $path = $args[0] ?? null; @@ -65,7 +66,7 @@ protected function sendRequest(string $type, string $request, array $data = [], $client = Http::withHeaders(array_merge([ 'Content-Type' => 'application/json', 'Accept' => 'application/json', - ], $headers ?? [])); + ], $headers)); return $async ? $client->async()->{$type}($url, $payload) diff --git a/src/Facades/Sendy.php b/src/Facades/Sendy.php index 2adc9fa..948070a 100644 --- a/src/Facades/Sendy.php +++ b/src/Facades/Sendy.php @@ -11,6 +11,7 @@ * @method static \Coderflex\LaravelSendy\Resources\Lists lists() * @method static \Coderflex\LaravelSendy\Resources\Brands brands() * @method static \Coderflex\LaravelSendy\Resources\Campaigns campaigns() + * @method static mixed post(string $endpoint, array $data, bool $async = false) */ class Sendy extends Facade { diff --git a/src/Resources/Brands.php b/src/Resources/Brands.php index 4f2a9b2..4386428 100644 --- a/src/Resources/Brands.php +++ b/src/Resources/Brands.php @@ -2,12 +2,17 @@ namespace Coderflex\LaravelSendy\Resources; -use Coderflex\LaravelSendy\Facades\Sendy; +use Coderflex\LaravelSendy\Sendy; +use Illuminate\Http\Client\Response; class Brands { - public function get() + public function __construct( + protected Sendy $sendy + ) {} + + public function get(): Response { - return Sendy::post('/api/brands/get-brands.php'); + return $this->sendy->post('/api/brands/get-brands.php'); } } diff --git a/src/Resources/Campaigns.php b/src/Resources/Campaigns.php index ecc9977..7484172 100644 --- a/src/Resources/Campaigns.php +++ b/src/Resources/Campaigns.php @@ -3,23 +3,28 @@ namespace Coderflex\LaravelSendy\Resources; use Coderflex\LaravelSendy\DTOs\Campaigns\CampaignDTO; -use Coderflex\LaravelSendy\Facades\Sendy; +use Coderflex\LaravelSendy\Sendy; +use Illuminate\Http\Client\Response; class Campaigns { - public function create(array $data, bool $async = false) + public function __construct( + protected Sendy $sendy + ) {} + + public function create(array $data, bool $async = false): Response { $data = CampaignDTO::validate($data); - return Sendy::post('/api/campaigns/create.php', $data, $async); + return $this->sendy->post('/api/campaigns/create.php', $data, $async); } - public function createAndSend(array $data, bool $async = false) + public function createAndSend(array $data, bool $async = false): Response { $data = array_merge($data, [ 'send_compaign' => 1, ]); - return Sendy::post('/api/campaigns/create.php', $data, $async); + return $this->sendy->post('/api/campaigns/create.php', $data, $async); } } diff --git a/src/Resources/Lists.php b/src/Resources/Lists.php index abbc42f..eb80c9f 100644 --- a/src/Resources/Lists.php +++ b/src/Resources/Lists.php @@ -3,19 +3,19 @@ namespace Coderflex\LaravelSendy\Resources; use Coderflex\LaravelSendy\DTOs\Lists\ListsDTO; -use Coderflex\LaravelSendy\Facades\Sendy; +use Coderflex\LaravelSendy\Sendy; +use Illuminate\Http\Client\Response; class Lists { - /** - * Get all lists for a specific brand. - * - * @return array - */ - public function get(array $data, bool $async = false) + public function __construct( + protected Sendy $sendy + ) {} + + public function get(array $data, bool $async = false): Response { $data = ListsDTO::validate($data); - return Sendy::post('/api/lists/get-lists.php', $data, $async); + return $this->sendy->post('/api/lists/get-lists.php', $data, $async); } } diff --git a/src/Resources/Subscribers.php b/src/Resources/Subscribers.php index afd833d..31f1d5c 100644 --- a/src/Resources/Subscribers.php +++ b/src/Resources/Subscribers.php @@ -6,44 +6,49 @@ use Coderflex\LaravelSendy\DTOs\Subscribers\SubscribeDTO; use Coderflex\LaravelSendy\DTOs\Subscribers\SubscriberStatusDTO; use Coderflex\LaravelSendy\DTOs\Subscribers\UnsubscribeDTO; -use Coderflex\LaravelSendy\Facades\Sendy; +use Coderflex\LaravelSendy\Sendy; +use Illuminate\Http\Client\Response; class Subscribers { - public function subscribe(array $data, bool $async = false) + public function __construct( + protected Sendy $sendy + ) {} + + public function subscribe(array $data, bool $async = false): Response { $data = SubscribeDTO::validate($data); - return Sendy::post('subscribe', $data, $async); + return $this->sendy->post('subscribe', $data, $async); } - public function unsubscribe(array $data, bool $async = false) + public function unsubscribe(array $data, bool $async = false): Response { $data = UnsubscribeDTO::validate($data); - return Sendy::post('api/subscribers/unsubscribe.php', $data, $async); + return $this->sendy->post('api/subscribers/unsubscribe.php', $data, $async); } - public function delete(array $data, bool $async = false) + public function delete(array $data, bool $async = false): Response { $data = DeleteSubscriberDTO::validate($data); - return Sendy::post('api/subscribers/delete.php', $data, $async); + return $this->sendy->post('api/subscribers/delete.php', $data, $async); } - public function status(array $data, bool $async = false) + public function status(array $data, bool $async = false): Response { $data = SubscriberStatusDTO::validate($data); - return Sendy::post('api/subscribers/subscription-status.php', $data, $async); + return $this->sendy->post('api/subscribers/subscription-status.php', $data, $async); } - public function count(int $listId, bool $async = false) + public function count(int $listId, bool $async = false): Response { $data = [ 'list_id' => $listId, ]; - return Sendy::post('api/subscribers/subscriber-count.php', $data, $async); + return $this->sendy->post('api/subscribers/subscriber-count.php', $data, $async); } } diff --git a/src/Sendy.php b/src/Sendy.php index 2abdd1a..48df8e3 100644 --- a/src/Sendy.php +++ b/src/Sendy.php @@ -10,21 +10,21 @@ class Sendy public function subscribers(): Resources\Subscribers { - return new Resources\Subscribers; + return new Resources\Subscribers($this); } public function lists(): Resources\Lists { - return new Resources\Lists; + return new Resources\Lists($this); } public function brands(): Resources\Brands { - return new Resources\Brands; + return new Resources\Brands($this); } public function campaigns(): Resources\Campaigns { - return new Resources\Campaigns; + return new Resources\Campaigns($this); } }