Repository navigation
Declare ArrayHash offset methods in the stub - #227
Merged
Merged
Conversation
Composer\InstalledVersions also sees the nette/utils bundled in the PHPStan phar and reported 3.2.10 even with nette/utils 4.1.5 installed, so the iterator assertions never ran. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Without offsetGet(), offset access on ArrayHash<T> was T|null from ArrayAccess instead of T as declared by nette/utils. The PHPDocs mirror nette/utils 4.1, except for the $key parameter of offsetSet(): array-key is not contravariant with ArrayAccess, which accepts null. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
ArrayHashstub from 2.0.14 doesn't declareoffsetGet(), so offset access onArrayHash<T>falls back toArrayAccessand isT|null. nette/utils 4.x declares@return T. Before 2.0.14, the class wasn't generic, so it wasn't a problem.The stub now declares the offset methods with the PHPDocs of nette/utils 4.1, so the types match nette/utils' own PHPDoc. The exception is the
$keyparameter ofoffsetSet().@param array-key $keybreaks contravariance withArrayAccess::offsetSet(), which acceptsnull. PHPStan reports that in stub files as a non-ignorablemethod.childParameterTypeerror. SooffsetSet()keeps accepting anullkey, as in 2.0.14.$hash['foo'],$hash->offsetGet('foo')onArrayHash<int>int|nullint$hash['foo'] = 'string'onArrayHash<int>$hash->offsetGet(1.5)from()andcount()stay out of the stub. Their types are the same either way, and declaring them would drop@return staticoffrom()on nette/utils 3.x.ArrayHashStubTestalso never ran the iterator assertions.Composer\InstalledVersionsreported the nette/utils bundled in the PHPStan phar (3.2.10), not the installed 4.1.5. The test now checks the native return type ofgetIterator().I checked it with nette/utils 4.1.5 and 3.1.4 (
--prefer-lowest).🤖 Generated with Claude Code