Binary Flags v3#16
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prepares BinaryFlags for the v3.0.0 breaking release by moving the numeric API toward integer-only masks/flags, removing Bits::BIT_64, updating docs/migration guidance, and refreshing dev tooling and tests to reflect the new contract.
Changes:
- Tighten numeric mask/flag APIs toward
int-only usage (and remove the prior float deprecation/normalization path). - Remove
Bits::BIT_64and add/adjust tests + migration docs accordingly. - Add
declare(strict_types=1);broadly and upgrade dev dependencies (PHPStan/Pest/Rector), plus PHPStan config tweaks.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| UPGRADE-v3.md | Updates v3 migration guidance and describes runtime impact of float inputs. |
| RELEASE_NOTES.md | Refreshes release notes to v3.0.0 scope (int-only + BIT_64 removal). |
| README.md | Updates breaking-change notice and BIT_64 guidance for v3. |
| composer.json | Bumps dev tooling versions (PHPStan/Pest/Rector). |
| phpstan.neon.dist | Adds ignore rule for deprecated alias trait not being analyzed. |
| src/Traits/InteractsWithNumericFlags.php | Removes float normalization/deprecation logic and tightens signatures to int. |
| src/BinaryFlags.php | Updates constructor and iterator/phpdoc contracts to int. |
| src/Bits.php | Removes Bits::BIT_64 constant and adds strict types. |
| src/Mask.php | Adds strict types declaration. |
| src/Flag.php | Adds strict types declaration. |
| src/BinaryEnumFlags.php | Adds strict types declaration. |
| src/Traits/InteractsWithEnumFlags.php | Adds strict types declaration. |
| src/Traits/BinaryFlags.php | Adds strict types declaration to deprecated alias trait. |
| tests/NumericTypeValidationTest.php | Adds new tests asserting floats are rejected and BIT_64 is undefined. |
| tests/NumericDeprecationTest.php | Removes v2.x float deprecation-warning behavior test. |
| tests/PermissionEnumTest.php | Renames/adjusts enum test wording around deprecation/float validation behavior. |
| tests/TestCase.php | Adds strict types declaration. |
| tests/Pest.php | Adds strict types declaration. |
| tests/NumericBitsTest.php | Adds strict types declaration. |
| tests/NumericBitsNamesTest.php | Adds strict types declaration. |
| tests/MaskTest.php | Adds strict types declaration. |
| tests/LegacyTraitCompatibilityTest.php | Adds strict types declaration. |
| tests/FlagWithNamesTest.php | Adds strict types declaration. |
| tests/FlagEnumTest.php | Adds strict types declaration. |
| tests/EnumErrorPathsTest.php | Adds strict types declaration. |
| tests/Stubs/Permission.php | Adds strict types declaration. |
| tests/Stubs/LegacyTraitFlags.php | Adds strict types declaration. |
| tests/Stubs/InvalidPermission.php | Adds strict types declaration. |
| tests/Stubs/ExamplePermissionFlags.php | Adds strict types declaration. |
| tests/Stubs/ExampleInvalidPermissionFlags.php | Adds strict types declaration. |
| tests/Stubs/ExampleFlagsWithNames.php | Adds strict types declaration. |
| tests/Stubs/ExampleFlags.php | Adds strict types declaration. |
| tests/Stubs/ExampleEnumFlags.php | Adds strict types declaration. |
| tests/Stubs/BadStringFlag.php | Adds strict types declaration. |
Comments suppressed due to low confidence (1)
src/Traits/InteractsWithNumericFlags.php:65
getAllFlagsMask()'sarray_reduce()callback is untyped, so static analysis (and PHPStan max) may infermixedfor$carry/$flagand the return value even though the method promisesint. This is especially relevant after tightening the return type toint.
Type-hint the closure parameters/return to keep the contract explicit and avoid PHPStan errors.
return array_reduce(
array_keys(static::getAllFlags()),
function ($carry, $flag) {
return $carry | $flag;
},
0,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
This pull request introduces the breaking changes for version 3.0.0 of the
BinaryFlagspackage, enforcing integer-only masks and flags, removing legacy float support, and eliminating the deprecatedBits::BIT_64. It also updates documentation and code contracts to reflect these changes, and upgrades development dependencies for better compatibility and analysis.Integer-only API and removal of float support
int; passing afloatwill throw aTypeErrorinstead of being normalized or issuing a deprecation warning. The float normalization/deprecation logic has been removed fromTraits\InteractsWithNumericFlags, and all relevant method signatures and docblocks have been updated. (src/Traits/InteractsWithNumericFlags.php[1] [2] [3] [4] [5] [6] [7] [8];src/BinaryFlags.php[9] [10] [11] [12]Removal of
Bits::BIT_64Bits::BIT_64constant has been removed, as the 64th bit is the sign bit in PHP and cannot be reliably used for flags. All documentation and migration notes have been updated accordingly. (src/Bits.php[1];README.md[2] [3];RELEASE_NOTES.md[4];UPGRADE-v3.md[5]Documentation and migration guidance
README.md,RELEASE_NOTES.md, andUPGRADE-v3.mdhave been updated to clarify the integer-only API, explain the removal of float support andBIT_64, and provide migration instructions for users upgrading from earlier versions. (README.md[1] [2];RELEASE_NOTES.md[3];UPGRADE-v3.md[4] [5]Development tooling updates
phpstan/phpstan,pestphp/pest, andrector/rectorfor improved analysis and testing. Added a new ignore rule for unused trait analysis inphpstan.neon.dist. (composer.json[1];phpstan.neon.dist[2]