-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Switch from StyleCI to PHP-CS fixer #502
Conversation
Done, pushed a commit! I just use env variables for this and we just need to make sure that at least for one job it's set. Same approach used for e.g. phpstan. I also fixed the failing lumen integration test. I boy I hate them, but it's better then nothing. They rely on scripting the manual steps necessary and easily fail due to the sensitivity of the regex when the source file changes even formatting (which happened in this case for I also took the liberty to simply remove the extended tests from 5.8; it's EOL anyway and only wil receive security fixes which shouldn't be critical for the extended test.
Only admins can do that (which I'm not). But before proceeding I would like to do some testing/feedbacking |
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.
Thanks for the initiative, that's really great; love it so far!
I think the hard part is now on agreeing on the actual config, see my inline thoughts on some of this.
My perfect outcome would be the most minimal configuration with the most aggressive approach so that no room for interpretation is left.
(ps: noticed that PhpStorm detects php-cs fixer and can auto correct it: how awesome is that)
.php_cs.dist
Outdated
<?php | ||
|
||
/** | ||
* Rules we follow are from PSR-2 as well as the rectified PSR-2 guide. |
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 blueprint where you got this whole fle from?
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.
.php_cs.dist
Outdated
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@PSR2' => 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.
So. I was wondering since it said @PSR2
at the top, why the other rules?
I removed them all and ran fix
and it did quite some changes, like these:
diff --git a/src/GraphQL.php b/src/GraphQL.php
index c5d3b0d..9562554 100644
--- a/src/GraphQL.php
+++ b/src/GraphQL.php
@@ -239,10 +239,12 @@ class GraphQL
if (! $type instanceof TypeConvertible) {
throw new TypeNotFound(
- sprintf('Unable to convert %s to a GraphQL type, please add/implement the interface %s',
+ sprintf(
+ 'Unable to convert %s to a GraphQL type, please add/implement the interface %s',
get_class($type),
TypeConvertible::class
- ));
+ )
+ );
}
foreach ($opts as $key => $value) {
diff --git a/src/Support/ResolveInfoFieldsAndArguments.php b/src/Support/ResolveInfoFieldsAndArguments.php
index 34aceea..bed6194 100644
--- a/src/Support/ResolveInfoFieldsAndArguments.php
+++ b/src/Support/ResolveInfoFieldsAndArguments.php
@@ -130,12 +130,16 @@ class ResolveInfoFieldsAndArguments
$spreadName = $selectionNode->name->value;
if (isset($this->info->fragments[$spreadName])) {
$fragment = $this->info->fragments[$spreadName];
- $fields = array_merge_recursive($this->foldSelectionSet($fragment->selectionSet, $descend),
- $fields);
+ $fields = array_merge_recursive(
+ $this->foldSelectionSet($fragment->selectionSet, $descend),
+ $fields
+ );
}
} elseif ($selectionNode instanceof InlineFragmentNode) {
- $fields = array_merge_recursive($this->foldSelectionSet($selectionNode->selectionSet, $descend),
- $fields);
+ $fields = array_merge_recursive(
+ $this->foldSelectionSet($selectionNode->selectionSet, $descend),
+ $fields
+ );
}
}
or
diff --git a/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php b/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
index 82a2932..e1a7581 100644
--- a/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
+++ b/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
@@ -36,7 +36,8 @@ GRAPHQL;
],
]);
- $this->assertSqlQueries(<<<'SQL'
+ $this->assertSqlQueries(
+ <<<'SQL'
Basically it felt more aggressive.
I liked that because for example, in the current version these two patterns are allowed:
$this->assertSqlQueries(
<<<'SQL'
and
$this->assertSqlQueries(<<<'SQL'
Nether one is touched and converted to the other.
Yet when I remove all the settings, it's converted the former form always.
I think this is better, the source will be more unified and leaves less room for interpretation.
.php_cs.dist
Outdated
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@PSR2' => true, | ||
'array_syntax' => [ 'syntax' => 'short' ], |
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.
Immediately noticed though, per my above comment, removing this one here means it will not enforce $foo = array();
being converted to $foo = [];
So I guess just @PSR2
isn't specific enough and still has room for interpretation.
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.
yeah @psr2 is not enough to get the "prettiest" formatting:-)
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've found https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 and applied and pushed the changes for review.
Not sold yet on the config though :)
I wish there was a better way then copypasting some gist around; maybe there is a package with a maintained "Laravel" compatible PHP-CS fixer config we could just be pulled it as a dev dependency?
@@ -259,7 +259,7 @@ public function __get($key) | |||
{ | |||
$attributes = $this->getAttributes(); | |||
|
|||
return isset($attributes[$key]) ? $attributes[$key] : null; | |||
return $attributes[$key] ?? null; |
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.
Now this is really nice
} | ||
|
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.
Oh my 🤔
Maybe this? https://github.com/matt-allan/laravel-code-style
|
I pushed some updates:
|
f88223b
to
9797ca6
Compare
Also added a PR template which mentions how to fix the code style |
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.
Thanks @crissi , that's some great contribution here: I'm a sucker for code style standardization 😄
From my side this is 👍 good to go and now we need to remove StyleCI
@rebing TL;DR: we propose to switch from StyleCI to PHP-CS fixer which is fully integrated in the pipeline and has the benefit that contributors can fix code style violations locally. If that's good with you, could you please remove the StyleCI integration completely here? 🙏
+1 for this ! Being able to fix everything locally is awesome. It would be great being able to do the same thing for travis, but I can imagine what a mess it could be. |
I've added a small fix in here: crissi#9 |
Thanks, already cherry-picked plus some other fixes! |
So I gues we just need to fix to make it pass the styleci check and then after this PR is merged the styleci is gone? |
…ha sorted imports
Otherwise composer can't install the dependencies correctly because this package has higher version constraints.
Primarily for a way to signal devs how to fix the code style, which the linter might error out on.
e9bc260
to
0d6320c
Compare
@rebing can you also please remove StyleCI? Thanks 🤗 |
now developers can run composer fix to fix styling issues and more easily set up their IDE because we are using phpcsfixer
and travis will fail and show the error diff from php-cs-fixer
TODOs
Links