Skip to content

#204 - Fix CachedTransformer, SlugifyTransformer and TypeSetterTransformer edge cases - #215

Merged
njoubert-cleverage merged 4 commits into
mainfrom
204
Sep 28, 2026
Merged

njoubert-cleverage merged 4 commits into
mainfrom
204

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #204.

Three transformers handle edge cases badly:

  • cached rejects any non-string input with a TypeError, before key_transformers can convert it to a string, while the documentation says that a non-string key value just skips the cache.
  • slugify accepts an invalid transliterator identifier, then fails on the first value with Call to a member function transliterate() on null.
  • type_setter has a TransformerException branch for settype() returning false that can never run in PHP 8: invalid types are already rejected by setAllowedValues, and settype() never returns false for the allowed types.

This PR:

  • CachedTransformer::generateCacheKey() takes a mixed $value: a key value that is still not a string after key_transformers skips the cache, as documented.
  • The slugify transliterator normalizer throws an InvalidOptionsException (with the intl error message) when \Transliterator::create() returns null, so the error shows up when the options are resolved.
  • Remove the dead TransformerException branch from TypeSetterTransformer::transform().
  • Update the reference documentation, add unit tests.

The new regression tests fail on main and pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None for configurations. A subclass of CachedTransformer overriding generateCacheKey() with a string $value parameter must widen it to mixed.

🤖 Generated with Claude Code

…ypeSetterTransformer edge cases: accept a non-string input in `cached` (key built after `key_transformers`), reject an invalid `transliterator` in `slugify` with an `InvalidOptionsException`, remove the unreachable error branch of `type_setter`. Update documentation, add tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
njoubert-cleverage and others added 2 commits September 28, 2026 13:59
…ng risky tests when coverage is enabled

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…res PHP 8.4, the bundle supports PHP >= 8.2

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit 835fb6d into main Sep 28, 2026
17 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.

CachedTransformer and SlugifyTransformer fail with a raw PHP error on edge cases; TypeSetterTransformer has a dead error branch

1 participant