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
refactor $conditionalExpressions
#1270
Conversation
'Property PropertiesFromArrayIntoObject\Foo::$float_test (float) does not accept float|int|string.', | ||
69, | ||
], | ||
[ | ||
'Property PropertiesFromArrayIntoObject\Foo::$foo (string) does not accept float|int|string.', | ||
69, | ||
], | ||
[ | ||
'Property PropertiesFromArrayIntoObject\Foo::$lall (int) does not accept float|int|string.', | ||
'Property PropertiesFromArrayIntoObject\Foo::$lall (int) does not accept string.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes sense to me. The error must be same with line 54.
phpstan-src/tests/PHPStan/Rules/Properties/data/properties-from-array-into-object.php
Lines 48 to 70 in d4b1163
public function create_simple_1(): self { | |
$self = new self(); | |
$data = $this->data(); | |
foreach($data as $property => $value) { | |
$self->{$property} = $value; | |
} | |
return $self; | |
} | |
public function create_complex(): self { | |
$self = new self(); | |
foreach($this->data() as $property => $value) { | |
if ($property === 'test') { | |
if ($self->{$property} === null) { | |
$self->{$property} = new \stdClass(); | |
} | |
} else { | |
$self->{$property} = $value; | |
} |
Checked for the failing tests and I think it's unrelated. |
Thank you! |
@rajyan I think there's opportunity for refactoring, most likely in multiple steps:
There are also other issues in https://github.com/phpstan/phpstan/milestone/12 (potentially very hard to solve) that you might tackle (if you feel like it) after 1) and 2) :) Thanks for considering! |
Thank you for your pointers. |
FYI @rajyan I noticed there are some commented-out test cases in phpstan-src/tests/PHPStan/Analyser/data/dependent-variable-certainty.php Lines 261 to 480 in 9f1e793
|
Thank you! I look into it. |
Working on phpstan/phpstan#3677 and half way done.
If my understanding is correct, the logic in merge of
conditionalExpressions
infilterBySpecifiedTypes
should be consistent withphpstan-src/src/Analyser/MutatingScope.php
Lines 4784 to 4786 in 0b3bfeb
so
continue 2
should becontinue
. I'm not sure enough with the fix yet, but the fixed test looks better to me.Also, this example (coalesce -> coalesce, coalesce -> ternary) is fixed with this change.
these cases are not fixed yet. (ternary -> ternary, ternary -> coalesce)
While investigating this issue, I noticed some inconsistencies in keys of
$conditionalExpressions
.I fixed to set key from
$holder->getKey()
like inphpstan-src/src/Analyser/MutatingScope.php
Lines 4514 to 4515 in f8be122
phpstan-src/src/Analyser/MutatingScope.php
Lines 4737 to 4741 in 0b3bfeb