Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/AuthenticationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/RateLimitException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/WatiApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
class WatiApiException extends WatiException
{
/** @var array<mixed>|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
) {
Expand Down
21 changes: 12 additions & 9 deletions src/WatiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -30,7 +30,7 @@ class WatiClient
* proxy: null|string
* }
*/
protected array $defaultOptions = [
private array $defaultOptions = [
'timeout' => 30,
'connect_timeout' => 10,
'verify' => true,
Expand All @@ -42,7 +42,7 @@ class WatiClient
* @param array<string, int|bool|string|null> $options
*/
public function __construct(
protected WatiEnvironment $environment,
private readonly WatiEnvironment $environment,
array $options = []
) {
$config = array_merge($this->defaultOptions, $options);
Expand All @@ -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
{
Expand Down Expand Up @@ -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();
Expand All @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions src/WatiEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Test Case
Expand Down