Skip to content

Add native types for PHP 8.3 - #1549

Merged
olivervogel merged 1 commit into
Intervention:developfrom
silarhi:feat/typehint-codebase-8-3-58ac61
Oct 5, 2026
Merged

olivervogel merged 1 commit into
Intervention:developfrom
silarhi:feat/typehint-codebase-8-3-58ac61

Conversation

@guillaume-sainthillier

Copy link
Copy Markdown
Contributor

Now that develop requires PHP ^8.3, the remaining untyped class constants in DominantPaletteAnalyzer and Colors\Themes\VibrantMuted\Definition are typed (private const float MIN_VIBRANT_SATURATION = 0.35), matching the rest of the codebase which already used typed constants.

Closures and arrow functions in src and tests that were missing parameter or return types now have them (e.g. drawRectangle(function (RectangleFactory $rectangle): void { ... })).

A few things worth noting:

  • Collection::filter() and Palette::filter() wrappers return mixed, not bool: with strict_types=1 a bool return would throw a TypeError for user callbacks returning a truthy non-bool value, which array_filter() accepts today.
  • The closures in the Colorspace::colorFromNormalized() methods are left untyped. Typing them ColorChannelInterface (what fromNormalized() returns) makes PHPStan report that the spread arguments don't match the specific channel types the Color constructors expect. Fixing that properly is a refactor rather than typing.
  • Stream resources (File::$stream, FileInterface::toStream(), CanBuildStream::buildStreamOrFail(), the GD ResolutionAnalyzer handles and encoder callbacks) keep their docblock types, since PHP has no native resource type and mixed would add nothing.

No behaviour change. PHPStan and PHPCS pass.

Type the remaining untyped class constants (a PHP 8.3 feature) in
DominantPaletteAnalyzer and the VibrantMuted theme definition, and add
parameter and return types to closures and arrow functions in src and
tests that were still missing them.

Stream resources keep their docblock-only types since PHP has no native
resource type.
@olivervogel

Copy link
Copy Markdown
Member

Thanks.

@olivervogel
olivervogel merged commit b305a3b into Intervention:develop Oct 5, 2026
8 checks passed
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