Skip to content

Make Flow Types fully compatible with Static Analysis Tools #1628

@norberttech

Description

@norberttech

Flow comes with it's own internal type system:

  • type_float()
  • type_string()
  • etc

The challange is that due to nullability being defined on a type level tools like phpstan can't properly narrow the type in methods like isValid(mixed $value) : bool
like it does for tools like webmozart/assert for example.

The goal is to also introduce Type::assert(mixed $value) : mixed so when we use it like this:

$floatValue = type_float()->assert($value); 
// $floatValue type is float, not float|null

the $floatValue is recognized as a proper float

Additionally we also want to get the same behavior for

$floatValue = caster()->to(type_float()->value($value);
// $floatValue type is float, not float|null

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions