#204 - Fix CachedTransformer, SlugifyTransformer and TypeSetterTransformer edge cases - #215
Merged
Merged
Conversation
…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>
3 tasks
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #204.
Three transformers handle edge cases badly:
cachedrejects any non-string input with aTypeError, beforekey_transformerscan convert it to a string, while the documentation says that a non-string key value just skips the cache.slugifyaccepts an invalidtransliteratoridentifier, then fails on the first value withCall to a member function transliterate() on null.type_setterhas aTransformerExceptionbranch forsettype()returningfalsethat can never run in PHP 8: invalid types are already rejected bysetAllowedValues, andsettype()never returnsfalsefor the allowed types.This PR:
CachedTransformer::generateCacheKey()takes amixed $value: a key value that is still not a string afterkey_transformersskips the cache, as documented.slugifytransliteratornormalizer throws anInvalidOptionsException(with the intl error message) when\Transliterator::create()returnsnull, so the error shows up when the options are resolved.TransformerExceptionbranch fromTypeSetterTransformer::transform().The new regression tests fail on
mainand pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.Requirements
Breaking changes
None for configurations. A subclass of
CachedTransformeroverridinggenerateCacheKey()with astring $valueparameter must widen it tomixed.🤖 Generated with Claude Code