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

Add phpcs to build and apply automatic fixes #1743

Merged
merged 6 commits into from
Mar 8, 2018
Merged

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Feb 9, 2018

Part of #1702. To help with reviews, this PR only applies automatic fixes and disables all other sniffs for later fixing.

Note: some tests fail, these will have to be fixed. Most of them are due to strict typing.

Note: if you want to expand all diffs by default (at your own risk), you can copy the following snippet into the dev console while on the "Files changed" tab:

document.querySelectorAll('.load-diff-button').forEach(item => item.click())

@alcaeus alcaeus added this to the 2.0.0 milestone Feb 9, 2018
@alcaeus alcaeus self-assigned this Feb 9, 2018
@alcaeus alcaeus added this to To Do in ODM 2.0 via automation Feb 9, 2018
@alcaeus alcaeus moved this from To Do to In progress in ODM 2.0 Feb 9, 2018
@@ -200,7 +205,7 @@ public function facet()
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/geoNear/
*
* @param float|array|Point $x
* @param float $y
* @param float $y
Copy link
Member

Choose a reason for hiding this comment

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

We have a rule to align params?

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently. Personally, I dislike it but I tried to not deviate too much from our official coding standard (except for space before colon because what kind of monster would want that?!?)

Copy link
Contributor

Choose a reason for hiding this comment

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

except for space before colon because what kind of monster would want that?!?

Me for example. 🐲

namespace Doctrine\ODM\MongoDB\Aggregation\Stage;

/**
* Fluent interface for adding a $addFields stage to an aggregation pipeline.
*
* @author Boris Guéry <guery.b@gmail.com>
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking, but empty line above should be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

@kukulich might know if that's easily added to the sniff in question - if not I'd leave it until the sniff can deal with it.

Copy link
Member

@malarzm malarzm Feb 9, 2018

Choose a reason for hiding this comment

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

It's not the only place, is there any way to configure CS fixer to disallow empty lines in comments when it's last line?

EDIT: or first line as well

Copy link

Choose a reason for hiding this comment

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

I'll improve/fix the fixer. I hope it will be done today in next bugfix version.

Copy link
Member Author

Choose a reason for hiding this comment

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

No rush - we'll have plenty more pull requests until we're done fixing phpcs in this project. Thank you for your help!

Copy link
Contributor

Choose a reason for hiding this comment

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

Have experienced that one in doctrine/doctrine2#7046 as well

Copy link

Choose a reason for hiding this comment

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

You can try dev-master of Slevomat CS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, been fixing these empty lines manually... :| You have it too easy @alcaeus. :P

Copy link
Contributor

Choose a reason for hiding this comment

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

@kukulich Btw same applies to TypeHintDeclaration sniff when @param/@return is removed. That really sounds like a candidate for DocCommentSpacingSniff? 😊

Copy link

Choose a reason for hiding this comment

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

Yes, new sniff is the best solution. It should be easy so maybe in the weekend or next week :)

* @param array $changeSet
*
* @param object $document
* @param array $changeSet
Copy link
Member

Choose a reason for hiding this comment

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

This is not treated as redundant with method definition?

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, seems to be a bug. I'll revisit those anyways when requiring 7.2 and introducing object typehint along with scalar typehints.

Copy link

Choose a reason for hiding this comment

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

object is not required because of enableObjectTypeHint option that is enabled by default only if you run phpcs on PHP 7.2+.

array is ok because there is <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" /> in phpcs.xml.

*
* @return void
Copy link
Member

Choose a reason for hiding this comment

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

This got removed even though there's no : void in the definition, is it desirable? I mean will some tool later infer that there's no return in the function so : void should be added?

Copy link
Member

@malarzm malarzm Feb 9, 2018

Choose a reason for hiding this comment

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

On the other hand next methods don't have @return void at all so I guess it's not a big deal

* @return MongoDBException
*/
public static function invalidValueForType($type, $expected, $got)
{
if (is_array($expected)) {
$expected = sprintf('%s or %s',
$expected = sprintf(
'%s or %s',
join(', ', array_slice($expected, 0, -1)),
Copy link
Member

Choose a reason for hiding this comment

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

Forbidden functions are not changed automatically or it's not that version of our CS yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't fix them automatically (it allows free configuration, so function signatures may vary), which is why it's not fixed in this PR.

new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document))
));
if (! empty($class->lifecycleCallbacks[Events::preUpdate])) {
$class->invokeLifecycleCallbacks(Events::preUpdate, $document, [new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document))]);
Copy link
Member

Choose a reason for hiding this comment

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

Are we ignoring line's length from now on?

Copy link
Member Author

Choose a reason for hiding this comment

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

PSR-2 does not include a hard limit. That said, I'm fine changing any lines you mark as "too long, could be split into multiples" 😛

Copy link
Member

Choose a reason for hiding this comment

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

No need, it just stood out, I don't mind scrolling sideways that much ;)

.travis.yml Outdated
script:
- vendor/bin/phpstan analyse -l 1 lib

- stage: Code Quality
php: 7.2
Copy link
Contributor

@Majkl578 Majkl578 Feb 19, 2018

Choose a reason for hiding this comment

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

This should be 7.1 since 7.1 is required in composer, otherwise you may end up with object typehint.

@alcaeus alcaeus force-pushed the phpcs branch 3 times, most recently from ff0d2c4 to 60e293e Compare March 2, 2018 19:01
@carusogabriel
Copy link
Contributor

@alcaeus I believe 60e293e can be surpassed by Doctrine CS v4 now :)

@alcaeus
Copy link
Member Author

alcaeus commented Mar 5, 2018

Yeah, have to catch up with the times...we're running an antique version of our coding-standard here 😉

@alcaeus alcaeus force-pushed the phpcs branch 2 times, most recently from aee5bea to e8fafce Compare March 8, 2018 18:41
@malarzm malarzm merged commit 04938ee into doctrine:master Mar 8, 2018
ODM 2.0 automation moved this from In progress to Done Mar 8, 2018
@carusogabriel
Copy link
Contributor

@alcaeus @malarzm May I update to CS v4?

@alcaeus alcaeus deleted the phpcs branch March 8, 2018 19:39
@alcaeus
Copy link
Member Author

alcaeus commented Mar 8, 2018

Damn, I thought I had that in there as well. Yes, feel free to do so.

@alcaeus alcaeus mentioned this pull request Mar 9, 2018
@alcaeus alcaeus added the Task label Dec 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
ODM 2.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants