Skip to content

Introduce checkTooWideParameterOutInProtectedAndPublicMethods #4229

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

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

Closes phpstan/phpstan#12080

I copied the strategy from TooWideMethodReturnTypehintRule

$isFirstDeclaration = $method->getPrototype()->getDeclaringClass() === $method->getDeclaringClass();
if (!$method->isPrivate()) {
if (!$method->getDeclaringClass()->isFinal() && !$method->isFinal()->yes()) {
if (!$this->checkProtectedAndPublicMethods) {
return [];
}
if ($isFirstDeclaration) {
return [];
}
}
}

But I didn't add the isFirstDeclaration check yet because it removes almost every reported errors... (and no early return was added before). Also, I already don't really understand the check in TooWideMethodReturnTypehintRule

Cause we're getting

class WithoutChild
{
     public function foo(): ?int // No error, but it "should" be reported with checkPublicAndProtected
	{
		return 42;
	}
}

class A
{
	public function foo(): int|string // No error cause it's the first declaration
	{
		return 42;
	}
}

class B extends A
{
	public function foo(): int|string // never returns string so it can be removed from the return type => but it will crash class C.
	{
		return 42;
	}
}

class C extends B
{
	public function foo(): int|string // never returns int so it can be removed from the return type
	{
		return '42';
	}
}

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

Successfully merging this pull request may close these issues.

by-ref @param-out should not complain about unused types unless final
1 participant