Fix: Remove nullable type hints from callable parameters in Result class#43
Merged
prewk merged 3 commits intoprewk:masterfrom Aug 19, 2025
Merged
Conversation
The callable parameters in Result methods were incorrectly marked as nullable (T=) when they should be required (T). This was causing PHPStan v1 to report errors about parameter mismatches. Since these callables are only invoked when there's an actual value present (Ok for map/andThen, Err for mapErr/orElse), the parameters should not be nullable. Fixes prewk#42
ff4f03b to
94b6b6c
Compare
|
Looks good, I would suggest though to make some of the methods more flexible: /**
* Calls op if the result is Ok, otherwise returns the Err value of self.
*
* @template U
* @template F
*
* @param callable(T):Result<U,F> $op
* @return Result<U,E|F>
*/
public function andThen(callable $op): self;
/**
* Calls op if the result is Err, otherwise returns the Ok value of self.
*
* @template U
* @template F
*
* @param callable(E):Result<U,F> $op
* @return Result<T|U,F>
*/
public function orElse(callable $op): self;
/**
* Unwraps a result, yielding the content of an Ok. Else, it returns optb.
*
* @template U
*
* @param U $optb
* @return T|U
*/
public function unwrapOr($optb): mixed;
/**
* Unwraps a result, yielding the content of an Ok. If the value is an Err then it calls op with its value.
*
* @template U
*
* @param callable(E):U $op
* @return T|U
*/
public function unwrapOrElse(callable $op): mixed; |
Updated Result class method signatures as suggested by @tminich: - andThen(): Added template F, changed callable to Result<U,F> and return to Result<U,E|F> - orElse(): Added template U, changed callable to Result<U,F> and return to Result<T|U,F> - unwrapOr(): Added template U, changed return type to T|U - unwrapOrElse(): Added template U, changed return type to T|U These changes provide more flexible and accurate type annotations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
@tminich done |
Updated actions/cache from v4.0.2 to v4 to resolve CI failures. The specific version was causing automatic failures due to deprecation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Owner
|
Wow, you fixed the CI ✨ |
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.
Description
This PR fixes the issue described in #42 regarding PHPStan v1 errors with nullable callable parameters.
Problem
The callable parameters in Result methods were incorrectly marked as nullable (
T=) when they should be required (T). This was causing PHPStan v1 to report errors about parameter mismatches.Solution
Removed the
=from all callable parameter type hints in the Result abstract class. Since these callables are only invoked when there's an actual value present (Ok for map/andThen, Err for mapErr/orElse), the parameters should not be nullable.Changes
callable(T=)tocallable(T)callable(E=)tocallable(E)Testing
Fixes #42