Skip to content

More precise types - #346

Open
xificurk wants to merge 4 commits into
nette:masterfrom
xificurk:typehints-improvements
Open

xificurk wants to merge 4 commits into
nette:masterfrom
xificurk:typehints-improvements

Conversation

@xificurk

@xificurk xificurk commented Nov 7, 2026

Copy link
Copy Markdown
Contributor
  • new feature - not really
  • BC break no

These changes only touch phpDoc. Static analysis tools (PHPStan, Psalm, IDEs) now see more exact types. Runtime behaviour does not change.

  • Non-empty strings: Strings::length() returns int<1, max> for a non-empty string and 0 for ''. Strings::lower(), firstLower(), upper(), firstUpper(), capitalize() and reverse() preserve the information about a non-empty string. Random::generate() always returns a non-empty string.
  • Non-negative numbers: Strings::indexOf(), Arrays::getKeyOffset() and searchKey() return ?int<0, max>. ArrayHash::count(), ArrayList::count() and CachingIterator::getCounter() return int<0, max>.
  • Arrays: grep() and wrap() keep the key type. flatten() returns a list unless $preserveKeys is true.
  • Validators: after isUnicode($value) returns true, $value is a string.

- Strings::length() returns int<1, max> for a non-empty string and 0 for ''
- Strings::lower(), firstLower(), upper(), firstUpper(), capitalize()
  and reverse() return a non-empty string for a non-empty string
- Random::generate() always returns a non-empty string, as it throws
  for a length below 1

Co-Authored-By: Claude Code
… counts are non-negative

- Strings::indexOf(), Arrays::getKeyOffset() and searchKey() return ?int<0, max>
- ArrayHash::count(), ArrayList::count() and CachingIterator::getCounter()
  (and its $counter property) return int<0, max>

Co-Authored-By: Claude Code
flatten() returns a list unless $preserveKeys is true.

Co-Authored-By: Claude Code
@xificurk
xificurk force-pushed the typehints-improvements branch from 2dd7739 to 0c1da84 Compare November 7, 2026 18:14
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.

1 participant