phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

ConstantArrayType: fix returned ConstantArrayTypeAndMethod

Open janedbal opened this issue 1 year ago • 3 comments
trafficstars

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();

janedbal avatar Aug 30 '24 09:08 janedbal

Is missing a test

staabm avatar Sep 01 '24 05:09 staabm

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

janedbal avatar Sep 02 '24 10:09 janedbal

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.

ondrejmirtes avatar Sep 02 '24 17:09 ondrejmirtes

Added a test and rebased on top of 2.0.x

janedbal avatar Dec 27 '24 15:12 janedbal

Thank you.

ondrejmirtes avatar Jan 04 '25 13:01 ondrejmirtes

I'm sorry, had to revert this. There are regressions (could be seen in the issue bot):

  • https://github.com/phpstan/phpstan/issues/11859
  • https://github.com/phpstan/phpstan/issues/8071

ondrejmirtes avatar Jan 04 '25 14:01 ondrejmirtes