Skip to content

Commit de1fb57

Browse files
committed
Standardize code
1 parent 97b1137 commit de1fb57

File tree

170 files changed

+1563
-1795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1563
-1795
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
- Filesystem errors on some Windows environments when running coilpack install command
1111
- GraphQL fieldtype modifier registration bug
12+
- Use coding standard
1213

1314
## [0.0.1] - 2022-12-29
1415

src/Api/Graph/Fields/Fieldtype.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace Expressionengine\Coilpack\Api\Graph\Fields;
44

5-
use GraphQL\Type\Definition\Type;
6-
use Rebing\GraphQL\Support\Field;
75
use Expressionengine\Coilpack\Api\Graph\Support\FieldtypeRegistrar;
86
use Expressionengine\Coilpack\Models\FieldContent;
9-
use Rebing\GraphQL\Support\Facades\GraphQL;
7+
use GraphQL\Type\Definition\Type;
8+
use Rebing\GraphQL\Support\Field;
109

1110
class Fieldtype extends Field
1211
{
@@ -24,12 +23,13 @@ public function __construct(array $settings = [])
2423
public function setField($field)
2524
{
2625
$this->attributes['field'] = $field;
26+
2727
return $this;
2828
}
2929

3030
public function type(): Type
3131
{
32-
if($this->attributes['type'] ?? false) {
32+
if ($this->attributes['type'] ?? false) {
3333
return $this->attributes['type'];
3434
}
3535

@@ -40,9 +40,9 @@ public function type(): Type
4040

4141
protected function getFieldtype()
4242
{
43-
if($this->attributes['field'] ?? false) {
43+
if ($this->attributes['field'] ?? false) {
4444
return $this->attributes['field']->getFieldtype();
45-
}elseif($this->attributes['fieldtype'] ?? false) {
45+
} elseif ($this->attributes['fieldtype'] ?? false) {
4646
return $this->attributes['fieldtype'];
4747
}
4848

@@ -54,7 +54,7 @@ public function args(): array
5454
$fieldtype = $this->getFieldtype();
5555
$modifiers = ($fieldtype) ? $fieldtype->modifiers() : [];
5656

57-
$args = collect($modifiers)->transform(function($modifier) {
57+
$args = collect($modifiers)->transform(function ($modifier) {
5858
return $modifier->toGraphQL();
5959
});
6060

@@ -63,15 +63,15 @@ public function args(): array
6363

6464
protected function resolve($root, array $args)
6565
{
66-
if($this->attributes['resolve'] ?? false && is_callable($this->attributes['resolve'])) {
66+
if ($this->attributes['resolve'] ?? false && is_callable($this->attributes['resolve'])) {
6767
$data = $this->attributes['resolve']($root, $args);
6868
} else {
6969
$data = $root->{$this->getProperty()};
7070
}
7171

7272
// apply modifiers;
73-
if (!empty($args)) {
74-
foreach($args as $key => $value) {
73+
if (! empty($args)) {
74+
foreach ($args as $key => $value) {
7575
return $data->callModifier($key, $value);
7676
}
7777
}

src/Api/Graph/Fields/FormattableDate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function resolve($root, array $args): ?string
4040
{
4141
$date = $root->{$this->getProperty()};
4242

43-
if (!$date instanceof \Carbon\Carbon) {
43+
if (! $date instanceof \Carbon\Carbon) {
4444
return null;
4545
}
4646

@@ -55,4 +55,4 @@ protected function getProperty(): string
5555
{
5656
return $this->attributes['alias'] ?? $this->attributes['name'];
5757
}
58-
}
58+
}

src/Api/Graph/Queries/CategoriesQuery.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Expressionengine\Coilpack\Api\Graph\Queries;
44

5-
use GraphQL\Type\Definition\Type;
5+
use Expressionengine\Coilpack\Models\Category\Category;
66
use GraphQL\Type\Definition\ResolveInfo;
7-
use Rebing\GraphQL\Support\SelectFields;
7+
use GraphQL\Type\Definition\Type;
88
use Rebing\GraphQL\Support\Facades\GraphQL;
99
use Rebing\GraphQL\Support\Query;
10-
11-
use Expressionengine\Coilpack\Models\Category\Category;
10+
use Rebing\GraphQL\Support\SelectFields;
1211

1312
class CategoriesQuery extends Query
1413
{
@@ -25,14 +24,14 @@ public function args(): array
2524
{
2625
return [
2726
'channel' => [
28-
'type' => Type::string()
27+
'type' => Type::string(),
2928
],
3029
'status' => [
31-
'type' => Type::string()
30+
'type' => Type::string(),
3231
],
3332
'limit' => [
34-
'type' => Type::int()
35-
]
33+
'type' => Type::int(),
34+
],
3635

3736
];
3837
}

src/Api/Graph/Queries/ChannelEntriesQuery.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Expressionengine\Coilpack\Api\Graph\Queries;
44

5-
use GraphQL\Type\Definition\Type;
5+
use Expressionengine\Coilpack\Models\Channel\ChannelEntry;
66
use GraphQL\Type\Definition\ResolveInfo;
7-
use Rebing\GraphQL\Support\SelectFields;
7+
use GraphQL\Type\Definition\Type;
88
use Rebing\GraphQL\Support\Facades\GraphQL;
99
use Rebing\GraphQL\Support\Query;
10-
11-
use Expressionengine\Coilpack\Models\Channel\ChannelEntry;
10+
use Rebing\GraphQL\Support\SelectFields;
1211

1312
class ChannelEntriesQuery extends Query
1413
{
@@ -25,14 +24,14 @@ public function args(): array
2524
{
2625
return [
2726
'channel' => [
28-
'type' => Type::string()
27+
'type' => Type::string(),
2928
],
3029
'status' => [
31-
'type' => Type::string()
30+
'type' => Type::string(),
3231
],
3332
'limit' => [
34-
'type' => Type::int()
35-
]
33+
'type' => Type::int(),
34+
],
3635

3736
];
3837
}
@@ -47,8 +46,8 @@ public function resolve($root, array $args, $context, ResolveInfo $info, \Closur
4746
$entries = ChannelEntry::select($select)->with($with);
4847

4948
// Filter by Channel name
50-
$entries->when($args['channel'] ?? false, function($query) use($args) {
51-
$query->whereHas('channel', function($query) use($args) {
49+
$entries->when($args['channel'] ?? false, function ($query) use ($args) {
50+
$query->whereHas('channel', function ($query) use ($args) {
5251
$query->where('channel_name', $args['channel']);
5352
});
5453
});
@@ -64,5 +63,4 @@ public function resolve($root, array $args, $context, ResolveInfo $info, \Closur
6463

6564
return $entries->get();
6665
}
67-
6866
}

src/Api/Graph/Queries/ChannelEntryQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function args(): array
2424
'entry_id' => [
2525
'name' => 'entry_id',
2626
'type' => Type::int(),
27-
'rules' => ['required']
27+
'rules' => ['required'],
2828
],
2929
];
3030
}

src/Api/Graph/Queries/MemberCurrentQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function args(): array
2525

2626
public function resolve($root, $args)
2727
{
28-
$user = auth('coilpack')->user() ?: tap(new Member, function($member) {
28+
$user = auth('coilpack')->user() ?: tap(new Member, function ($member) {
2929
$member->screen_name = 'Guest';
3030
$member->member_id = null;
3131
});

src/Api/Graph/Queries/MembersQuery.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Expressionengine\Coilpack\Api\Graph\Queries;
44

5-
use Expressionengine\Coilpack\Models\Member\Member;
65
use GraphQL\Type\Definition\Type;
76
use Rebing\GraphQL\Support\Facades\GraphQL;
87
use Rebing\GraphQL\Support\Query;

src/Api/Graph/Queries/VariablesQuery.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Expressionengine\Coilpack\Api\Graph\Queries;
44

5-
use Expressionengine\Coilpack\Models\Channel\ChannelEntry;
65
use GraphQL\Type\Definition\Type;
76
use Rebing\GraphQL\Support\Facades\GraphQL;
87
use Rebing\GraphQL\Support\Query;
@@ -22,8 +21,8 @@ public function args(): array
2221
{
2322
return [
2423
'site' => [
25-
'type' => Type::int()
26-
]
24+
'type' => Type::int(),
25+
],
2726
];
2827
}
2928

src/Api/Graph/Support/FieldtypeRegistrar.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
namespace Expressionengine\Coilpack\Api\Graph\Support;
44

5-
use Expressionengine\Coilpack\Fieldtypes\Fieldtype;
6-
use Expressionengine\Coilpack\Models\Channel\ChannelField;
7-
use Expressionengine\Coilpack\FieldtypeManager;
85
use Expressionengine\Coilpack\Contracts\GeneratesGraphType;
96
use Expressionengine\Coilpack\Contracts\ListsGraphType;
7+
use Expressionengine\Coilpack\FieldtypeManager;
8+
use Expressionengine\Coilpack\Fieldtypes\Fieldtype;
109
use Expressionengine\Coilpack\Fieldtypes\Modifier;
11-
use Rebing\GraphQL\Support\Facades\GraphQL;
10+
use Expressionengine\Coilpack\Models\Channel\ChannelField;
1211
use GraphQL\Type\Definition\Type;
12+
use Rebing\GraphQL\Support\Facades\GraphQL;
1313

14-
class FieldtypeRegistrar {
15-
14+
class FieldtypeRegistrar
15+
{
1616
protected $types = [];
17+
1718
protected $inputs = [];
19+
1820
protected $booted = false;
1921

2022
public function __construct(FieldtypeManager $manager)
@@ -24,7 +26,7 @@ public function __construct(FieldtypeManager $manager)
2426

2527
public function boot()
2628
{
27-
if($this->booted) {
29+
if ($this->booted) {
2830
return;
2931
}
3032

@@ -56,10 +58,10 @@ public function registerFieldtypes()
5658
{
5759
$fieldtypes = $this->fieldtypeManager->allFieldtypes();
5860

59-
foreach($fieldtypes as $fieldtype) {
61+
foreach ($fieldtypes as $fieldtype) {
6062
$fieldtype = app(FieldtypeManager::class)->make($fieldtype->name);
6163
$this->registerFieldtype($fieldtype);
62-
foreach($fieldtype->modifiers() as $modifier) {
64+
foreach ($fieldtype->modifiers() as $modifier) {
6365
$this->registerModifier($modifier);
6466
}
6567
}
@@ -69,19 +71,19 @@ public function registerModifier(Modifier $modifier)
6971
{
7072
$name = $modifier->getQualifiedName();
7173

72-
if(array_key_exists($name, $this->inputs)) {
74+
if (array_key_exists($name, $this->inputs)) {
7375
return GraphQL::type($name);
7476
}
7577

76-
if(empty($modifier->parameters)) {
78+
if (empty($modifier->parameters)) {
7779
return null;
7880
}
7981

8082
$typeDefinition = new GeneratedInputType([
8183
'name' => $name,
8284
'fields' => function () use ($modifier) {
8385
return $modifier->parameters;
84-
}
86+
},
8587
]);
8688

8789
GraphQL::addType($typeDefinition, $name);
@@ -98,21 +100,21 @@ public function registerField(ChannelField $field)
98100
{
99101
$fieldtype = $field->getFieldType();
100102

101-
if($type = $this->registerFieldtype($fieldtype)) {
103+
if ($type = $this->registerFieldtype($fieldtype)) {
102104
return $type;
103105
}
104106

105-
if(array_key_exists($field->field_name, $this->types)) {
107+
if (array_key_exists($field->field_name, $this->types)) {
106108
return $this->types[$field->field_name];
107109
}
108110

109111
$name = "Field\\{$field->field_name}";
110112

111113
$typeDefinition = new GeneratedType([
112114
'name' => $name,
113-
'fields' => function() use($fieldtype, $field) {
115+
'fields' => function () use ($fieldtype, $field) {
114116
return $fieldtype->generateGraphType($field);
115-
}
117+
},
116118
]);
117119

118120
GraphQL::addType($typeDefinition, $name);
@@ -131,7 +133,7 @@ public function registerFieldtype(Fieldtype $fieldtype)
131133
return $this->types[$fieldtype->name];
132134
}
133135

134-
if(! $fieldtype instanceof GeneratesGraphType) {
136+
if (! $fieldtype instanceof GeneratesGraphType) {
135137
$type = $fieldtype->graphType();
136138
$this->types[$fieldtype->name] = $type;
137139

@@ -143,7 +145,7 @@ public function getTypeForField($field)
143145
{
144146
$type = $this->getType($field->field_name);
145147
$type = $type ?: $this->getType($field->field_type);
146-
if($type === null) {
148+
if ($type === null) {
147149
dd($field->field_name, $field->field_type, $field->getFieldType(), $this->types);
148150
}
149151

@@ -158,6 +160,7 @@ public function getType($field)
158160

159161
if (array_key_exists($field, $this->types)) {
160162
$type = $this->types[$field];
163+
161164
return (is_string($type)) ? GraphQL::type($type) : $this->types[$field];
162165
}
163166

@@ -173,6 +176,4 @@ public function dd()
173176
{
174177
dd($this->allTypes(), GraphQL::getTypes());
175178
}
176-
177-
178-
}
179+
}

0 commit comments

Comments
 (0)