Skip to content

Commit 6c9f01d

Browse files
authored
backport change (#61)
* backport change * fix obsolete test (only 3.x) * fix cs
1 parent e272c9d commit 6c9f01d

13 files changed

+31
-17
lines changed

src/Generator/SchemaGenerator.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
final class SchemaGenerator implements SchemaGeneratorInterface
1313
{
14-
1514
/**
1615
* @var int[]
1716
*/
@@ -89,7 +88,7 @@ public function generate(): array
8988
$schema['fields'][] = $field;
9089
}
9190

92-
$schemas[$schema['namespace'] . '.' . $schema['name']] = json_encode($schema);
91+
$schemas[$schema['namespace'] . '.' . $schema['name']] = json_encode($schema, JSON_PRESERVE_ZERO_FRACTION);
9392
}
9493

9594
return $schemas;

src/Merger/SchemaMerger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function exportSchema(
176176
}
177177

178178
/** @var string $fileContents */
179-
$fileContents = json_encode($rootSchemaDefinition);
179+
$fileContents = json_encode($rootSchemaDefinition, JSON_PRESERVE_ZERO_FRACTION);
180180

181181
file_put_contents($this->getOutputDirectory() . '/' . $schemaFilename, $fileContents);
182182
}

src/Merger/SchemaMergerInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
interface SchemaMergerInterface
1212
{
13-
1413
/**
1514
* @return SchemaRegistryInterface
1615
*/

src/Optimizer/FieldOrderOptimizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function optimize(string $definition): string
1717

1818
$data = $this->processSchema($data);
1919

20-
return json_encode($data, JSON_THROW_ON_ERROR);
20+
return json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
2121
}
2222

2323
/**

src/Optimizer/FullNameOptimizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function optimize(string $definition): string
1818
$currentNamespace = $data['namespace'] ?? '';
1919
$data = $this->processSchema($currentNamespace, $data, true);
2020

21-
return json_encode($data, JSON_THROW_ON_ERROR);
21+
return json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
2222
}
2323

2424
/**

src/Optimizer/PrimitiveSchemaOptimizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function optimize(string $definition, bool $isPrimitive = false): string
2222

2323
$data = $this->processSchema($data);
2424

25-
return json_encode($data, JSON_THROW_ON_ERROR);
25+
return json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
2626
}
2727

2828
/**

src/PhpClass/PhpClassProperty.php

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class PhpClassProperty implements PhpClassPropertyInterface
88
{
9-
109
/**
1110
* @var string
1211
*/

src/Registry/ClassRegistry.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
final class ClassRegistry implements ClassRegistryInterface
1616
{
17-
1817
/**
1918
* @var array<string,int>
2019
*/

src/Registry/ClassRegistryInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
interface ClassRegistryInterface
1010
{
11-
1211
/**
1312
* @param string $classDirectory
1413
* @return ClassRegistryInterface

src/Registry/SchemaRegistry.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ private function registerSchemaFile(\SplFileInfo $fileInfo): void
135135
}
136136

137137
$schemaData = json_decode($fileContent, true, JSON_THROW_ON_ERROR);
138-
$namespace = '';
138+
$namespace = '';
139139

140-
if (true === isset($schemaData['namespace'])) {
141-
$namespace = $schemaData['namespace'];
142-
}
140+
if (true === isset($schemaData['namespace'])) {
141+
$namespace = $schemaData['namespace'];
142+
}
143143

144144
if (null === $schemaData) {
145145
throw new SchemaRegistryException(sprintf(SchemaRegistryException::FILE_INVALID, $fileName));

src/Registry/SchemaRegistryInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
interface SchemaRegistryInterface
1010
{
11-
1211
/**
1312
* @param string $schemaTemplateDirectory
1413
* @return SchemaRegistryInterface

tests/Unit/Optimizer/FieldOrderOptimizerTest.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function testOptimize(): void
5151
"type": "array",
5252
"items": ["null", "com.example.Page"]
5353
},
54+
{
55+
"name": "price",
56+
"type": "float",
57+
"default": 99.0
58+
},
5459
{
5560
"name": "defaultFont",
5661
"type": "com.example.Font"
@@ -147,6 +152,11 @@ public function testOptimize(): void
147152
"type": "array",
148153
"items": ["null", "com.example.Page"]
149154
},
155+
{
156+
"name": "price",
157+
"type": "float",
158+
"default": 99.0
159+
},
150160
{
151161
"name": "defaultFont",
152162
"type": "com.example.Font"
@@ -201,7 +211,7 @@ public function testOptimize(): void
201211
]
202212
}
203213
]
204-
}'));
214+
}'), JSON_PRESERVE_ZERO_FRACTION);
205215

206216
$optimizer = new FieldOrderOptimizer();
207217

tests/Unit/Optimizer/FullNameOptimizerTest.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function testOptimize(): void
5151
"type": "array",
5252
"items": ["null","com.example.Page"]
5353
},
54+
{
55+
"name": "price",
56+
"type": "float",
57+
"default": 99.0
58+
},
5459
{
5560
"name": "appendix",
5661
"type": "array",
@@ -125,6 +130,11 @@ public function testOptimize(): void
125130
"type": "array",
126131
"items": ["null","Page"]
127132
},
133+
{
134+
"name": "price",
135+
"type": "float",
136+
"default": 99.0
137+
},
128138
{
129139
"name": "appendix",
130140
"type": "array",
@@ -158,7 +168,7 @@ public function testOptimize(): void
158168
},
159169
{ "name": "backSide", "type": "com.example.other.Cover"}
160170
]
161-
}'));
171+
}'), JSON_PRESERVE_ZERO_FRACTION);
162172

163173
$optimizer = new FullNameOptimizer();
164174

0 commit comments

Comments
 (0)