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

False positive: null check condition in nested method #999

Closed
JanMikes opened this issue May 10, 2018 · 1 comment
Closed

False positive: null check condition in nested method #999

JanMikes opened this issue May 10, 2018 · 1 comment

Comments

@JanMikes
Copy link
Contributor

JanMikes commented May 10, 2018

Summary of a problem or a feature request

It would be awesome, if there is nullability check in other method, to recognise that variable can not be null anymore.

Code snippet that reproduces the problem

https://phpstan.org/r/4e1685f6643e62a6eb8ed7c9fb31d482

	/** @var null|string */
	private $a;

	public function hasA(): bool
	{
		return $this->a !== null;	
	}
	
	
	public function getA(): string
	{
		if (false === $this->hasA()) {
			throw new \LogicException();
		}
		
		return $this->a;
	}

Expected output

I expected no errors as it seems to be valid PHP code to me.

@JanMikes JanMikes changed the title False positive: null check condition in other method False positive: null check condition in nested method May 10, 2018
@ondrejmirtes
Copy link
Member

This has been discussed many times 😊

See #534, #634, #201.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants