From 8f43cd3d7c1e9fbf3063bf3fb072b77935ab9eba Mon Sep 17 00:00:00 2001 From: Mohammed Elhaouari Date: Sat, 21 Feb 2026 22:15:05 +0100 Subject: [PATCH] Add formatting --- pint.json | 26 ++++++++++++++++++++++ src/Exceptions/AuthenticationException.php | 2 +- src/Exceptions/RateLimitException.php | 4 ++-- src/Exceptions/ValidationException.php | 2 +- src/Exceptions/WatiApiException.php | 4 ++-- src/WatiClient.php | 21 +++++++++-------- src/WatiEnvironment.php | 8 +++---- tests/Pest.php | 2 ++ 8 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 pint.json diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..0517bba --- /dev/null +++ b/pint.json @@ -0,0 +1,26 @@ +{ + "preset": "laravel", + "rules": { + "array_push": true, + "date_time_immutable": true, + "declare_strict_types": true, + "lowercase_keywords": true, + "lowercase_static_reference": true, + "final_class": false, + "final_internal_class": true, + "final_public_method_for_abstract_class": true, + "fully_qualified_strict_types": true, + "modernize_types_casting": true, + "new_with_parentheses": false, + "no_superfluous_elseif": true, + "no_useless_else": true, + "no_multiple_statements_per_line": true, + "ordered_interfaces": true, + "ordered_traits": true, + "protected_to_private": true, + "self_accessor": true, + "self_static_accessor": true, + "strict_comparison": true, + "visibility_required": true + } +} diff --git a/src/Exceptions/AuthenticationException.php b/src/Exceptions/AuthenticationException.php index 7bb092c..93aaf3c 100644 --- a/src/Exceptions/AuthenticationException.php +++ b/src/Exceptions/AuthenticationException.php @@ -7,7 +7,7 @@ use Psr\Http\Message\ResponseInterface; use Throwable; -class AuthenticationException extends WatiApiException +final class AuthenticationException extends WatiApiException { public function __construct( string $message = 'Authentication failed. Check your bearer token.', diff --git a/src/Exceptions/RateLimitException.php b/src/Exceptions/RateLimitException.php index 7f4156b..36d8e37 100644 --- a/src/Exceptions/RateLimitException.php +++ b/src/Exceptions/RateLimitException.php @@ -7,9 +7,9 @@ use Psr\Http\Message\ResponseInterface; use Throwable; -class RateLimitException extends WatiApiException +final class RateLimitException extends WatiApiException { - protected ?int $retryAfter = null; + private ?int $retryAfter = null; public function __construct( string $message = 'Rate limit exceeded. Please retry after some time.', diff --git a/src/Exceptions/ValidationException.php b/src/Exceptions/ValidationException.php index d4a9c35..34da332 100644 --- a/src/Exceptions/ValidationException.php +++ b/src/Exceptions/ValidationException.php @@ -7,7 +7,7 @@ use Psr\Http\Message\ResponseInterface; use Throwable; -class ValidationException extends WatiApiException +final class ValidationException extends WatiApiException { public function __construct( string $message = 'Validation failed. Check your request parameters.', diff --git a/src/Exceptions/WatiApiException.php b/src/Exceptions/WatiApiException.php index 43396aa..d46c8e1 100644 --- a/src/Exceptions/WatiApiException.php +++ b/src/Exceptions/WatiApiException.php @@ -10,11 +10,11 @@ class WatiApiException extends WatiException { /** @var array|null */ - protected ?array $responseData = null; + private ?array $responseData = null; public function __construct( string $message, - protected int $statusCode, + private readonly int $statusCode, ?ResponseInterface $response = null, ?Throwable $previous = null ) { diff --git a/src/WatiClient.php b/src/WatiClient.php index 5bad568..2a231a2 100644 --- a/src/WatiClient.php +++ b/src/WatiClient.php @@ -17,9 +17,9 @@ use Wati\Http\Exceptions\WatiApiException; use Wati\Http\Exceptions\WatiException; -class WatiClient +final class WatiClient { - protected Client $client; + private Client $client; /** * @var array{ @@ -30,7 +30,7 @@ class WatiClient * proxy: null|string * } */ - protected array $defaultOptions = [ + private array $defaultOptions = [ 'timeout' => 30, 'connect_timeout' => 10, 'verify' => true, @@ -42,7 +42,7 @@ class WatiClient * @param array $options */ public function __construct( - protected WatiEnvironment $environment, + private readonly WatiEnvironment $environment, array $options = [] ) { $config = array_merge($this->defaultOptions, $options); @@ -52,8 +52,11 @@ public function __construct( } /** - * @throws WatiException + * @throws AuthenticationException + * @throws RateLimitException + * @throws ValidationException * @throws WatiApiException + * @throws WatiException */ public function send(RequestInterface $request): ResponseInterface { @@ -100,7 +103,7 @@ public function send(RequestInterface $request): ResponseInterface } } - protected function normalizeRequestPath(RequestInterface $request): RequestInterface + private function normalizeRequestPath(RequestInterface $request): RequestInterface { $uri = $request->getUri(); $path = $uri->getPath(); @@ -113,17 +116,17 @@ protected function normalizeRequestPath(RequestInterface $request): RequestInter return $request; } - protected function hasAuthHeader(RequestInterface $request): bool + private function hasAuthHeader(RequestInterface $request): bool { return array_key_exists('Authorization', $request->getHeaders()); } - protected function injectUserAgentHeaders(RequestInterface $request): RequestInterface + private function injectUserAgentHeaders(RequestInterface $request): RequestInterface { return $request->withHeader('User-Agent', 'WatiHttp-PHP HTTP/1.1'); } - protected function injectSdkHeaders(RequestInterface $request): RequestInterface + private function injectSdkHeaders(RequestInterface $request): RequestInterface { return $request ->withHeader('Wati-SDK-Name', 'wati-http-client') diff --git a/src/WatiEnvironment.php b/src/WatiEnvironment.php index 5cb4266..de03f75 100644 --- a/src/WatiEnvironment.php +++ b/src/WatiEnvironment.php @@ -4,13 +4,13 @@ namespace Wati\Http; -class WatiEnvironment +final readonly class WatiEnvironment { - const int BEARER_PREFIX_LENGTH = 7; // strlen('bearer ') + public const int BEARER_PREFIX_LENGTH = 7; // strlen('bearer ') - protected readonly string $endpoint; + private string $endpoint; - protected readonly string $bearerToken; + private string $bearerToken; /** * Create a new Wati environment. diff --git a/tests/Pest.php b/tests/Pest.php index 8c2ce0a..fe74f58 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,7 @@