Skip to content

Commit ad7a935

Browse files
authored
Merge pull request #555 from mfn/mfn-php-cs
[PHPCS] Tune configuration
2 parents fc58f01 + 7a0367a commit ad7a935

File tree

29 files changed

+242
-111
lines changed

29 files changed

+242
-111
lines changed

.php_cs.dist

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ return (new MattAllan\LaravelCodeStyle\Config())
77
->setRules([
88
'@Laravel' => true,
99
'@Laravel:risky' => true,
10+
// Project specific
11+
'array_indentation' => true,
12+
'declare_strict_types' => true,
13+
'is_null' => true,
14+
'modernize_types_casting' => true,
15+
'method_argument_space' => [
16+
'on_multiline' => 'ensure_fully_multiline',
17+
],
1018
])
11-
->setRiskyAllowed(true);
19+
->setRiskyAllowed(true);

src/GraphQL.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,12 @@ protected function buildObjectTypeFromClass($type, array $opts = []): Type
239239

240240
if (! $type instanceof TypeConvertible) {
241241
throw new TypeNotFound(
242-
sprintf('Unable to convert %s to a GraphQL type, please add/implement the interface %s',
242+
sprintf(
243+
'Unable to convert %s to a GraphQL type, please add/implement the interface %s',
243244
get_class($type),
244245
TypeConvertible::class
245-
));
246+
)
247+
);
246248
}
247249

248250
foreach ($opts as $key => $value) {

src/Support/ResolveInfoFieldsAndArguments.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ private function foldSelectionSet(SelectionSetNode $selectionSet, int $descend):
130130
$spreadName = $selectionNode->name->value;
131131
if (isset($this->info->fragments[$spreadName])) {
132132
$fragment = $this->info->fragments[$spreadName];
133-
$fields = (array) array_replace_recursive($this->foldSelectionSet($fragment->selectionSet, $descend),
134-
$fields);
133+
$fields = (array) array_replace_recursive(
134+
$this->foldSelectionSet($fragment->selectionSet, $descend),
135+
$fields
136+
);
135137
}
136138
} elseif ($selectionNode instanceof InlineFragmentNode) {
137-
$fields = (array) array_replace_recursive($this->foldSelectionSet($selectionNode->selectionSet, $descend),
138-
$fields);
139+
$fields = (array) array_replace_recursive(
140+
$this->foldSelectionSet($selectionNode->selectionSet, $descend),
141+
$fields
142+
);
139143
}
140144
}
141145

src/Support/SelectFields.php

+46-13
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,14 @@ protected static function handleFields(
190190
if (is_a($parentType, config('graphql.pagination_type', PaginationType::class))) {
191191
/* @var GraphqlType $fieldType */
192192
$fieldType = $fieldObject->config['type'];
193-
self::handleFields($queryArgs, $field, $fieldType->getWrappedType(), $select,
194-
$with, $ctx);
193+
self::handleFields(
194+
$queryArgs,
195+
$field,
196+
$fieldType->getWrappedType(),
197+
$select,
198+
$with,
199+
$ctx
200+
);
195201
}
196202
// With
197203
elseif (is_array($field['fields']) && $queryable) {
@@ -208,11 +214,26 @@ protected static function handleFields(
208214

209215
self::addAlwaysFields($fieldObject, $field, $parentTable, true);
210216

211-
$with[$relationsKey] = self::getSelectableFieldsAndRelations($queryArgs, $field, $newParentType,
212-
$customQuery, false, $ctx);
217+
$with[$relationsKey] = self::getSelectableFieldsAndRelations(
218+
$queryArgs,
219+
$field,
220+
$newParentType,
221+
$customQuery,
222+
false,
223+
$ctx
224+
);
213225
} elseif (is_a($parentTypeUnwrapped, \GraphQL\Type\Definition\InterfaceType::class)) {
214-
self::handleInterfaceFields($queryArgs, $field, $parentTypeUnwrapped, $select, $with, $ctx,
215-
$fieldObject, $key, $customQuery);
226+
self::handleInterfaceFields(
227+
$queryArgs,
228+
$field,
229+
$parentTypeUnwrapped,
230+
$select,
231+
$with,
232+
$ctx,
233+
$fieldObject,
234+
$key,
235+
$customQuery
236+
);
216237
} else {
217238
self::handleFields($queryArgs, $field, $fieldObject->config['type'], $select, $with, $ctx);
218239
}
@@ -361,8 +382,11 @@ private static function handleRelation(array &$select, $relation, ?string $paren
361382
} else {
362383
$foreignKey = $relation->getQualifiedForeignKeyName();
363384
}
364-
$foreignKey = $parentTable ? ($parentTable.'.'.preg_replace('/^'.preg_quote($parentTable, '/').'\./',
365-
'', $foreignKey)) : $foreignKey;
385+
$foreignKey = $parentTable ? ($parentTable.'.'.preg_replace(
386+
'/^'.preg_quote($parentTable, '/').'\./',
387+
'',
388+
$foreignKey
389+
)) : $foreignKey;
366390
if (is_a($relation, MorphTo::class)) {
367391
$foreignKeyType = $relation->getMorphType();
368392
$foreignKeyType = $parentTable ? ($parentTable.'.'.$foreignKeyType) : $foreignKeyType;
@@ -377,8 +401,10 @@ private static function handleRelation(array &$select, $relation, ?string $paren
377401
$select[] = $foreignKey;
378402
}
379403
} // If 'HasMany', then add it in the 'with'
380-
elseif ((is_a($relation, HasMany::class) || is_a($relation, MorphMany::class) || is_a($relation,
381-
HasOne::class) || is_a($relation, MorphOne::class))
404+
elseif ((is_a($relation, HasMany::class) || is_a($relation, MorphMany::class) || is_a(
405+
$relation,
406+
HasOne::class
407+
) || is_a($relation, MorphOne::class))
382408
&& ! array_key_exists($foreignKey, $field)) {
383409
$segments = explode('.', $foreignKey);
384410
$foreignKey = end($segments);
@@ -478,7 +504,8 @@ protected static function handleInterfaceFields(
478504
function (GraphqlType $type) use ($query) {
479505
/* @var Relation $query */
480506
return app($type->config['model'])->getTable() === $query->getParent()->getTable();
481-
});
507+
}
508+
);
482509
$typesFiltered = array_values($typesFiltered ?? []);
483510

484511
if (count($typesFiltered) === 1) {
@@ -496,8 +523,14 @@ function (GraphqlType $type) use ($query) {
496523
}
497524

498525
/** @var callable $callable */
499-
$callable = self::getSelectableFieldsAndRelations($queryArgs, $field, $newParentType, $customQuery,
500-
false, $ctx);
526+
$callable = self::getSelectableFieldsAndRelations(
527+
$queryArgs,
528+
$field,
529+
$newParentType,
530+
$customQuery,
531+
false,
532+
$ctx
533+
);
501534

502535
return $callable($query);
503536
};

tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public function testUniquePassRulePass(): void
3636
],
3737
]);
3838

39-
$this->assertSqlQueries(<<<'SQL'
39+
$this->assertSqlQueries(
40+
<<<'SQL'
4041
select count(*) as aggregate from "users" where "name" = ?;
4142
SQL
4243
);
@@ -72,7 +73,8 @@ public function testUniqueFailRulePass(): void
7273
],
7374
]);
7475

75-
$this->assertSqlQueries(<<<'SQL'
76+
$this->assertSqlQueries(
77+
<<<'SQL'
7678
select count(*) as aggregate from "users" where "name" = ?;
7779
SQL
7880
);
@@ -143,7 +145,8 @@ public function testUniqueFailRuleFail(): void
143145
],
144146
]);
145147

146-
$this->assertSqlQueries(<<<'SQL'
148+
$this->assertSqlQueries(
149+
<<<'SQL'
147150
select count(*) as aggregate from "users" where "name" = ?;
148151
SQL
149152
);

tests/Database/SelectFields/AlwaysRelationTests/AlwaysRelationTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public function testAlwaysSingleHasManyRelationField(): void
5151
'expectErrors' => true,
5252
]);
5353

54-
$this->assertSqlQueries(<<<'SQL'
54+
$this->assertSqlQueries(
55+
<<<'SQL'
5556
select "users"."id" from "users";
5657
SQL
5758
);
@@ -134,7 +135,8 @@ public function testAlwaysSingleMorphRelationField(): void
134135
'expectErrors' => true,
135136
]);
136137

137-
$this->assertSqlQueries(<<<'SQL'
138+
$this->assertSqlQueries(
139+
<<<'SQL'
138140
select "users"."name", "users"."id" from "users";
139141
SQL
140142
);

tests/Database/SelectFields/AlwaysTests/AlwaysTest.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function testAlwaysSingleField(): void
4444

4545
$result = $this->graphql($query);
4646

47-
$this->assertSqlQueries(<<<'SQL'
47+
$this->assertSqlQueries(
48+
<<<'SQL'
4849
select "posts"."body", "posts"."title", "posts"."id" from "posts";
4950
select "comments"."id", "comments"."post_id", "comments"."body" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
5051
SQL
@@ -99,7 +100,8 @@ public function testAlwaysSingleMultipleFieldInString(): void
99100

100101
$result = $this->graphql($query);
101102

102-
$this->assertSqlQueries(<<<'SQL'
103+
$this->assertSqlQueries(
104+
<<<'SQL'
103105
select "posts"."body", "posts"."title", "posts"."id" from "posts";
104106
select "comments"."id", "comments"."post_id", "comments"."body", "comments"."title" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
105107
SQL
@@ -154,7 +156,8 @@ public function testAlwaysSingleMultipleFieldInArray(): void
154156

155157
$result = $this->graphql($query);
156158

157-
$this->assertSqlQueries(<<<'SQL'
159+
$this->assertSqlQueries(
160+
<<<'SQL'
158161
select "posts"."body", "posts"."title", "posts"."id" from "posts";
159162
select "comments"."id", "comments"."post_id", "comments"."body", "comments"."title" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
160163
SQL
@@ -209,7 +212,8 @@ public function testAlwaysSameFieldTwice(): void
209212

210213
$result = $this->graphql($query);
211214

212-
$this->assertSqlQueries(<<<'SQL'
215+
$this->assertSqlQueries(
216+
<<<'SQL'
213217
select "posts"."body", "posts"."title", "posts"."id" from "posts";
214218
select "comments"."id", "comments"."post_id", "comments"."body" from "comments" where "comments"."post_id" in (?) order by "comments"."id" asc;
215219
SQL

tests/Database/SelectFields/ArrayTests/ArrayTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rebing\GraphQL\Tests\Database\SelectFields\ArrayTests;
46

57
use Rebing\GraphQL\Tests\Support\Models\Post;

tests/Database/SelectFields/ComputedPropertiesTests/ComputedPropertiesTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function testComputedProperty(): void
4242

4343
$result = $this->graphql($query);
4444

45-
$this->assertSqlQueries(<<<'SQL'
45+
$this->assertSqlQueries(
46+
<<<'SQL'
4647
select "users"."id", "users"."name" from "users";
4748
select "posts"."id", "posts"."published_at", "posts"."user_id" from "posts" where "posts"."user_id" in (?) order by "posts"."id" asc;
4849
SQL

tests/Database/SelectFields/DepthTests/DepthTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public function testDefaultDepthAdjusted(): void
9696

9797
$result = $this->graphql($graphql);
9898

99-
$this->assertSqlQueries(<<<'SQL'
99+
$this->assertSqlQueries(
100+
<<<'SQL'
100101
select "users"."id" from "users";
101102
select "posts"."id", "posts"."user_id" from "posts" where "posts"."user_id" in (?) order by "posts"."id" asc;
102103
select "users"."id" from "users" where "users"."id" in (?);

tests/Database/SelectFields/InterfaceTests/InterfaceTest.php

+16-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function testGeneratedSqlQuery(): void
3434

3535
$result = $this->graphql($graphql);
3636

37-
$this->assertSqlQueries(<<<'SQL'
37+
$this->assertSqlQueries(
38+
<<<'SQL'
3839
select "title" from "posts";
3940
SQL
4041
);
@@ -79,7 +80,8 @@ public function testGeneratedRelationSqlQuery(): void
7980

8081
$result = $this->graphql($graphql);
8182

82-
$this->assertSqlQueries(<<<'SQL'
83+
$this->assertSqlQueries(
84+
<<<'SQL'
8385
select "id", "title" from "posts";
8486
select "comments"."title", "comments"."post_id", "comments"."id" from "comments" where "comments"."post_id" in (?) and "id" >= ? order by "comments"."id" asc;
8587
SQL
@@ -141,14 +143,16 @@ public function testGeneratedInterfaceFieldSqlQuery(): void
141143
$result = $this->graphql($graphql);
142144

143145
if (Application::VERSION < '5.6') {
144-
$this->assertSqlQueries(<<<'SQL'
146+
$this->assertSqlQueries(
147+
<<<'SQL'
145148
select "users"."id" from "users";
146149
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?);
147150
select * from "posts" where "posts"."id" in (?);
148151
SQL
149152
);
150153
} else {
151-
$this->assertSqlQueries(<<<'SQL'
154+
$this->assertSqlQueries(
155+
<<<'SQL'
152156
select "users"."id" from "users";
153157
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?);
154158
select "id", "title" from "posts" where "posts"."id" in (?);
@@ -223,15 +227,17 @@ public function testGeneratedInterfaceFieldWithRelationSqlQuery(): void
223227
$result = $this->graphql($graphql);
224228

225229
if (Application::VERSION < '5.6') {
226-
$this->assertSqlQueries(<<<'SQL'
230+
$this->assertSqlQueries(
231+
<<<'SQL'
227232
select "users"."id" from "users";
228233
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
229234
select * from "posts" where "posts"."id" in (?);
230235
select "likes"."id", "likes"."likable_id", "likes"."likable_type" from "likes" where "likes"."likable_id" in (?) and "likes"."likable_type" = ? and 0=0;
231236
SQL
232237
);
233238
} else {
234-
$this->assertSqlQueries(<<<'SQL'
239+
$this->assertSqlQueries(
240+
<<<'SQL'
235241
select "users"."id" from "users";
236242
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
237243
select "id", "title" from "posts" where "posts"."id" in (?);
@@ -334,15 +340,17 @@ public function testGeneratedInterfaceFieldWithRelationAndCustomQueryOnInterface
334340
$result = $this->graphql($graphql);
335341

336342
if (Application::VERSION < '5.6') {
337-
$this->assertSqlQueries(<<<'SQL'
343+
$this->assertSqlQueries(
344+
<<<'SQL'
338345
select "users"."id" from "users";
339346
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
340347
select * from "comments" where "comments"."id" in (?);
341348
select "likes"."id", "likes"."likable_id", "likes"."likable_type" from "likes" where "likes"."likable_id" in (?) and "likes"."likable_type" = ? and 1=1;
342349
SQL
343350
);
344351
} else {
345-
$this->assertSqlQueries(<<<'SQL'
352+
$this->assertSqlQueries(
353+
<<<'SQL'
346354
select "users"."id" from "users";
347355
select "likes"."likable_id", "likes"."likable_type", "likes"."user_id", "likes"."id" from "likes" where "likes"."user_id" in (?, ?);
348356
select "id", "title" from "comments" where "comments"."id" in (?);

tests/Database/SelectFields/InterfaceTests/PostType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function fields(): array
2121
{
2222
$interface = GraphQL::type('LikableInterface');
2323

24-
return [
24+
return
25+
[
2526
'likes' => [
2627
'type' => Type::listOf(GraphQL::type('Like')),
2728
'query' => function (array $args, MorphMany $query) {

0 commit comments

Comments
 (0)