Skip to content

Transformers: a common policy for null, array and object inputs #405

Open

Description

@njoubert-cleverage

The transformers have no common policy for the inputs they do not expect: null, an array, an object. Some return null for null (trim, convert_value), others the input itself (date_parser with a falsy value), others an empty string (multi_replace, hash of null), others throw: an explicit UnexpectedValueException (hash, slugify and date_parser since #398, #400 and #402, convert_value without auto_cast) or a raw TypeError / Error from a PHP function with strict types.

Define one policy for v6.0, for instance:

  • null gives null for every transformer that does not handle it explicitly (ignore_missing-like behaviour), or always throws;
  • a scalar or a \Stringable is cast to string by the string transformers;
  • an array or another object throws an UnexpectedValueException naming the transformer and the type, never a raw TypeError;

then apply it to every transformer, document it in each reference page (Accepted inputs) and in UPGRADE.md, and test it (a shared data provider over the transformers).

Found during the audit v3 (audit-v3-angles.md #202).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions