Add Size::dimensions() for destructuring (fixes #1480)#1485
Open
Abdooo2235 wants to merge 5 commits intoIntervention:developfrom
Open
Add Size::dimensions() for destructuring (fixes #1480)#1485Abdooo2235 wants to merge 5 commits intoIntervention:developfrom
Abdooo2235 wants to merge 5 commits intoIntervention:developfrom
Conversation
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.
Summary
Closes #1480.
Adds
Size::dimensions(): array{0: int, 1: int}so consumers can destructuresize into a
[width, height]int pair:Why not change
[$w, $h] = $image->size()directly?The literal syntax in the original issue would require changing
ArrayAccess::offsetGetonSize. That offset is currently the wayPolygon(Size's parent) exposes the four cornerPointobjects, andSize::setWidth()/setHeight()rely on it internally(
\$this[1]->setX(...), etc.). Repurposing those offsets to return intswould be a breaking change for every caller and for the class's own setters.
dimensions()is the non-breaking alternative: same ergonomics fordestructuring, zero risk for existing code.
Tests
Added to
tests/Unit/SizeTest.php:testDimensionsReturnsWidthAndHeightAsIntstestDimensionsEnablesArrayDestructuringtestDimensionsReflectsSetWidthAndSetHeighttestArrayAccessStillReturnsCornerPoints(explicit BC guard)vendor/bin/phpunit tests/Unit/SizeTest.phppasses locally (67 tests, 152 assertions).Notes
SizeInterfaceupdated to include the new method.PolygonorArrayAccesssemantics.