Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/Curl/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private function prepareResponseOptions($httpClient)
{
curl_setopt($httpClient, CURLOPT_HEADER, true);
curl_setopt($httpClient, CURLOPT_RETURNTRANSFER, true);
curl_setopt($httpClient, CURLOPT_SSL_VERIFYPEER, true);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract a prepareConnectionOptions method for these options.

curl_setopt($httpClient, CURLOPT_SSL_VERIFYHOST, 2);
}

private function execute(RequestInterface $request, $httpClient): ResponseInterface
Expand Down
4 changes: 2 additions & 2 deletions src/Feature/Contacts/ContactsFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
interface ContactsFeature
{
/**
* @param FindContactsBag|null $findContactsBag
* @return Contact[]
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
*/
public function findContacts(FindContactsBag $findContactsBag = null): array;
public function findContacts($findContactsBag = null): array;

public function findContact(FindContactBag $findContactBag): Contact;

Expand Down
4 changes: 2 additions & 2 deletions src/Feature/Contacts/ContactsHttpFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function __construct(RestRequestExecutor $restRequestExecutor, DataFactor
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param FindContactsBag|null $findContactsBag
*/
public function findContacts(FindContactsBag $findContactsBag = null): array
public function findContacts($findContactsBag = null): array
{
$result = $this->restRequestExecutor->read('contacts', (array)$findContactsBag);

Expand Down
9 changes: 6 additions & 3 deletions src/Feature/Sms/Bag/ScheduleSmsBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function setParams(array $params): self
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param bool|null $checkIdx
*/
public function setExternalId(string $idx, bool $checkIdx = null): self
public function setExternalId(string $idx, $checkIdx = null): self
{
$this->idx = [$idx];
$this->checkIdx = $checkIdx;
Expand All @@ -82,7 +82,10 @@ public function setExternalId(string $idx, bool $checkIdx = null): self
* @deprecated
* @see ScheduleSmsBag::setExternalId()
*/
public function setIdx(array $idx, bool $checkIdx = null): self
/**
* @param bool|null $checkIdx
*/
public function setIdx(array $idx, $checkIdx = null): self
{
$this->idx = $idx;
$this->checkIdx = $checkIdx;
Expand Down
9 changes: 6 additions & 3 deletions src/Feature/Sms/Bag/ScheduleSmsToGroupBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public static function withTemplateName(DateTimeInterface $scheduleAt, string $g
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param bool|null $checkIdx
*/
public function setExternalId(string $idx, bool $checkIdx = null): self
public function setExternalId(string $idx, $checkIdx = null): self
{
$this->idx = [$idx];
$this->checkIdx = $checkIdx;
Expand All @@ -70,7 +70,10 @@ public function setExternalId(string $idx, bool $checkIdx = null): self
* @deprecated
* @see ScheduleSmsToGroupBag::setExternalId()
*/
public function setIdx(array $idx, bool $checkIdx = null): self
/**
* @param bool|null $checkIdx
*/
public function setIdx(array $idx, $checkIdx = null): self
{
$this->idx = $idx;
$this->checkIdx = $checkIdx;
Expand Down
4 changes: 2 additions & 2 deletions src/Feature/Sms/Bag/ScheduleSmssBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public function setParams(array $params): self
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param bool|null $checkIdx
*/
public function setExternalId(array $idx, bool $checkIdx = null): self
public function setExternalId(array $idx, $checkIdx = null): self
{
$this->idx = $idx;
$this->checkIdx = $checkIdx;
Expand Down
4 changes: 2 additions & 2 deletions src/Feature/Sms/Bag/SendSmsBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function setParams(array $params): self
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param bool|null $checkIdx
*/
public function setExternalId(string $idx, bool $checkIdx = null): self
public function setExternalId(string $idx, $checkIdx = null): self
{
$this->idx = [$idx];
$this->checkIdx = $checkIdx;
Expand Down
9 changes: 6 additions & 3 deletions src/Feature/Sms/Bag/SendSmsToGroupBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public static function withTemplateName(string $group, string $templateName): se
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param bool|null $checkIdx
*/
public function setExternalId(string $idx, bool $checkIdx = null): self
public function setExternalId(string $idx, $checkIdx = null): self
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is not 100% backward compatible. If someone extended these classes and methods, they would receive a warning for PHP < 8.0:

Warning: Declaration of Smsapi\Client\Tests\Unit\Feature\Sms\Bag\ExtendedSendSmssBag::setExternalId(array $idx, ?bool $checkIdx = NULL): Smsapi\Client\Feature\Sms\Bag\SendSmssBag should be compatible with Smsapi\Client\Feature\Sms\Bag\SendSmssBag::setExternalId(array $idx, $checkIdx = NULL): Smsapi\Client\Feature\Sms\Bag\SendSmssBag in /app/tests/Unit/Feature/Sms/Bag/SendSmssBagTest.php on line 23

and a fatal error for PHP >= 8.0.

Fatal error: Declaration of Smsapi\Client\Tests\Unit\Feature\Sms\Bag\ExtendedSendSmssBag::setExternalId(array $idx, ?bool $checkIdx = null): Smsapi\Client\Feature\Sms\Bag\SendSmssBag must be compatible with Smsapi\Client\Feature\Sms\Bag\SendSmssBag::setExternalId(array $idx, $checkIdx = null): Smsapi\Client\Feature\Sms\Bag\SendSmssBag in /app/tests/Unit/Feature/Sms/Bag/SendSmssBagTest.php on line 23

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is probably no better solution - I'd merge it and release it in the next version of the lib.

{
$this->idx = [$idx];
$this->checkIdx = $checkIdx;
Expand All @@ -63,7 +63,10 @@ public function setExternalId(string $idx, bool $checkIdx = null): self
* @deprecated
* @see SendSmsToGroupBag::setExternalId()
*/
public function setIdx(array $idx, bool $checkIdx = null): self
/**
* @param bool|null $checkIdx
*/
public function setIdx(array $idx, $checkIdx = null): self
{
$this->idx = $idx;
$this->checkIdx = $checkIdx;
Expand Down
4 changes: 2 additions & 2 deletions src/Feature/Sms/Bag/SendSmssBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function setParams(array $params): self
}

/**
* @todo method signature to be changed in next major release as implicitly marking parameter as nullable is deprecated since PHP 8.4
* @param bool|null $checkIdx
*/
public function setExternalId(array $idx, bool $checkIdx = null): self
public function setExternalId(array $idx, $checkIdx = null): self
{
$this->idx = $idx;
$this->checkIdx = $checkIdx;
Expand Down
37 changes: 32 additions & 5 deletions src/Infrastructure/HttpClient/Decorator/LoggerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -26,21 +27,47 @@ public function __construct(ClientInterface $client, LoggerInterface $logger)
public function sendRequest(RequestInterface $request): ResponseInterface
{
$this->logger->info('Request', [
'request' => $request,
'method' => $request->getMethod(),
'uri' => $request->getUri(),
'headers' => $request->getHeaders(),
'body' => $request->getBody()->getContents(),
'headers' => $this->sanitizeHeaders($request->getHeaders()),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default logger is NullLogger. If you're injecting your own logger and have trouble with the logged data, your logger is the place to process it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detach all that logging related stuff from this PR. All the rest is acceptable.

'body' => $this->readBody($request->getBody()),
]);

$response = $this->client->sendRequest($request);

$this->logger->info('Response', [
'response' => $response,
'headers' => $response->getHeaders(),
'body' => $response->getBody()->getContents(),
'body' => $this->readBody($response->getBody()),
]);

return $response;
}

private function readBody(StreamInterface $stream): string
{
if ($stream->isSeekable()) {
$body = (string) $stream;
$stream->rewind();

return $body;
}

return '<non-seekable stream, size=' . ($stream->getSize() ?? 'unknown') . '>';
}

private function sanitizeHeaders(array $headers): array
{
$sensitiveHeaders = ['authorization', 'proxy-authorization'];

foreach ($headers as $name => $values) {
if (in_array(strtolower($name), $sensitiveHeaders, true)) {
$headers[$name] = array_map(function (string $value): string {
$len = strlen($value);
return sprintf('xxxx... (len = %d)', $len);
}, $values);
}
}

return $headers;
}
}
Loading
Loading