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
HeaderCommentFixer - support monolithic files with shebang #6199
HeaderCommentFixer - support monolithic files with shebang #6199
Conversation
@kubawerlos , do I understand right that you don't want to support all non-monolithic files, but support monolithic scripts that are having a shebang? |
@keradus well I might named the PR wrong, I meant to support what is changed in 1 === $tokens->countTokenKind(T_OPEN_TAG); and actually it could be exactly what |
let's change the name of PR then, as we are still not supporting all non-monolithic files (and we shouldn't) Why not changing the implementation of |
In theory, a file like the following is not monolithic: some leading text that is echo'd and not a hash/shebang
<?php // single PHP open tag
echo 123; as such keeping the method to detect it stating it is not monolithic seems good to me. #!/usr/bin/env php
<?php
echo 1; I think it was HHVM that would tokenize a hashbang to a different type than an T_INLINE_HTML, but PHP doesn't. Since for us here we only care about this for the header fixer I'm +1 as PHP templates are rare and templates not starting an open tag even more rare. |
I believe we should: fix regular files
fix scripts with shebang: #!/usr/bin/env php
<?php
echo 1; NOT fix non-monolithic and non-script files, eg foo bar
<?PHP
echo "baz" <?PHP
echo "foo bar"
?>
baz |
@@ -118,7 +118,7 @@ public function getDefinition(): FixerDefinitionInterface | |||
*/ | |||
public function isCandidate(Tokens $tokens): bool | |||
{ | |||
return isset($tokens[0]) && $tokens[0]->isGivenKind(T_OPEN_TAG) && $tokens->isMonolithicPhp(); | |||
return 1 === $tokens->countTokenKind(T_OPEN_TAG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's update isMonolithic
instead?
#6199 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this cleanup first: #6229 and then have a discussion how to update isMonolithic
properly - I've already pushed the changes, but it seems a bit naive solution: https://github.com/werlos/PHP-CS-Fixer/compare/simplify_Tokens_isMonolithicPhp_tests...werlos:update_Tokens_isMonolithicPhp and I believe deserves separate PR.
Then we will continue this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's force-squash during merging
Thank you @kubawerlos. |
Such as
dev-tools/composer-alias-update.php
anddev-tools/info-extractor.php
.