Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create method typed array with docblock Object[] #60

Open
3ehu opened this issue Mar 21, 2019 · 2 comments
Open

Unable to create method typed array with docblock Object[] #60

3ehu opened this issue Mar 21, 2019 · 2 comments

Comments

@3ehu
Copy link

3ehu commented Mar 21, 2019

This line:

https://github.com/gossi/php-code-generator/blob/d67b8f9d775710e9401fc1a9306c7b7797860a65/src/model/parts/TypeDocblockGeneratorPart.php#L52

Overwriting @return tag if you define method type.

This causes that I'm unable to generate method

/**

  • @return Bar[]
    */
    function Foo(): array
@gossi
Copy link
Member

gossi commented Mar 21, 2019

Can you give a code example?

@3ehu
Copy link
Author

3ehu commented Mar 22, 2019

Case 1:

        $method = PhpMethod::create('MyMethod');
        $method->setType('Bar[]');

//        $method->getDocblock()->appendTag(ReturnTag::create("Bar[]"));

        $class = PhpClass::create("Bar")
            ->setMethod($method);

        $generator = new CodeGenerator([
            'generateReturnTypeHints' =>  true
        ]);
        print_r($generator->generate($class));

Result

	/**
	 * @return Bar[]
	 */
	public function MyMethod(): Bar[] {

Case 2:

        $method = PhpMethod::create('MyMethod');
//        $method->setType('array');

        $method->getDocblock()->appendTag(ReturnTag::create("Bar[]"));

        $class = PhpClass::create("Bar")
            ->setMethod($method);

        $generator = new CodeGenerator([
            'generateReturnTypeHints' =>  true
        ]);
        print_r($generator->generate($class));

Result:

	/**
	 * @return Bar[]
	 */
	public function MyMethod() {

Case 3

        $method = PhpMethod::create('MyMethod');
        $method->setType('array');

        $method->getDocblock()->appendTag(ReturnTag::create("Bar[]"));

        $class = PhpClass::create("Bar")
            ->setMethod($method);

        $generator = new CodeGenerator([
            'generateReturnTypeHints' =>  true
        ]);
        print_r($generator->generate($class));

Result:

	/**
	 * @return array
	 */
	public function MyMethod(): array {

Expected Result ( Comment lines 51-53 in TypeDocblockGeneratorPart.php)

	/**
	 * @return Bar[]
	 */
	public function MyMethod(): array {

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

No branches or pull requests

2 participants