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:
2026-05-06 12:42:25 +02:00
parent 48f2a00564
commit 5980c36ae4
3 changed files with 18 additions and 14 deletions

View File

@@ -25,7 +25,7 @@ final class PiiScrubbingTest extends TestCase
$event = Event::createEvent();
$event->setRequest($request);
return (new SentryEventScrubber)->scrub($event, $hint);
return SentryEventScrubber::scrub($event, $hint);
}
public function test_password_in_request_body_is_scrubbed(): void
@@ -171,7 +171,7 @@ final class PiiScrubbingTest extends TestCase
$event = Event::createEvent();
$hint = EventHint::fromArray(['exception' => new NotFoundHttpException]);
$this->assertNull((new SentryEventScrubber)->scrub($event, $hint));
$this->assertNull(SentryEventScrubber::scrub($event, $hint));
}
public function test_http_exception_500_is_captured(): void
@@ -179,7 +179,7 @@ final class PiiScrubbingTest extends TestCase
$event = Event::createEvent();
$hint = EventHint::fromArray(['exception' => new HttpException(500, 'boom')]);
$this->assertNotNull((new SentryEventScrubber)->scrub($event, $hint));
$this->assertNotNull(SentryEventScrubber::scrub($event, $hint));
}
public function test_throwable_from_controller_is_captured(): void
@@ -187,7 +187,7 @@ final class PiiScrubbingTest extends TestCase
$event = Event::createEvent();
$hint = EventHint::fromArray(['exception' => new RuntimeException('programmer error')]);
$this->assertNotNull((new SentryEventScrubber)->scrub($event, $hint));
$this->assertNotNull(SentryEventScrubber::scrub($event, $hint));
}
public function test_form_values_replacement_blocks_attempts_to_smuggle_pii(): void