libvips / php-vips

php binding for libvips
MIT License
615 stars 25 forks source link

composite annotated incorrectly #199

Closed axkirillov closed 1 year ago

axkirillov commented 1 year ago

Is the composite method annotated incorrectly?

    /**
     * Composite $other on top of $this with $mode.
     *
     * @param mixed $other          The overlay.
     * @param BlendMode|array $mode The mode to composite with.
     * @param array $options        An array of options to pass to the operation.
     *
     * @throws Exception
     *
     * @return Image A new image.
     */
    public function composite($other, $mode, array $options = []): Image

The second param is annotated as BlendMode|array, but BlendMode is not a true enum, just an empty class with a bunch of constants. I assume the intention here is just to use the constants but then the type is string and static analysers (phpstan) will complain about that.

jcupitt commented 1 year ago

Hi @axkirillov,

You're right, this could probably be improved.

php-vips lets you either use numbers for enum values (so 2 is VIPS_BLEND_MODE_OVER, for example), or strings (they get looked up in the enum introspection and turned to numbers before being passed to libvips).

BlendMode is supposed to help catch typos. I think php only added true enums in 8.1, so we can't use them yet.