Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes small internal cleanups to the sanitization flow and updates package metadata to better reflect current functionality.
Changes:
- Avoid repeated
getSessionId()calls during sanitization. - Tighten the
addSanitization()contract vianon-empty-stringPHPDoc annotations. - Update
composer.jsondescription to include sanitization and CSS extraction behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/SensitiveValueSanitizer.php |
Refactors session-id sanitization path; adds PHPDoc contract to addSanitization(). |
src/PhpInfo.php |
Mirrors the addSanitization() PHPDoc contract at the facade level. |
composer.json |
Expands the library description to reflect sanitization and CSS handling. |
Comments suppressed due to low confidence (1)
src/SensitiveValueSanitizer.php:71
- The new
@param non-empty-string $sanitizedocblock isn’t enforced at runtime. As written, callers can still pass an empty string, which will add''as a replacement key and can trigger warnings instrtr()(and creates a duplicate key withurlencode('')). Consider explicitly rejecting/ignoring empty$sanitizeinaddSanitization()so the sanitizer can’t be put into an invalid state by external input.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitize[$sanitize] = $this->sanitize[urlencode($sanitize)] = $with ?? $this->sanitizeWith;
return $this;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
src/SensitiveValueSanitizer.php:74
- The new PHPDoc says
$sanitizeis anon-empty-string, but the method still accepts''at runtime and will store it into$this->sanitize, which can later triggerstrtr()warnings. Either enforce the contract (e.g., ignore/throw on empty) or adjust the annotation so it matches actual behavior.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitize[$sanitize] = $this->sanitize[urlencode($sanitize)] = $with ?? $this->sanitizeWith;
return $this;
src/PhpInfo.php:75
- This wrapper now documents
$sanitizeasnon-empty-string, but it doesn't enforce it and will forward an empty string to the sanitizer. To keep the public API contract accurate and avoidstrtr()warnings, consider validating here too or documenting/propagating whatever behaviorSensitiveValueSanitizer::addSanitization()uses for empty input.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitizer->addSanitization($sanitize, $with);
return $this;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/SensitiveValueSanitizer.php:73
- The new
@param non-empty-string $sanitizecontract isn’t enforced at runtime. If a caller passes''toaddSanitization(), it will still be added to the replacement map andsanitize()will callstrtr()with an empty search string, which triggers a PHP warning (the same class of issue this PR is addressing for session IDs). Consider validating$sanitize !== ''and either throwing anInvalidArgumentExceptionor skipping the entry.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitize[$sanitize] = $this->sanitize[urlencode($sanitize)] = $with ?? $this->sanitizeWith;
return $this;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
src/SensitiveValueSanitizer.php:73
addSanitization()is now documented as accepting anon-empty-string, but the method still allows''at runtime. If a caller passes an empty string, it will still be inserted into the replacement map and can triggerstrtr()warnings (the regression this PR is addressing). Consider enforcing non-empty at runtime (e.g., throw anInvalidArgumentExceptionor ignore empty input) so the public API matches the docblock and warnings are prevented reliably.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitize[$sanitize] = $this->sanitize[urlencode($sanitize)] = $with ?? $this->sanitizeWith;
return $this;
src/PhpInfo.php:75
PhpInfo::addSanitization()is documented as taking anon-empty-string, but it doesn’t enforce that before delegating to the sanitizer. Passing''is still possible for external callers and can reintroducestrtr()warnings. Consider validating here (or inSensitiveValueSanitizer::addSanitization()) to make the public API robust against empty inputs.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitizer->addSanitization($sanitize, $with);
return $this;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/SensitiveValueSanitizer.php:73
addSanitization()is now documented as accepting anon-empty-string, but the method still accepts anystringat runtime. If a caller passes'', it will still add an empty search string into thestrtr()map, reintroducing the same warning this PR is addressing. Consider enforcing this contract (throw anInvalidArgumentExceptionor ignore empty input) to make the API safe even without static analysis.
/**
* @param non-empty-string $sanitize
*/
public function addSanitization(string $sanitize, ?string $with = null): self
{
$this->sanitize[$sanitize] = $this->sanitize[urlencode($sanitize)] = $with ?? $this->sanitizeWith;
return $this;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Annotating with PHPStan is fine, but requires some work to be done by the caller to not pass empty strings. This is more friendly. Partially reverts some work done in #28
Annotating with PHPStan is fine, but requires some work to be done by the caller to not pass empty strings. This is more friendly. Partially reverts some work done in #28
Annotating with PHPStan is fine, but requires some work to be done by the caller to not pass empty strings. This is more friendly. Partially reverts some work done in #28
getSessionId()just oncestrtr(), otherwise it throws a warning (reworked in Check empty sanitization string run-time #30)composer.json