Skip to content

Commit 05df8b0

Browse files
authored
Merge pull request #12 from jane-olszewska/remove-extra-spaces-description
Fix extra spaces inserted into multi-line strings
2 parents d635ded + a2df905 commit 05df8b0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/Generator/AbstractTypeGenerator.php

+16
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ protected function varExport($var, $default = null, array $compilerNames = [])
145145
case is_object($var):
146146
return $default;
147147

148+
case is_string($var):
149+
$string = var_export($var, true);
150+
151+
// handle multi-line strings
152+
$lines = explode("\n", $string);
153+
if (count($lines) > 1) {
154+
$firstLine = array_shift($lines) . "'" . ' . "\n"';
155+
$lastLine = "'" . array_pop($lines);
156+
$lines = array_map(function($s) { return "'" . $s . "'" . ' . "\n"'; }, $lines);
157+
array_unshift($lines, $firstLine);
158+
array_push($lines, $lastLine);
159+
$string = implode(" . \n", $lines);
160+
}
161+
162+
return $string;
163+
148164
default:
149165
return var_export($var, true);
150166
}

tests/StarWarsIntrospectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function testAllowsQueryingTheSchemaForFieldArgs()
312312
'args' => [
313313
[
314314
'defaultValue' => 'null',
315-
'description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.',
315+
'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' => [
318318
'kind' => 'ENUM',

tests/starWarsSchema.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ Query:
143143
args:
144144
episode:
145145
type: "Episode"
146-
description: "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
146+
description: |
147+
If omitted, returns the hero of the whole saga.
148+
If provided, returns the hero of that particular episode.
147149
resolve: ["Overblog\\GraphQLGenerator\\Tests\\Resolver", "getHero"]
148150
human:
149151
type: "Human"

0 commit comments

Comments
 (0)