Skip to content

Better typehint selection for methods used in several examples #1

Description

@stof

This continues the discussion started by @docteurklein in phpspec/phpspec#230 (comment) as he made a valid argument:

Take the following spec:

function it_does_something_with_a_token(ArrayToken $token)
{
    $token->getId()->willReturn(1234);

    $this->foo($token)->shouldReturn(1234);
}

function it_does_something_special_with_object_token(ObjectToken $token)
{
    $token->getId()->willReturn(null);

    $this->foo($token)->shouldReturn(3);
}

In this case, both examples will ask for the generation of foo. But applyignt he current logic will typehint it as ArrayToken or ObjectToken (depending of which example wins) and the other example will explode with a fatal error.
But the spec here allows you to know that none of these typehints are the expected one. In such case, it should look for all cases asking for generation, and find the common type (by looking at the common ancestor class in the inheritance hierarchy or a common interface)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions