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.
Greptile Overview
Greptile Summary
This PR represents a major v1.0.0 refactor that consolidates the bitmask API into a single, immutable class with improved enum support.
Key Changes:
BaseBitmask,TinyBitmask,SmallBitmask, andMediumBitmaskinto a single immutableBitmaskclassmake(),tiny(),small(),medium()) for different bit sizesBackedEnumandUnitEnumsupport in all methods via the newmaskValue()helperMaxValueenum withSizeenum that computesmaxValue()dynamicallyfinalandreadonlyfor immutability guaranteesset,unset,toggle) now return new instances instead of mutating statePowerOfTwovalue object in favor ofisPowerOfTwo()helper functionArchitecture Improvements:
->valueextractionConfidence Score: 4/5
unset()method doesn't validate the result after bitwise NOT operation, though tests suggest this works correctly in practice.src/Bitmask.phpunset method (line 66-71) - while tests pass, the bitwise NOT operation could theoretically produce unexpected results with PHP's signed integer handlingImportant Files Changed
File Analysis
maskValue()helper to convert UnitEnum and BackedEnum to integer valuesSequence Diagram
sequenceDiagram participant User participant Bitmask participant maskValue participant isPowerOfTwo participant Size User->>Bitmask: make(Flag::A, Size::UInt8) Bitmask->>maskValue: maskValue(Flag::A) alt BackedEnum maskValue-->>Bitmask: flag.value else UnitEnum maskValue-->>Bitmask: 1 << position else int maskValue-->>Bitmask: flag end Bitmask->>Size: size.maxValue() Size-->>Bitmask: (1 << bits) - 1 Bitmask->>Bitmask: Validate value <= maxValue Bitmask-->>User: Bitmask instance User->>Bitmask: set(Flag::B) Bitmask->>maskValue: maskValue(Flag::B) maskValue-->>Bitmask: flagValue Bitmask->>isPowerOfTwo: isPowerOfTwo(flagValue) isPowerOfTwo-->>Bitmask: true Bitmask->>Bitmask: newValue = value | flagValue Bitmask->>Bitmask: Validate newValue <= maxValue Bitmask->>Bitmask: new Bitmask(newValue, size) Bitmask-->>User: New immutable instance User->>Bitmask: has(Flag::B) Bitmask->>maskValue: maskValue(Flag::B) maskValue-->>Bitmask: flagValue Bitmask->>isPowerOfTwo: isPowerOfTwo(flagValue) isPowerOfTwo-->>Bitmask: true Bitmask->>Bitmask: (value & flagValue) === flagValue Bitmask-->>User: boolean result User->>Bitmask: unset(Flag::B) Bitmask->>maskValue: maskValue(Flag::B) maskValue-->>Bitmask: flagValue Bitmask->>isPowerOfTwo: isPowerOfTwo(flagValue) isPowerOfTwo-->>Bitmask: true Bitmask->>Bitmask: value & (~flagValue) Bitmask->>Bitmask: new Bitmask(result, size) Bitmask-->>User: New immutable instance