Skip to content

[PHPStanStaticTypeMapper] Allow Closure type on ClosureTypeMapper based on PHP versions#4785

Merged
TomasVotruba merged 10 commits intomainfrom
enable-return-closure
Aug 14, 2023
Merged

[PHPStanStaticTypeMapper] Allow Closure type on ClosureTypeMapper based on PHP versions#4785
TomasVotruba merged 10 commits intomainfrom
enable-return-closure

Conversation

@samsonasik
Copy link
Copy Markdown
Member

No description provided.

Comment on lines -1 to -23
<?php

namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture;

final class SkipPropertyAssign
{
private $command;

public function __construct(\Closure $command)
{
$this->command = $command;
}

public function getCommand()
{
if (!$this->command instanceof \Closure) {
return $this->command;
}

$this->command = ($this->command)();

return $this->command;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@TomasVotruba I removed this test fixture, because for whatever type assigned in __construct(), if it replaced in different method, it will always be new type, which I think very rare use case, eg on symfony:

https://github.com/symfony/symfony/blob/c82d8c99090346aaf938346a5342625e6eafc02e/src/Symfony/Component/Console/Command/LazyCommand.php#L194

The ClassPropertyAssignToConstructorPromotionRector don't cover that, as other type when re-assign with other type in other method will have different type as well.

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@TomasVotruba
Copy link
Copy Markdown
Member

Thanks, let's merge this 👍

@TomasVotruba TomasVotruba merged commit b0105f2 into main Aug 14, 2023
@TomasVotruba TomasVotruba deleted the enable-return-closure branch August 14, 2023 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants