Skip to content

Conversation

lcobucci
Copy link
Member

@lcobucci lcobucci commented Aug 19, 2017

Making sure we have all sniffs we use on doctrine projects.

Replaces #7

@lcobucci lcobucci self-assigned this Aug 19, 2017
@lcobucci lcobucci requested a review from Ocramius August 19, 2017 23:32
@lcobucci lcobucci force-pushed the upgrade-dependencies branch from 07068be to 4fa08c1 Compare August 19, 2017 23:33
@lcobucci
Copy link
Member Author

Still need to update documentation, sure...

php:
- 7.1
- 7.2
- nightly
Copy link
Member

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"
Copy link
Member

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...

Copy link
Member Author

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,
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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(
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

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];
Copy link
Member

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;
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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">
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope 😞

Copy link
Member

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"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment plox

@lcobucci lcobucci force-pushed the upgrade-dependencies branch from 4fa08c1 to b340846 Compare August 20, 2017 00:12
@lcobucci lcobucci requested a review from Ocramius August 20, 2017 00:15
$phpcsFile->addError('Missing space before the string concatenation operator ".".', $stackPtr, 'Before');
}
do {
--$colonPosition;
Copy link
Member

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">
Copy link
Member

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"/>
Copy link
Member

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.
@lcobucci lcobucci force-pushed the upgrade-dependencies branch from b340846 to 80deebe Compare August 20, 2017 00:23
@lcobucci lcobucci requested a review from Ocramius August 20, 2017 00:47
@Ocramius Ocramius added this to the 1.0.0 milestone Aug 20, 2017
@Ocramius Ocramius merged commit 50ef313 into master Aug 20, 2017
@Ocramius Ocramius deleted the upgrade-dependencies branch August 20, 2017 00:50
@lcobucci lcobucci changed the title Upgrade dependencies (PHPCS v3) Implement missing sniffs (upgrading to PHPCS v3) Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants