fix: overly strict ArraySpreadInsteadOfArrayMergeRector#7247
fix: overly strict ArraySpreadInsteadOfArrayMergeRector#7247samsonasik merged 1 commit intorectorphp:mainfrom
Conversation
3ab7e36 to
628d85d
Compare
samsonasik
left a comment
There was a problem hiding this comment.
since it optional rule and not part of set, I am fine with this 👍
|
Thank you @calebdw |
This is only true for php8+ |
|
@staabm oops, yes, working with non array at https://3v4l.org/OWtO5#v7.4.33 I will create PR for it. |
|
@staabm it seems there is already test for php 7.4, see so, the issue is probably it should skip |
|
I am not sure whether there is a bug. Just wanted to point out that one of the assumptions does not work for php7 |
|
@staabm it is a bug, I created PR: to avoid regression. |
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
Hello!
The
ArraySpreadInsteadOfArrayMergeRectorwas unnecessarily skipping valid transformations when it couldn't determine that parameters were explicitly typed asArrayTypeorConstantArrayType. This prevented the rector from transforming many validarray_merge()calls to the more modern spread operator syntax:This PR removes overly strict type requirement that prevented these valid transformations---
array_merge()itself enforces array types at runtime, it has a strict signature and throws aTypeErrorif non-arrays are passed.This is safe for the following reasons:
array_merge($var1, $var2), then$var1and$var2are guaranteed to be arrays at runtime. Converting to[...$var1, ...$var2]maintains the exact same runtime behavior and type requirements.array_merge($nonArray)and[...$nonArray]throw errors when given non-arrays, so the transformation doesn't change error handling (https://3v4l.org/2YVCi)array_merge(), there's really no reason to not use itThanks!