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

Class constant named FUNCTION is incorrectly tokenized #1180

Closed
mniewrzal opened this issue Sep 30, 2016 · 5 comments
Closed

Class constant named FUNCTION is incorrectly tokenized #1180

mniewrzal opened this issue Sep 30, 2016 · 5 comments

Comments

@mniewrzal
Copy link

PHPCBF wasn't able to format file: https://raw.githubusercontent.com/felixfbecker/php-language-server/master/src/SymbolFinder.php
It looks that number of iterations was insufficient.

Console output:

Processing SymbolFinder.php [PHP => 704 tokens in 84 lines]... DONE in 31ms (12 fixable violations)
        => Fixing file: 2/12 violations remaining [made 50 passes]... ERROR in 1.66 secs
No fixable errors were found
Time: 1.71 secs; Memory: 6Mb

PHP_CodeSniffer version 2.7.0 (stable)

@mniewrzal
Copy link
Author

I extracted minimal snippet to reproduce issue. Source file under link will probably change in near feature.

<?php
       if ($symbol && $kind === SymbolKind::VARIABLE && ($symbol->kind === SymbolKind::METHOD || $symbol->kind === SymbolKind::FUNCTION)
        ) 

@aik099
Copy link
Contributor

aik099 commented Sep 30, 2016

  1. what coding standard are you using?
  2. how does phpcs report look for that code snippet?

@mniewrzal
Copy link
Author

what coding standard are you using?

I tested phpcbf with '--standard=PSR2' and '--standard=PEAR', formatting ends with error for both.

how does phpcs report look for that code snippet?

vendor/bin/phpcs TestFile.php --standard=PEAR

FILE: /home/wywrzal/git/php-language-server/TestFile.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
 2 | ERROR   | [ ] Missing file doc comment
 2 | WARNING | [x] Inline control structures are discouraged
 2 | WARNING | [ ] Line exceeds 85 characters; contains 136
   |         |     characters
 3 | ERROR   | [x] Multi-line IF statement not indented correctly;
   |         |     expected 7 spaces but found 8
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
vendor/bin/phpcs TestFile.php --standard=PSR2

FILE: /home/wywrzal/git/php-language-server/TestFile.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 2 LINES
----------------------------------------------------------------------
 2 | ERROR   | [x] Inline control structures are not allowed
 2 | WARNING | [ ] Line exceeds 120 characters; contains 136
   |         |     characters
 3 | ERROR   | [x] Whitespace found at end of line
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

@gsherwood
Copy link
Member

The problem appears to be caused by the tokenizing of SymbolKind::FUNCTION, where FUNCTION is seem a T_FUNCTION instead of T_STRING.

@gsherwood gsherwood changed the title Unable to format PHP file Class constant named FUNCTION is incorrectly tokenized Oct 4, 2016
gsherwood added a commit that referenced this issue Oct 4, 2016
I don't think this is related to PHP 5.6, but this was the best place to put the code.
@gsherwood
Copy link
Member

This has now been fixed. Thanks for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants