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

ReturnToYieldFromFixer error on file-wide return #7317

Closed
juliangut opened this issue Sep 23, 2023 · 0 comments · Fixed by #7318
Closed

ReturnToYieldFromFixer error on file-wide return #7317

juliangut opened this issue Sep 23, 2023 · 0 comments · Fixed by #7318
Labels

Comments

@juliangut
Copy link
Contributor

juliangut commented Sep 23, 2023

Bug report

Description

When run in files simply returning arrays, such as configuration files, shouldBeFixed method errors in the process of detecting the end of the array: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/src/Fixer/ArrayNotation/ReturnToYieldFromFixer.php#L85

The next thing in the file is the end of it but the fixer assumes there should be something else (assumes the return is inside a method/function) when actually in this case the tokens index is null and the expression fails with "Illegal offset type"

Simply checking $functionEndIndex !== null should fix the problem

Runtime version

PHP CS Fixer 3.28.0 Jump & Run by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.2.10

Code snippet that reproduces the problem

<?php
return [
     static function() { return []; ),
];
@juliangut juliangut changed the title ReturnToYieldFromFixer error on file return ReturnToYieldFromFixer error on file-wide return Sep 23, 2023
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 a pull request may close this issue.

1 participant