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

Yield From values are not recognised as returned values in Squiz FunctionComment sniff #1364

Closed
tomasfejfar opened this issue Feb 20, 2017 · 4 comments

Comments

@tomasfejfar
Copy link

function fetchEntity(): MyEntity
{
// get it from DB
}

/**
 * @return MyEntity[]|Generator
*/
function generator(): Generator
{
    yield $this->fetchEntity();
}

I want to typehint the generator contents to my IDE. It's a generator, but it acts like an array of entities as well.

Unfortunatelly I end up with phpcs error:
Function has no return statement, but annotation @return is present (Squiz.Commenting.FunctionComment.InvalidNoReturn)

Is this expected behaviour?

@gsherwood
Copy link
Member

This was reported as bug #479 and released in version 2.3.1 nearly 2 years ago. I've given it another test and I don't receive the error, and the unit tests are still passing, so I can't see a regression.

Are you using a really old version of PHPCS?

@tomasfejfar
Copy link
Author

Oh, sorry I misinterpreted the problem when creating the issue. The root cause seem to be the usage of yield from.

$ vendor\bin\phpcs --version
PHP_CodeSniffer version 2.8.1 (stable) by Squiz (http://www.squiz.net)
$ vendor\bin\phpcs --standard=ruleset.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp app
...
 77 | ERROR | [ ] Function has no return statement, but annotation
    |       |     @return is present
    |       |     (Squiz.Commenting.FunctionComment.InvalidNoReturn)

The offending code is

	/**
	 * @return \App\Entity[]|\Generator  <------------ line 77
	 */
	public function createAllEntitiesGenerator(): Generator
	{
		$query = $this
			->createAllEntitiesQueryBuilder()
			->getQuery();
		yield from Util::createGeneratorFromQueryWithEmClear($query, $this->entityManager);
	}

@gsherwood gsherwood changed the title Function that is a generator should be typehintable to contents of the generator Yield From values are not recognised as returned values in Squiz FunctionComment sniff Mar 8, 2017
gsherwood added a commit that referenced this issue Mar 8, 2017
@gsherwood
Copy link
Member

Thanks for that extra code. It made the problem is to find and fix.

@tomasfejfar
Copy link
Author

I was just trying to understand how the tests work and to send PR 🙂 It's great that you managed to find and fix it so quickly. Thanks.

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

No branches or pull requests

2 participants