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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"tiny-blocks/collection": "^2.6"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.52",
"infection/infection": "^0.34",
"phpstan/phpstan": "^2.2",
"phpunit/phpunit": "^13.2",
"ergebnis/composer-normalize": "^2.54",
"infection/infection": "^0.35",
"phpstan/phpstan": "^2.3",
"phpunit/phpunit": "^13.4",
"slevomat/coding-standard": "^8.31",
"squizlabs/php_codesniffer": "^4.0"
},
Expand Down Expand Up @@ -74,7 +74,7 @@
"test-file": "@php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage --filter",
"tests": [
"@php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests",
"@php ./vendor/bin/infection --threads=max --logger-html=reports/coverage/mutation-report.html --coverage=reports/coverage"
"@php ./vendor/bin/infection --threads=max --logger-html=reports/coverage/mutation-report.html"
]
}
}
48 changes: 24 additions & 24 deletions src/Internal/Redactor/VisibleShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@ enum VisibleShape: string
case WORDS = 'WORDS';
case LOCAL_PART = 'LOCAL_PART';

public function applyTo(Mask $mask, string $value, int $prefixLength, int $suffixLength): string
{
return match ($this) {
VisibleShape::EDGES => VisibleShape::edges(
mask: $mask,
value: $value,
prefixLength: $prefixLength,
suffixLength: $suffixLength
),
VisibleShape::WORDS => VisibleShape::words(
mask: $mask,
value: $value,
prefixLength: $prefixLength,
suffixLength: $suffixLength
),
VisibleShape::LOCAL_PART => VisibleShape::localPart(
mask: $mask,
value: $value,
prefixLength: $prefixLength,
suffixLength: $suffixLength
)
};
}

private static function edges(Mask $mask, string $value, int $prefixLength, int $suffixLength): string
{
$totalLength = mb_strlen($value, 'UTF-8');
Expand Down Expand Up @@ -89,4 +65,28 @@ private static function localPart(Mask $mask, string $value, int $prefixLength,
mb_substr($value, $atPosition, null, 'UTF-8')
);
}

public function applyTo(Mask $mask, string $value, int $prefixLength, int $suffixLength): string
{
return match ($this) {
VisibleShape::EDGES => VisibleShape::edges(
mask: $mask,
value: $value,
prefixLength: $prefixLength,
suffixLength: $suffixLength
),
VisibleShape::WORDS => VisibleShape::words(
mask: $mask,
value: $value,
prefixLength: $prefixLength,
suffixLength: $suffixLength
),
VisibleShape::LOCAL_PART => VisibleShape::localPart(
mask: $mask,
value: $value,
prefixLength: $prefixLength,
suffixLength: $suffixLength
)
};
}
}
42 changes: 21 additions & 21 deletions src/Metrics/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,6 @@ public static function of(string $name, string $namespace): Metric
);
}

/**
* Returns a copy of the metric carrying no field at all.
*
* <p>What survives a redaction is what the record should carry, so a caller that filters the
* fields rebuilds them from an empty one instead of writing over the originals: a field the
* filter dropped has no value to write, and would otherwise stay.</p>
*
* @return Metric A copy with every field removed.
*/
public function withoutFields(): Metric
{
return new Metric(
name: $this->name,
unit: $this->unit,
value: $this->value,
fields: [],
namespace: $this->namespace,
dimensions: $this->dimensions
);
}

/**
* Returns a copy of the metric expressed in another unit.
*
Expand Down Expand Up @@ -162,4 +141,25 @@ public function withDimension(string $name, string $value): Metric
dimensions: [...$this->dimensions, $name => MetricDimension::of(name: $name, value: $value)]
);
}

/**
* Returns a copy of the metric carrying no field at all.
*
* <p>What survives a redaction is what the record should carry, so a caller that filters the
* fields rebuilds them from an empty one instead of writing over the originals: a field the
* filter dropped has no value to write, and would otherwise stay.</p>
*
* @return Metric A copy with every field removed.
*/
public function withoutFields(): Metric
{
return new Metric(
name: $this->name,
unit: $this->unit,
value: $this->value,
fields: [],
namespace: $this->namespace,
dimensions: $this->dimensions
);
}
}
4 changes: 2 additions & 2 deletions src/Redactions/BirthDateRedaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*/
final readonly class BirthDateRedaction implements Redaction
{
private const int DEFAULT_VISIBLE_PREFIX_LENGTH = 4;

private const array DEFAULT_FIELDS = ['birth*date', 'date_of_birth'];

private const int DEFAULT_VISIBLE_PREFIX_LENGTH = 4;

private Redaction $redactor;

private function __construct(array $fields, int $visiblePrefixLength)
Expand Down
4 changes: 2 additions & 2 deletions src/Redactions/PostalCodeRedaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*/
final readonly class PostalCodeRedaction implements Redaction
{
private const int DEFAULT_VISIBLE_PREFIX_LENGTH = 3;

private const array DEFAULT_FIELDS = ['post*code', 'zip*code'];

private const int DEFAULT_VISIBLE_PREFIX_LENGTH = 3;

private Redaction $redactor;

private function __construct(array $fields, int $visiblePrefixLength)
Expand Down
14 changes: 7 additions & 7 deletions src/Redactions/QueryParametersRedaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ private function __construct(array $fields)
}

/**
* Creates a QueryParametersRedaction keeping only the named parameters readable.
* Builds a QueryParametersRedaction masking every query parameter.
*
* @param string[] $fields The parameter names left untouched, wildcards accepted.
* @return QueryParametersRedaction The created instance.
*/
public static function keeping(array $fields): QueryParametersRedaction
public static function default(): QueryParametersRedaction
{
return new QueryParametersRedaction(fields: $fields);
return QueryParametersRedaction::keeping(fields: []);
}

/**
* Builds a QueryParametersRedaction masking every query parameter.
* Creates a QueryParametersRedaction keeping only the named parameters readable.
*
* @param string[] $fields The parameter names left untouched, wildcards accepted.
* @return QueryParametersRedaction The created instance.
*/
public static function default(): QueryParametersRedaction
public static function keeping(array $fields): QueryParametersRedaction
{
return QueryParametersRedaction::keeping(fields: []);
return new QueryParametersRedaction(fields: $fields);
}

public function redact(array $payload): array
Expand Down
4 changes: 2 additions & 2 deletions src/Redactions/SecretRedaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
final readonly class SecretRedaction implements Redaction
{
private const int DEFAULT_FIXED_MASK_LENGTH = 8;

private const array DEFAULT_FIELDS = [
'*token*',
'*secret*',
Expand All @@ -25,6 +23,8 @@
'*private_key*'
];

private const int DEFAULT_FIXED_MASK_LENGTH = 8;

private Redaction $redactor;

private function __construct(array $fields, int $fixedMaskLength)
Expand Down
12 changes: 6 additions & 6 deletions tests/Models/EmbeddedMetricPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public function metrics(): mixed
return $this->declaration()['Metrics'];
}

public function timestamp(): mixed
private function envelope(): array
{
return $this->envelope()['Timestamp'];
return (array)$this->payload['_aws'];
}

public function namespaced(): mixed
public function timestamp(): mixed
{
return $this->declaration()['Namespace'];
return $this->envelope()['Timestamp'];
}

public function dimensions(): mixed
{
return $this->declaration()['Dimensions'];
}

private function envelope(): array
public function namespaced(): mixed
{
return (array)$this->payload['_aws'];
return $this->declaration()['Namespace'];
}

private function declaration(): array
Expand Down
Loading