Skip to content

ContextFactory incorrect namespace aliases #76

Closed
@piku235

Description

@piku235

Following the example below:

namespace App;

use Common\Domain\DayOfWeek;

class Foo 
{
    /**
     * @var DayOfWeek
     */
    private $dayOfWeek;
}

Unfortunately, instead of the typeCommon\Domain\DayOfWeek on the dayOfWeek property, its type is App\DayOfWeek.

After a longer digging, I stumbled upon ContextFactory::extractUseStatements method. The problem here is how this method uses aliasing.
For the example above the Context::getNamespaceAliases call will end up with

array('Common\Domain\DayOfWeek' => 'Common\Domain\DayOfWeek')

instead of

array('DayOfWeek' => 'Common\Domain\DayOfWeek')

Also, I noticed the tests testReadsAliasesFromClassReflection, testReadsAliasesFromProvidedNamespaceAndContent are incorrect for ContextFactory, that's why it looks like no one has been able to notice it all this time.

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