Repository navigation
[v6] #405 - Transformers: a common policy for null, array and object inputs - #525
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <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 #405: one policy for the inputs the transformers do not expect, instead of a different behaviour by transformer (
null, the input,'', anUnexpectedValueException, a rawTypeError/Error, or"Array"with a warning, silent when the PHP warnings are not thrown).convert_valuewithauto_cast,date_parser,explode,hash,multi_replace,preg_filter,preg_match,slugify,trim):nullgivesnull, a scalar or a\Stringableis cast to a string, an array or another object (a\BackedEnumincluded) throwsUnexpectedValueException: The <code> transformer expects a string, <type> given.array_element,array_last,array_unset,implode,instantiate,unset): anything but an array,nullincluded, throwsUnexpectedValueException: The <code> transformer expects an array, <type> given.(array_elementandarray_lastthrew aTypeError).sprintfandimplodereject an argument or an item that is an array or an object.callback,cast,default,mapping,rules, the arguments ofsprintf, a date fordate_format...).''stays an ordinary string: the documented behaviours for empty values (date_parserreturning a falsy value,explode('')→[],preg_match('')→null) are unchanged.@internalhelper (InputPolicy). A shared data provider over the registry (TransformerInputPolicyTest) checks the policy for every transformer, and fails when a transformer is added without a row.UPGRADE.md.Checked locally:
make quality, and PHPUnit with pcov (1428 tests, none risky).Requirements
Breaking changes
nullgivesnullwithhash(the hash of''before),slugify(anUnexpectedValueExceptionbefore),explode([]before) andmulti_replace(''before). Add adefaulttransformer where an empty string or an empty array is expected (seeUPGRADE.md).UnexpectedValueExceptionin the string transformers,sprintfandimplode("Array"with a warning, or anError, before); anything but an array throws one inarray_element/array_last(TypeErrorbefore) anddate_parserrejects an empty array.🤖 Generated with Claude Code