Skip to content

feat(masker): add withoutValuePatterns to drop default value patterns by name#5

Merged
rflavien merged 2 commits into
mainfrom
feat/masker-without-value-patterns
Jun 18, 2026
Merged

feat(masker): add withoutValuePatterns to drop default value patterns by name#5
rflavien merged 2 commits into
mainfrom
feat/masker-without-value-patterns

Conversation

@rflavien

Copy link
Copy Markdown
Contributor

Contexte

Le MaskerBuilder permet d'ajouter des patterns de valeur via withValuePatterns(), mais il n'existait aucun moyen d'en retirer un par défaut. Certains défauts (email, iban) sont source de faux positifs selon le contexte applicatif ; jusqu'ici, les désactiver imposait de remplacer tout le matcher via withValueMatcher(), perdant ainsi les autres défauts et la détection carte (Luhn).

Changement

Nouvelle méthode withoutValuePatterns(array $names), symétrique de withValuePatterns() :

MaskerBuilder::create()
    ->withoutValuePatterns(['email', 'iban']) // retire ces défauts, garde le reste + détection carte
    ->buildProcessor();
  • Exclusion par nom parmi les clés de DefaultValuePatterns (email, jwt, bearer, iban, api_secret_key, aws_access_key, google_api_key, pem_private_key).
  • Porte uniquement sur les défauts ; les patterns ajoutés via withValuePatterns() ne sont pas affectés.
  • Noms inconnus ignorés silencieusement (cohérent avec les autres méthodes additives).
  • CreditCardMatcher non concerné (pour le désactiver : withoutValueMatching() / withValueMatcher()).

Tests

5 nouveaux cas dans MaskerBuilderTest : exclusion ciblée vs autres défauts/carte actifs, plusieurs noms en un appel, coexistence avec patterns ajoutés, accumulation multi-appels, nom inconnu ignoré.

make validate passe intégralement : php-cs-fixer, PHPStan, coverage 100%, Infection MSI 100% / Covered MSI 100%, PBT (proofs).

🤖 Generated with Claude Code

… by name

Symmetric to withValuePatterns: lets callers exclude default value
patterns by name (e.g. email, iban) while keeping the other defaults
and Luhn card detection. Previously this required replacing the whole
value matcher via withValueMatcher, losing every other default.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new MaskerBuilder::withoutValuePatterns() API to selectively disable specific default value-detection patterns (by name) without replacing the entire value matcher, preserving other defaults and credit-card (Luhn) detection.

Changes:

  • Introduce withoutValuePatterns(array $names) on MaskerBuilder, storing excluded default pattern names and removing them from DefaultValuePatterns during default matcher construction.
  • Add PHPUnit coverage for default-pattern exclusion behavior (context masking) across multiple scenarios.
  • Document the new builder option in the README configuration section.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/MaskerBuilder.php Adds withoutValuePatterns() and applies exclusions when building the default value matcher.
tests/MaskerBuilderTest.php Adds new tests covering exclusion of default value patterns (context masking scenarios).
README.md Documents the new withoutValuePatterns(['email', 'iban']) builder option.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/MaskerBuilderTest.php
The default value matcher also masks the log message via MaskingProcessor,
so assert the exclusion flows through that path: an excluded email is left
intact in the message while card detection still redacts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rflavien
rflavien merged commit 04a724c into main Jun 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants