Merged
Conversation
1409258 to
f148a0b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new fit() helper function for type-based dispatch, wires it into the library, and adds unit tests and stubs to validate its behavior, while also tweaking type-related utilities and tooling configuration.
Changes:
- Added
empaphy\usephul\fit()with support for unions, intersections,mixed, and a fallback case, plus anUnhandledFitExceptionfor unhandled subjects. - Introduced PHPUnit-based unit tests and stub classes/interfaces to verify
fit()behavior, including success, failure, and error conditions across types and PHP versions. - Adjusted the
Var\Typeenum to reuse ZEND string constants, simplified attribute inspection logic inType\functions.php, and updated Composer autoload and tooling scripts.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
tests/Unit/fitTest.php |
Adds PHPUnit tests covering matching, non-matching, missing types, missing callbacks, and PHP 8.2-specific behavior to validate the new fit() function. |
tests/Unit/Stubs/FooInterface.php |
Defines a FooInterface stub used to test interface-based matching in fit(). |
tests/Unit/Stubs/FooBar.php |
Adds FooBar implementing both FooInterface and BarInterface to exercise intersection type handling in fit(). |
tests/Unit/Stubs/Foo.php |
Introduces a Foo stub implementing FooInterface for object type tests. |
tests/Unit/Stubs/BarInterface.php |
Adds a BarInterface stub used with FooBar to test intersection behavior. |
tests/Unit/Stubs/Bar.php |
Adds a Bar stub implementing BarInterface for additional object matching cases. |
tests/Unit/Stubs/AbstractFoo.php |
Provides an abstract FooInterface implementation stub for potential extended type scenarios in tests. |
src/functions.php |
Implements fit() with reflection-based analysis of parameter types (including unions/intersections), error reporting for invalid callbacks, and throwing UnhandledFitException when no callback fits. |
src/Var/Type.php |
Changes Type::UNKNOWN to use ZEND_STR_UNKNOWN and imports that constant, aligning enum values with the ZEND string constants. |
src/UnhandledFitException.php |
Introduces a domain-specific exception that carries the unhandled subject and callbacks and formats a diagnostic message based on the subject. |
src/Type/functions.php |
Simplifies the applies() helper by inlining the reflection logic and directly returning the attribute presence check. |
composer.json |
Registers src/functions.php for autoloading, adds autoload-dev PSR-4 mappings for test namespaces, and increases PHPStan’s memory limit in the stan script. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8f32272 to
3fd0d7c
Compare
3fd0d7c to
8c163b1
Compare
|
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.
No description provided.