From 2cf79ab841004f30b41626eee58c36c431c7b370 Mon Sep 17 00:00:00 2001 From: ousid Date: Mon, 5 May 2025 13:29:01 +0400 Subject: [PATCH 1/6] udpate readme.md --- README.md | 1 - 1 file changed, 1 deletion(-) 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) --- From 1979c24bf716f1e72273835bcbb08f0da10bff1a Mon Sep 17 00:00:00 2001 From: ousid Date: Mon, 5 May 2025 13:31:48 +0400 Subject: [PATCH 2/6] wip --- phpstan.neon.dist | 2 -- 1 file changed, 2 deletions(-) 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 From 67d836a39cbdceba9a160c01ebf0031d5487f9da Mon Sep 17 00:00:00 2001 From: ousid Date: Mon, 5 May 2025 14:20:16 +0400 Subject: [PATCH 3/6] refactoring --- src/Concerns/InteractsWithHttpRequests.php | 5 ++-- src/Facades/Sendy.php | 1 + src/Resources/Brands.php | 11 ++++++--- src/Resources/Campaigns.php | 15 ++++++++---- src/Resources/Lists.php | 16 ++++++------- src/Resources/Subscribers.php | 27 +++++++++++++--------- src/Sendy.php | 8 +++---- 7 files changed, 50 insertions(+), 33 deletions(-) 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); } } From b83afe94b33ad4d85621b7e32203c69c0683ff52 Mon Sep 17 00:00:00 2001 From: ousid Date: Mon, 5 May 2025 14:26:04 +0400 Subject: [PATCH 4/6] update `composer.json` --- .github/workflows/run-tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index adbcbe3..a9f190f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,7 +31,7 @@ jobs: testbench: 9.* - laravel: 10.* testbench: 8.* - + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} 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", From 5332cfd34a865bc1cbec688ee6a1d61d7d2b4b53 Mon Sep 17 00:00:00 2001 From: ousid Date: Mon, 5 May 2025 14:27:42 +0400 Subject: [PATCH 5/6] update `run-tests.yml` --- .github/workflows/run-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a9f190f..6b1df26 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,6 +31,9 @@ jobs: testbench: 9.* - laravel: 10.* testbench: 8.* + exclude: + - laravel: 10.* + php: 8.4 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} From ef3a50343446d0df535599f1978c86eeb59d536c Mon Sep 17 00:00:00 2001 From: ousid Date: Mon, 5 May 2025 14:32:56 +0400 Subject: [PATCH 6/6] wip --- .github/workflows/run-tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6b1df26..05e4db9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,15 +22,13 @@ 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.* - - laravel: 10.* - testbench: 8.* exclude: - laravel: 10.* php: 8.4