Skip to content

phpstan should not trust the phpdoc #1926

@dbu

Description

@dbu

Summary of a problem or a feature request

Result of || is always false is wrongly reported for a parameter validation.

Code snippet that reproduces the problem

   /**
     * @param SerializerInterface&ArrayTransformerInterface $originalSerializer must implement both SerializerInterface and ArrayTransformerInterface interfaces
     */
    public function __construct(
        $originalSerializer,
    ) {
        if (!$originalSerializer instanceof SerializerInterface
            || !$originalSerializer instanceof ArrayTransformerInterface
        ) {
            throw new \InvalidArgumentException(sprintf(
                'Original serializer must implement both ArrayTransformerInterface and SerializerInterface, but is %s',
                \get_class($originalSerializer)
            ));
        }

Expected output

This code seems fine correct to me. The check is needed because there is no PHP parameter declaration.

For context, this happens in liip/serializer-jms-adapter#1 - our workaround was to ignore the warning about || always being false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions