assert icon indicating copy to clipboard operation
assert copied to clipboard

`null` type hint on `nullOr` assertions

Open marcosh opened this issue 6 years ago • 1 comments

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

marcosh avatar Mar 12 '19 08:03 marcosh

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';
 }

rquadling avatar Mar 25 '19 09:03 rquadling