-
Notifications
You must be signed in to change notification settings - Fork 51
Implement missing sniffs (upgrading to PHPCS v3) #8
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
Conversation
07068be
to
4fa08c1
Compare
Still need to update documentation, sure... |
php: | ||
- 7.1 | ||
- 7.2 | ||
- nightly |
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.
Nightly should be allowed to fail
composer.json
Outdated
"require": { | ||
"php": "^7.1", | ||
"squizlabs/php_codesniffer": "~3.0", | ||
"dealerdirect/phpcodesniffer-composer-installer": "^0.4" |
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.
O_o
Also - unsure if I'd want that in the dep chain...
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.
The other option is to manually have composer scripts to register the directory (on each repo).
public function register() | ||
{ | ||
return [ | ||
T_IF, |
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.
Use FQNs for absolute symbols (prefix with \
)
{ | ||
$tokens = $phpcsFile->getTokens(); | ||
|
||
if (isset($tokens[$stackPtr]['parenthesis_opener']) === false |
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.
Is there a constant for these keys?
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.
Nope... I can add.
]; | ||
} | ||
|
||
public function process(File $phpcsFile, $stackPtr) |
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.
What's the method return type?
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.
According to the interface is void|int
, so no way to add the return type declaration here.
$file->fixer->replaceToken($nextTokenPosition, ''); | ||
} | ||
|
||
private function validateParenthesisCloser( |
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.
Please document the array
parameter type
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.
That comes from PHP_CodeSniffer\Files\File#tokens
and all it says is: "The tokens stack map.". I'm not sure what we should add here.
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 can add mixed[][]
if it helps 😂
31 => 1, | ||
34 => 1, | ||
); | ||
return [T_BOOLEAN_NOT]; |
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.
Generally, look for T_
and use the FQN
$phpcsFile->addError('Missing space before the string concatenation operator ".".', $stackPtr, 'Before'); | ||
} | ||
do { | ||
--$colonPosition; |
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.
Use array_reverse()
instead of relying on decrements - really odd and uncommon to read
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.
Can't reverse the entire map of tokens, maybe extracting that into a method with a proper name?
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.
Ah, I see - you basically need that position to be set after the while
.
Is it possible that this block ever goes into an infinite loop? It looks like it, but the assumptions around its design are missing for me.
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.
That sniff is applied on return type tokens, there's no way to declare return types without using the colon. It might go into an infinite loop if PHP syntax changes.
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.
Got it 👍
@@ -0,0 +1,33 @@ | |||
<?xml version="1.0"?> | |||
<ruleset name="Doctrine"> |
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.
Is there an XSD somewhere?
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.
Nope 😞
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.
😢
<arg name="basepath" value="."/> | ||
<arg name="extensions" value="php"/> | ||
<arg name="colors" /> | ||
<arg value="p"/> |
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.
p
?
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.
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.
Comment plox
4fa08c1
to
b340846
Compare
$phpcsFile->addError('Missing space before the string concatenation operator ".".', $stackPtr, 'Before'); | ||
} | ||
do { | ||
--$colonPosition; |
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.
Ah, I see - you basically need that position to be set after the while
.
Is it possible that this block ever goes into an infinite loop? It looks like it, but the assumptions around its design are missing for me.
@@ -0,0 +1,33 @@ | |||
<?xml version="1.0"?> | |||
<ruleset name="Doctrine"> |
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.
😢
<arg name="basepath" value="."/> | ||
<arg name="extensions" value="php"/> | ||
<arg name="colors" /> | ||
<arg value="p"/> |
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.
Comment plox
Since we have a better option in PHPCS v3
We were missing the checks for: - Spaces before AND after not operator - Spaces before AND after return type declaration
So that our standard gets automatically registered to PHPCS.
That's easier than doing some workarounds on PHPUnit.
b340846
to
80deebe
Compare
Making sure we have all sniffs we use on doctrine projects.
Replaces #7