Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

TypeGenerator add a backslash for a custom type with ParameterGenerator #117

Closed
florentsorel opened this issue Jul 4, 2017 · 3 comments
Closed
Assignees
Labels

Comments

@florentsorel
Copy link

Hello,

I have a problem with TypeGenerator when it's used with ParameterGenerator.

The output from generate method is return $nullable . '\' . $this->type;

I'm using it like this:

$this->addUse('Zend\EventManager\EventInterface');

$method = new MethodGenerator();
$method->setName('onBootstrap');

$method->setParameter(
    new ParameterGenerator(
        'event',
        'EventInterface'
    )
);

$this->addMethodFromGenerator($method);

The issue here is when the file is generated, the parameter type looks like:

use Zend\EventManager\EventInterface;

public function onBootstrap(\EventInterface $event)
{
}

Could you provide a way to generate short namespace without backslash for ParameterGenerator? (because $nullable will always be empty from the ParameterGenerator context.)

Like when we define implemented interfaces the method generateShortOrCompleteClassname is called in ClassGenerator

If the use statment exists, then use short synthax instead of fully qualified name.

@Ocramius
Copy link
Member

Ocramius commented Jul 4, 2017

You have to pass the FQCN, not just the short name.

@Ocramius
Copy link
Member

Ocramius commented Jul 4, 2017

See #76

@Ocramius Ocramius closed this as completed Jul 4, 2017
@Ocramius Ocramius self-assigned this Jul 4, 2017
@Ocramius
Copy link
Member

Ocramius commented Jul 4, 2017

To clarify further: this was discussed before.

The code generator is a code generator, and changing parameters given based on context is a mess that leads to an infinite amount of bugs down the line.

Make it working code, then focus on optimising imports later (can be done with an AST pass, for example, but not with this library)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants