Skip to content

feat: new fit() function#21

Merged
AlwinGarside merged 1 commit intomainfrom
feature/fit
Feb 7, 2026
Merged

feat: new fit() function#21
AlwinGarside merged 1 commit intomainfrom
feature/fit

Conversation

@AlwinGarside
Copy link
Contributor

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 an UnhandledFitException for 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\Type enum to reuse ZEND string constants, simplified attribute inspection logic in Type\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.

@AlwinGarside AlwinGarside force-pushed the feature/fit branch 3 times, most recently from 8f32272 to 3fd0d7c Compare February 7, 2026 19:59
@empaphy empaphy deleted a comment from Copilot AI Feb 7, 2026
@empaphy empaphy deleted a comment from Copilot AI Feb 7, 2026
@empaphy empaphy deleted a comment from Copilot AI Feb 7, 2026
@empaphy empaphy deleted a comment from Copilot AI Feb 7, 2026
@empaphy empaphy deleted a comment from Copilot AI Feb 7, 2026
@empaphy empaphy deleted a comment from Copilot AI Feb 7, 2026
@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Code Coverage

Package Line Rate Branch Rate Complexity Health
array.php 100% 100% 41
debug.php 100% 100% 5
Enumerations/EnumDynamicity.php 100% 100% 4
Fallback.php 100% 100% NaN
functions.php 100% 100% 19
generators.php 100% 100% 14
Math/functions.php 100% 100% 21
other.php 100% 100% 12
Path/functions.php 100% 100% 42
Path/PathInfo.php 100% 100% 1
pcre.php 100% 100% 5
Sorting/Direction.php 100% 100% NaN
Sorting/Type.php 100% 100% NaN
Type/functions.php 100% 100% 7
UnhandledFitException.php 100% 100% 3
Var/functions.php 100% 100% 20
Var/Type.php 100% 100% 3
Summary 100% (422 / 422) 100% (0 / 0) NaN

@AlwinGarside AlwinGarside merged commit ef8e9c1 into main Feb 7, 2026
10 checks passed
@AlwinGarside AlwinGarside deleted the feature/fit branch February 7, 2026 20:08
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.

2 participants