-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Undefined offset: 0 in PropertyHelper.php on line 81 #881
Comments
@morozov it’s caused probably by “else if”. Use “elseif” and everything should be fine I think. There’s also sniff in PHPCS itself that can report “else if” usage. |
@kukulich thank you for the suggestion. I just tried it on the real file (4800 LOC, proprietary codebase), and the crash is still reproducible. If you want, I can post another PoC that doesn't include Regardless of whether there is a workaround, I believe the issue is worth fixing or at least some better research. I'm trying to apply the coding standard to a huge legacy old codebase with thousands of violations in some files. Getting the fixer crash in the middle of a multi-hour long process, excluding the problematic files and starting over is a bit unproductive (I found a couple more issues like this in the OOTB standards as well). |
@morozov It looks I cannot reproduce it on PHP 7.4. Do you use PHP 7.2 or lower? Btw it you use |
I used PHP 7.4.2 and it's also reproducible with 7.3.14.
Thank you for the suggestion. I was thinking of applying the fixes in parts. |
@morozov Hmm, it may be bug in PHPCS that's caused by some combination of sniffs and fixes :( The method |
According to the stack trace, it's called from within the Slevomat Coding Standard:
It didn't help. The issue is reproducible without the <?php
class Problem
{
public function test()
{
return 1;
if (true) {
return;
} elseif (true) {
return;
} else { // A comment
return;
}
}
protected $property;
} |
@morozov I'm not sure if you understood me well.
|
@kukulich ah… I see. Makes sense. So far, I ended up manually moving the comment and it also enabled fixing the entire file: diff --git a/Problem.php b/Problem.php
index f56c9e0bf52..7a73c72b353 100644
--- a/Problem.php
+++ b/Problem.php
@@ -8,7 +8,8 @@ class Problem
return;
} else if (true) {
return;
- } else { // A comment
+ } else {
+ // A comment
return;
}
} |
Inline comments should be also fixed by #890 |
PHPCBF no longer crashes fixing the example in the description as well as the real 4800-LOC file. However, the result of fixing the example has some misalignment: diff --git a/Problem.php b/Problem.php
index 41ba5980f5e..b1b698f2d0c 100644
--- a/Problem.php
+++ b/Problem.php
@@ -6,11 +6,14 @@ class Problem
{
if (true) {
return;
- } elseif (true) {
- return;
- } else { // A comment
+ }
+
+ if (true) {
return;
}
+
+ // A comment
+ return;
}
protected $property; Is it something that could be addressed here or we’ll need a separate issue for that? |
@morozov Try dev-master please. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This issue is similar to #254. I don't know whether it's the PHP_CodeSniffer that produces an invalid token or the Slevomat Coding Standard that expects the unavailable properties of the token, so I'll file it here.
These are the relevant dependency versions:
Consider the following code example:
An attempt to fix this file make
phpcs
crash:As far as I understand the failure, the code expects at least one condition available in the token but there is none in this case.
coding-standard/SlevomatCodingStandard/Helpers/PropertyHelper.php
Line 81 in c8f2e2b
I was able to reproduce the issue only by keeping the property declared after the method, the
else if
combination and the comment after theelse
.The text was updated successfully, but these errors were encountered: