Skip to content

Commit

Permalink
backport change (#61)
Browse files Browse the repository at this point in the history
* backport change

* fix obsolete test (only 3.x)

* fix cs
  • Loading branch information
nick-zh authored Nov 23, 2022
1 parent e272c9d commit 6c9f01d
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/Generator/SchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

final class SchemaGenerator implements SchemaGeneratorInterface
{

/**
* @var int[]
*/
Expand Down Expand Up @@ -89,7 +88,7 @@ public function generate(): array
$schema['fields'][] = $field;
}

$schemas[$schema['namespace'] . '.' . $schema['name']] = json_encode($schema);
$schemas[$schema['namespace'] . '.' . $schema['name']] = json_encode($schema, JSON_PRESERVE_ZERO_FRACTION);
}

return $schemas;
Expand Down
2 changes: 1 addition & 1 deletion src/Merger/SchemaMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function exportSchema(
}

/** @var string $fileContents */
$fileContents = json_encode($rootSchemaDefinition);
$fileContents = json_encode($rootSchemaDefinition, JSON_PRESERVE_ZERO_FRACTION);

file_put_contents($this->getOutputDirectory() . '/' . $schemaFilename, $fileContents);
}
Expand Down
1 change: 0 additions & 1 deletion src/Merger/SchemaMergerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

interface SchemaMergerInterface
{

/**
* @return SchemaRegistryInterface
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Optimizer/FieldOrderOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function optimize(string $definition): string

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

return json_encode($data, JSON_THROW_ON_ERROR);
return json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Optimizer/FullNameOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function optimize(string $definition): string
$currentNamespace = $data['namespace'] ?? '';
$data = $this->processSchema($currentNamespace, $data, true);

return json_encode($data, JSON_THROW_ON_ERROR);
return json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Optimizer/PrimitiveSchemaOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function optimize(string $definition, bool $isPrimitive = false): string

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

return json_encode($data, JSON_THROW_ON_ERROR);
return json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/PhpClass/PhpClassProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class PhpClassProperty implements PhpClassPropertyInterface
{

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/Registry/ClassRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

final class ClassRegistry implements ClassRegistryInterface
{

/**
* @var array<string,int>
*/
Expand Down
1 change: 0 additions & 1 deletion src/Registry/ClassRegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface ClassRegistryInterface
{

/**
* @param string $classDirectory
* @return ClassRegistryInterface
Expand Down
8 changes: 4 additions & 4 deletions src/Registry/SchemaRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ private function registerSchemaFile(\SplFileInfo $fileInfo): void
}

$schemaData = json_decode($fileContent, true, JSON_THROW_ON_ERROR);
$namespace = '';
$namespace = '';

if (true === isset($schemaData['namespace'])) {
$namespace = $schemaData['namespace'];
}
if (true === isset($schemaData['namespace'])) {
$namespace = $schemaData['namespace'];
}

if (null === $schemaData) {
throw new SchemaRegistryException(sprintf(SchemaRegistryException::FILE_INVALID, $fileName));
Expand Down
1 change: 0 additions & 1 deletion src/Registry/SchemaRegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface SchemaRegistryInterface
{

/**
* @param string $schemaTemplateDirectory
* @return SchemaRegistryInterface
Expand Down
12 changes: 11 additions & 1 deletion tests/Unit/Optimizer/FieldOrderOptimizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function testOptimize(): void
"type": "array",
"items": ["null", "com.example.Page"]
},
{
"name": "price",
"type": "float",
"default": 99.0
},
{
"name": "defaultFont",
"type": "com.example.Font"
Expand Down Expand Up @@ -147,6 +152,11 @@ public function testOptimize(): void
"type": "array",
"items": ["null", "com.example.Page"]
},
{
"name": "price",
"type": "float",
"default": 99.0
},
{
"name": "defaultFont",
"type": "com.example.Font"
Expand Down Expand Up @@ -201,7 +211,7 @@ public function testOptimize(): void
]
}
]
}'));
}'), JSON_PRESERVE_ZERO_FRACTION);

$optimizer = new FieldOrderOptimizer();

Expand Down
12 changes: 11 additions & 1 deletion tests/Unit/Optimizer/FullNameOptimizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function testOptimize(): void
"type": "array",
"items": ["null","com.example.Page"]
},
{
"name": "price",
"type": "float",
"default": 99.0
},
{
"name": "appendix",
"type": "array",
Expand Down Expand Up @@ -125,6 +130,11 @@ public function testOptimize(): void
"type": "array",
"items": ["null","Page"]
},
{
"name": "price",
"type": "float",
"default": 99.0
},
{
"name": "appendix",
"type": "array",
Expand Down Expand Up @@ -158,7 +168,7 @@ public function testOptimize(): void
},
{ "name": "backSide", "type": "com.example.other.Cover"}
]
}'));
}'), JSON_PRESERVE_ZERO_FRACTION);

$optimizer = new FullNameOptimizer();

Expand Down

0 comments on commit 6c9f01d

Please sign in to comment.