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

ConstantArrayType: fix returned ConstantArrayTypeAndMethod #3372

Conversation

janedbal
Copy link
Contributor

@janedbal janedbal commented Aug 30, 2024

With this, we can recognize those cases:

class Parnt
{
	public function __construct()
	{
		array_map([self::class, 'method1'], [1]); // calls Parnt::method1
		array_map([$this, 'method1'], [1]); // calls Child::method1
	}

	public function method1(): void {
	    echo 'parent';
	}
	
}

class Child extends Parnt
{
	public function __construct()
	{
		parent::__construct();
	}

	public function method1(): void {
	    echo 'child';
	}
	
}

new Child();

@staabm
Copy link
Contributor

staabm commented Sep 1, 2024

Is missing a test

@janedbal
Copy link
Contributor Author

janedbal commented Sep 2, 2024

I'm not sure if there is any native functionality to test against. I need this function for proper dead-code analysis.

@ondrejmirtes
Copy link
Member

If nothing else is possible then we need a unit test in ConstantArrayTypeTest. Make sure to initialize $this->createReflectionProvider() so that the Type works properly.

@janedbal janedbal force-pushed the constant-array-type-fix-findTypeAndMethodNames branch from c19e56a to dd1184a Compare December 27, 2024 15:35
@janedbal janedbal changed the base branch from 1.12.x to 2.0.x December 27, 2024 15:35

$this->assertCount(1, $classStringResult);
$this->assertCount(1, $objectResult);
$this->assertInstanceOf(ConstantStringType::class, $classStringResult[0]->getType());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this is still just ObjectType here.

@janedbal
Copy link
Contributor Author

Added a test and rebased on top of 2.0.x

@ondrejmirtes ondrejmirtes changed the base branch from 2.0.x to 2.1.x January 4, 2025 13:57
@ondrejmirtes ondrejmirtes merged commit 13f6406 into phpstan:2.1.x Jan 4, 2025
428 of 430 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@ondrejmirtes
Copy link
Member

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.

3 participants