refactor: SentryEventScrubber static + config array notation
The scrubber is fully stateless. Container-resolution per event was overhead without value, the closure indirection polluted the config layer with executable logic, and stack traces showed an anonymous closure frame instead of the class name. - SentryEventScrubber::scrub() and its private helpers all become static methods. No instance fields, so the change is mechanical. - config/sentry.php before_send switches from a closure that calls app() to PHP array-callable notation [Class, method]. Symfony OptionsResolver accepts array-callables for static methods. - PiiScrubbingTest swaps (new SentryEventScrubber)->scrub(...) for SentryEventScrubber::scrub(...). Semantics unchanged. Tests 1537 unchanged. Larastan and Pint clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -44,7 +44,7 @@ final class SentryEventScrubber
|
||||
|
||||
private const MAX_DEPTH = 10;
|
||||
|
||||
public function scrub(Event $event, ?EventHint $hint = null): ?Event
|
||||
public static function scrub(Event $event, ?EventHint $hint = null): ?Event
|
||||
{
|
||||
if ($hint?->exception instanceof HttpException && $hint->exception->getStatusCode() < 500) {
|
||||
return null;
|
||||
@@ -54,9 +54,9 @@ final class SentryEventScrubber
|
||||
|
||||
if ($request !== []) {
|
||||
$event->setRequest(array_merge($request, [
|
||||
'data' => $this->scrubBody($request['data'] ?? []),
|
||||
'headers' => $this->scrubHeaders($request['headers'] ?? []),
|
||||
'query_string' => $this->scrubQueryString($request['query_string'] ?? ''),
|
||||
'data' => self::scrubBody($request['data'] ?? []),
|
||||
'headers' => self::scrubHeaders($request['headers'] ?? []),
|
||||
'query_string' => self::scrubQueryString($request['query_string'] ?? ''),
|
||||
'cookies' => self::SCRUBBED,
|
||||
]));
|
||||
}
|
||||
@@ -68,7 +68,7 @@ final class SentryEventScrubber
|
||||
* @param mixed $data
|
||||
* @return mixed
|
||||
*/
|
||||
private function scrubBody($data, int $depth = 0)
|
||||
private static function scrubBody($data, int $depth = 0)
|
||||
{
|
||||
if (! is_array($data)) {
|
||||
return $data;
|
||||
@@ -92,7 +92,7 @@ final class SentryEventScrubber
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$data[$key] = $this->scrubBody($value, $depth + 1);
|
||||
$data[$key] = self::scrubBody($value, $depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ final class SentryEventScrubber
|
||||
* @param array<string, mixed>|string $headers
|
||||
* @return array<string, mixed>|string
|
||||
*/
|
||||
private function scrubHeaders($headers)
|
||||
private static function scrubHeaders($headers)
|
||||
{
|
||||
if (! is_array($headers)) {
|
||||
return $headers;
|
||||
@@ -118,7 +118,7 @@ final class SentryEventScrubber
|
||||
return $headers;
|
||||
}
|
||||
|
||||
private function scrubQueryString(string $queryString): string
|
||||
private static function scrubQueryString(string $queryString): string
|
||||
{
|
||||
if ($queryString === '') {
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user