Skip to content

Conversation

@Edvarde
Copy link
Contributor

@Edvarde Edvarde commented Jul 24, 2025

Replace null defaults with MissingValue to make behavior more explicit and IDE-friendly

Problem

When using helper methods like:

->when($condition, $value, null)

many IDEs (e.g., PhpStorm) suggest that the third argument is redundant because it matches the default (null).
If a developer removes it (trusting the IDE), the behavior changes silently:

  • ->when(..., null) → the field is included in the response with value null
  • ->when(...) → the field is skipped entirely (because MissingValue is used internally)

This leads to non-obvious bugs, especially when the difference between null and "not passed at all" is significant.

Solution

This PR changes the default value from null to new MissingValue in affected helper methods.

Why this matters

  • Makes the distinction between null and "not provided" explicit
  • Prevents IDEs from suggesting misleading simplifications
  • Improves developer experience and reduces potential bugs
  • Encourages conscious handling of optional parameters

After this change, the difference is clearly reflected in the method signature. IDEs will no longer suggest removing null without warning.

@Edvarde Edvarde closed this Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants