Skip to content

Commit 20b47b7

Browse files
author
Jeremiah VALERIE
committed
Fix input and args defaultValue
`defaultValue` should be set only if value different than null
1 parent 05df8b0 commit 20b47b7

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ enabled:
55

66
disabled:
77
- unalign_equals
8+
- psr0

src/Generator/AbstractTypeGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ protected function varExport($var, $default = null, array $compilerNames = [])
153153
if (count($lines) > 1) {
154154
$firstLine = array_shift($lines) . "'" . ' . "\n"';
155155
$lastLine = "'" . array_pop($lines);
156-
$lines = array_map(function($s) { return "'" . $s . "'" . ' . "\n"'; }, $lines);
156+
$lines = array_map(function ($s) {
157+
return "'" . $s . "'" . ' . "\n"';
158+
}, $lines);
157159
array_unshift($lines, $firstLine);
158160
array_push($lines, $lastLine);
159-
$string = implode(" . \n", $lines);
161+
$string = implode(" . ", $lines);
160162
}
161163

162164
return $string;

src/Generator/TypeGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ protected function generateDeprecationReason(array $value)
5555

5656
protected function generateDefaultValue(array $value)
5757
{
58-
return $this->varExportFromArrayValue($value, 'defaultValue');
58+
$defaultValue = $this->varExportFromArrayValue($value, 'defaultValue');
59+
if ('null' === $defaultValue) {
60+
return '';
61+
}
62+
63+
return "\n".'<spaces>\'defaultValue\' => '.$defaultValue.',';
5964
}
6065

6166
protected function generateType(array $value)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
<spaces>'name' => <name>,
33
<spaces>'type' => <type>,
4-
<spaces>'description' => <description>,
5-
<spaces>'defaultValue' => <defaultValue>,
4+
<spaces>'description' => <description>,<defaultValue>
65
],
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<name> => [
22
<spaces>'type' => <type>,
3-
<spaces>'defaultValue' => <defaultValue>,
4-
<spaces>'description' => <description>,
3+
<spaces>'description' => <description>,<defaultValue>
54
],

tests/StarWarsIntrospectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function testAllowsQueryingTheSchemaForFieldArgs()
311311
'name' => 'hero',
312312
'args' => [
313313
[
314-
'defaultValue' => 'null',
314+
'defaultValue' => null,
315315
'description' => "If omitted, returns the hero of the whole saga.\nIf provided, returns the hero of that particular episode.\n",
316316
'name' => 'episode',
317317
'type' => [
@@ -370,7 +370,7 @@ public function testAllowsQueryingTheSchemaForFieldArgs()
370370
'kind' => 'SCALAR',
371371
'ofType' => null,
372372
],
373-
'defaultValue' => 'null',
373+
'defaultValue' => null,
374374
]
375375
],
376376
],

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function assertCodeStandard($pathToCode, $level = null, $fixers = null)
1919
{
2020
// Run linter in dry-run mode so it changes nothing.
2121
$csBuilder = new ProcessBuilder([
22-
'php-cs-fixer',
22+
__DIR__ . '/../bin/php-cs-fixer',
2323
'fix',
2424
'--dry-run',
2525
'--diff',

0 commit comments

Comments
 (0)