Skip to content

Apply fixes from StyleCI #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2021
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
24 changes: 13 additions & 11 deletions src/MessageAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class MessageAccessor
private string $replace;

public function __construct(
array $values = [],
array $queryFilters = [],
array $headersFilters = [],
array $jsonFilers = [],
array $values = [],
array $queryFilters = [],
array $headersFilters = [],
array $jsonFilers = [],
string $replace = '********'
){
) {
$this->values = $values;
$this->queryFilters = $queryFilters;
$this->headersFilters = $headersFilters;
Expand All @@ -49,16 +49,16 @@ public function getBase(RequestInterface $request): string

$base = '';
if ($uri->getScheme()) {
$base .= $uri->getScheme() . '://';
$base .= $uri->getScheme().'://';
}
if ($uri->getUserInfo()) {
$base .= $uri->getUserInfo() . '@';
$base .= $uri->getUserInfo().'@';
}
if ($uri->getHost()) {
$base .= $uri->getHost();
}
if ($uri->getPort()) {
$base .= ':' . $uri->getPort();
$base .= ':'.$uri->getPort();
}

return $base;
Expand Down Expand Up @@ -87,7 +87,9 @@ public function getHeaders(MessageInterface $message): array
* Determine if the request is JSON.
*
* @see vendor/laravel/framework/src/Illuminate/Http/Client/Request.php
*
* @param MessageInterface $message
*
* @return bool
*/
public function isJson(MessageInterface $message): bool
Expand All @@ -112,7 +114,7 @@ public function getContent(MessageInterface $message): string
$body = json_encode($this->getJson($message));
} else {
$body = $message->getBody()->__toString();
foreach($this->values as $value) {
foreach ($this->values as $value) {
$body = str_replace($value, $this->replace, $body);
}
}
Expand All @@ -139,9 +141,9 @@ protected function replaceParameters(array $array, array $parameters, array $val
}
}

array_walk_recursive( $array, function (&$item) use ($values, $replace, $strict) {
array_walk_recursive($array, function (&$item) use ($values, $replace, $strict) {
foreach ($values as $value) {
if (! $strict && str_contains($item, $value)) {
if (!$strict && str_contains($item, $value)) {
$item = str_replace($value, $replace, $item);
} elseif ($strict && $value === $item) {
$item = $replace;
Expand Down
48 changes: 25 additions & 23 deletions tests/MessageAccessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ public function setUp(): void
'POST',
'https://user:[email protected]:9000/some-path/secret/should-not-be-removed?test=true&search=foo&filter[field1]=A&filter[field2]=B#anchor',
[
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Bearer 1234567890',
],
json_encode([
'data' => [
'foo' => 'bar',
'baz' => [
[
'field_1' => 'value1',
'field_2' => 'value2',
'field_1' => 'value1',
'field_2' => 'value2',
'password' => '123456',
'secret' => 'this is not for everyone',
]
]
'secret' => 'this is not for everyone',
],
],
],
])
);
Expand All @@ -66,8 +66,10 @@ public function test_get_uri()

public function test_get_base()
{
$this->assertEquals('https://user:********@********.example.com:9000',
urldecode($this->messageAccessor->getBase($this->request)));
$this->assertEquals(
'https://user:********@********.example.com:9000',
urldecode($this->messageAccessor->getBase($this->request))
);
}

public function test_get_query()
Expand All @@ -76,7 +78,7 @@ public function test_get_query()

$this->assertIsArray($query);
$this->assertEquals([
'test' => 'true',
'test' => 'true',
'search' => '********',
'filter' => [
'field1' => 'A',
Expand All @@ -91,10 +93,10 @@ public function test_get_headers()

$this->assertIsArray($headers);
$this->assertEquals([
'Accept' => ['application/json'],
'Content-Type' => ['application/json'],
'Accept' => ['application/json'],
'Content-Type' => ['application/json'],
'Authorization' => ['********'],
'Host' => ['********.example.com:9000'],
'Host' => ['********.example.com:9000'],
], $headers);
}

Expand All @@ -114,12 +116,12 @@ public function test_get_json()
'foo' => 'bar',
'baz' => [
[
'field_1' => 'value1',
'field_2' => 'value2',
'field_1' => 'value1',
'field_2' => 'value2',
'password' => '********',
'secret' => 'this is not for everyone', // Note that keys are NOT filtered
]
]
'secret' => 'this is not for everyone', // Note that keys are NOT filtered
],
],
],
], $json);
}
Expand All @@ -133,12 +135,12 @@ public function test_get_content()
'foo' => 'bar',
'baz' => [
[
'field_1' => 'value1',
'field_2' => 'value2',
'field_1' => 'value1',
'field_2' => 'value2',
'password' => '********',
'secret' => 'this is not for everyone', // Note that keys are NOT filtered
]
]
'secret' => 'this is not for everyone', // Note that keys are NOT filtered
],
],
],
]), $content);
}
Expand Down