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
Add FopenFlagOrderFixer & FopenFlagsFixer #3812
Add FopenFlagOrderFixer & FopenFlagsFixer #3812
Conversation
That could be different fixer that would ensure there is always
|
ping @ntzm could you provide a string that shows all possible flags in the correct order? Than this fixer can be finished :) |
Sorry missed your initial ping, will sort at the weekend |
|
thanks @ntzm :) |
@ntzm anything you would like me to change here? |
$content = $tokens[$argumentFlagIndex]->getContent(); | ||
$contentQuote = $content[0]; // `'` or `"` | ||
|
||
$content = substr($content, 1, -1); |
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.
How about binary strings? e.g. b'rw'
, B"rw"
😄
$argumentFlagIndex = null; | ||
|
||
for ($i = $argumentStartIndex; $i <= $argumentEndIndex; ++$i) { | ||
if ($tokens[$i]->equalsAny([[T_WHITESPACE], [T_COMMENT], [T_DOC_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.
I think isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])
may be more optimal here
Think something is wrong with my GitHub notifications, seem to be missing some, sorry about the delay |
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.
Just minor points
src/AbstractFopenFlagOrderFixer.php
Outdated
* | ||
* @author SpacePossum | ||
*/ | ||
abstract class AbstractFopenFlagOrderFixer extends AbstractFunctionReferenceFixer |
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.
I would suggest removing Order
from this name, as only one of the extending classes actually has to do with ordering.
@@ -166,6 +166,7 @@ | |||
'dir_constant' => true, | |||
'ereg_to_preg' => true, | |||
'error_suppression' => true, | |||
'fopen_flag_order' => true, |
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.
Do we want the other rule as well?
|
||
if (strlen($mode) > 13) { // 13 === length 'r+w+a+x+c+etb' | ||
return; // sanity check to be less risky | ||
} |
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.
Line 65 - 79 seem to be duplicated on both fixers, can they be a protected function on the base class?
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.
line 77 shouldn't be the same, besides that I think the shared logic shouldn't be made abstract as it will limit other possible fixers
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.
As the abstract fixer is called AbstractFopenFlagFixer
all extensions should operate only on the flags of fopen. I would thus like to make the case that actually all logic in this function except lines 77-86 should be in the parent class. The method now only needs to take in string $mode
and return either a fixed or non-altered $mode
. For the other fixer, the lines are 78-83 (plus the implode of 84).
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.
I disagree; other fixers might want to operate on more tokens, like complex arguments, and not (only) when the mode is set as literal.
src/AbstractFopenFlagFixer.php
Outdated
$arguments = $argumentsAnalyzer->getArguments( | ||
$tokens, | ||
$index, | ||
$tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index) |
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.
This is already done in $this->find()
and available as $candidate[2]
.
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.
nice catch, fixed
Thank you @SpacePossum. |
This PR was merged into the 2.13-dev branch. Discussion ---------- Add FopenFlagOrderFixer & FopenFlagsFixer closes #3417 ping @ntzm , hope you can help me out with: - define the order of all flags - ~do we want to have an option to remove flags when found, like `t`~ - ~do we want to have an option to add flags when not found, like `b`~ Commits ------- 8682d86 Add FopenFlagOrderFixer & FopenFlagsFixer
closes #3417
ping @ntzm , hope you can help me out with:
do we want to have an option to remove flags when found, liket
do we want to have an option to add flags when not found, likeb