Skip to content

Add Size::dimensions() for destructuring (fixes #1480)#1485

Open
Abdooo2235 wants to merge 5 commits intoIntervention:developfrom
Abdooo2235:fix/1480-size-dimensions
Open

Add Size::dimensions() for destructuring (fixes #1480)#1485
Abdooo2235 wants to merge 5 commits intoIntervention:developfrom
Abdooo2235:fix/1480-size-dimensions

Conversation

@Abdooo2235
Copy link
Copy Markdown

Summary

Closes #1480.

Adds Size::dimensions(): array{0: int, 1: int} so consumers can destructure
size into a [width, height] int pair:

[$width, $height] = $image->size()->dimensions();

Why not change [$w, $h] = $image->size() directly?

The literal syntax in the original issue would require changing
ArrayAccess::offsetGet on Size. That offset is currently the way
Polygon (Size's parent) exposes the four corner Point objects, and
Size::setWidth()/setHeight() rely on it internally
(\$this[1]->setX(...), etc.). Repurposing those offsets to return ints
would be a breaking change for every caller and for the class's own setters.

dimensions() is the non-breaking alternative: same ergonomics for
destructuring, zero risk for existing code.

Tests

Added to tests/Unit/SizeTest.php:

  • testDimensionsReturnsWidthAndHeightAsInts
  • testDimensionsEnablesArrayDestructuring
  • testDimensionsReflectsSetWidthAndSetHeight
  • testArrayAccessStillReturnsCornerPoints (explicit BC guard)

vendor/bin/phpunit tests/Unit/SizeTest.php passes locally (67 tests, 152 assertions).

Notes

  • SizeInterface updated to include the new method.
  • No changes to Polygon or ArrayAccess semantics.

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.

Enable array destructuring of Size::class with width & height

1 participant