Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null type hint on nullOr assertions #277

Open
marcosh opened this issue Mar 12, 2019 · 1 comment
Open

null type hint on nullOr assertions #277

marcosh opened this issue Mar 12, 2019 · 1 comment

Comments

@marcosh
Copy link

marcosh commented Mar 12, 2019

At the moment the nullOr assertions are not considering the null input value. For example the nullOrIp assertion type hints on string. Shouldn't it be more correct to add also the null type hint?

It's not possible to use ?string since the library targets php 7.0, but it should be ok to use string|null or just use string $value = null

@rquadling
Copy link
Contributor

rquadling commented Mar 25, 2019

Nullable typehints are PHP 7.1, so until I get to move the base PHP version, we will stick with the way it is.

As for the nullOr assertions, these are handled by __callStatic and so the docblock SHOULD have |null against them.

I'll look into updating the docblocks this week.

Below if my first quick look at the patch for the documentation generator.

if ($prefix === 'nullOr' && strpos($type, 'null') === false && $parameterIndex === 0) {
  $type .= '|null';
 }

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

No branches or pull requests

2 participants