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

SquareBraceTransformer - fix detect array destructing in foreach #6064

Merged
merged 1 commit into from
Oct 10, 2021
Merged

SquareBraceTransformer - fix detect array destructing in foreach #6064

merged 1 commit into from
Oct 10, 2021

Conversation

SpacePossum
Copy link
Contributor

closes #6062

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0007%) to 92.82% when pulling b2bee6b on SpacePossum:6062 into 39192f5 on FriendsOfPHP:master.

@jacekciach
Copy link

@SpacePossum I've checked out the branch: the fix works.

$ ./php-cs-fixer fix --dry-run -vvv --diff --using-cache=no --config=../php-cs-fixer-bug/.php-cs-fixer.dist.php ../php-cs-fixer-bug/testcase/
PHP CS Fixer 3.2.2-DEV by Fabien Potencier and Dariusz Ruminski
Runtime: PHP 7.2.18
Loaded config default from "../php-cs-fixer-bug/.php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.
F                                                                                                                                                       1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error
   1) php-cs-fixer-bug/testcase/test.php (list_syntax)
      ---------- begin diff ----------
--- /home/jciach/php/php-cs-fixer-bug/testcase/test.php
+++ /home/jciach/php/php-cs-fixer-bug/testcase/test.php
@@ -1,27 +1,27 @@
 <?php
 
-foreach ($iterable as [
+foreach ($iterable as list(
     'a' => $a,
     'b' => $b,
-]) {
+)) {
     // do something
 }
 
-foreach ($iterable as [
+foreach ($iterable as list(
     $a,
     $b,
-]) {
+)) {
     // do something
 }
 
 $result = $pdo->query("SELECT id, name FROM employees");
-while ([$id, $name] = $result->fetch(PDO::FETCH_NUM)) {
+while (list($id, $name) = $result->fetch(PDO::FETCH_NUM)) {
     echo "id: $id, name: $name\n";
 }
 
-[$a, $b] = $array;
+list($a, $b) = $array;
 
-[
+list(
     $a,
     $b,
-] = $array;
+) = $array;

      ----------- end diff -----------


Checked all files in 0.068 seconds, 12.000 MB memory used

@SpacePossum SpacePossum merged commit 3968d73 into PHP-CS-Fixer:master Oct 10, 2021
@SpacePossum SpacePossum deleted the 6062 branch October 10, 2021 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Short syntax lists in for/foreach loop declarations are seen as arrays
3 participants