Skip to content

Handle null values using a Juicer #11

@rgazelot

Description

@rgazelot

Hi there, it's me again!

I found a weird case to handle : I wanted to use a Juicer on a field and when I wrote tests I tried with a null value and found that it throws a php exception about the clean process.

$validator
  ->addField('foo', true)
    ->addJuicer('foo', (new \Chanmix51\ParameterJuicer\ParameterJuicer)
        ->addField('bar', true)
          ->addValidator('bar', function($v) {
            if ("baz" !== $v) {
              throw new \Chanmix51\ParameterJuicer\ValidationException('error.');
            }
          })
    )
;

$data = [
  'foo' => null,
];

$data = $validator->squash($data);

// PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Chanmix51\ParameterJuicer\ParameterJuicer::clean() must be of the type array, null given in /vendor/chanmix51/parameter-juicer/sources/lib/ParameterJuicer.php:348

I think that this case should be handle, what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions