Skip to content

Commit

Permalink
Merge pull request #45 from liip/cs
Browse files Browse the repository at this point in the history
Cs
  • Loading branch information
dbu authored Mar 4, 2024
2 parents 987b2b1 + 5d86303 commit 16ee2ed
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

# unreleased

* Fixed: Dates with a getter/setter where incorrectly handled in the refactoring for 2.6.0.
See (#44)[https://github.com/liip/serializer/pull/44]

# 2.6.0

* (De)serialization now accepts timezones, and lists of deserialization formats

# 2.5.1
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/ClassToGenerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ClassToGenerate implements \IteratorAggregate
public function __construct(
private GeneratorConfiguration $configuration,
private string $className,
array $defaultVersions = null
?array $defaultVersions = null
) {
$this->defaultVersions = null === $defaultVersions ? null : array_map('strval', $defaultVersions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/DeserializerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
private Deserialization $templating,
array $classesToGenerate,
private string $cacheDirectory,
GeneratorConfiguration $configuration = null
?GeneratorConfiguration $configuration = null
) {
$this->filesystem = new Filesystem();
$this->configuration = $this->createGeneratorConfiguration($configuration, $classesToGenerate);
Expand Down
8 changes: 4 additions & 4 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(private string $cacheDirectory)
* Serializing primitive types is not currently implemented and will lead
* to an UnsupportedTypeException.
*/
public function serialize(mixed $data, string $format, Context $context = null): string
public function serialize(mixed $data, string $format, ?Context $context = null): string
{
if ('json' !== $format) {
throw new UnsupportedFormatException('Liip serializer only supports JSON for now');
Expand All @@ -47,7 +47,7 @@ public function serialize(mixed $data, string $format, Context $context = null):
* Version or groups are currently not implemented for deserialization and
* passing a context with one of those values set will lead to an Exception.
*/
public function deserialize(string $data, string $type, string $format, Context $context = null): mixed
public function deserialize(string $data, string $type, string $format, ?Context $context = null): mixed
{
if ('json' !== $format) {
throw new UnsupportedFormatException('Liip serializer only supports JSON for now');
Expand All @@ -68,7 +68,7 @@ public function deserialize(string $data, string $type, string $format, Context
* Serializing primitive types is not currently implemented and will lead
* to an UnsupportedTypeException.
*/
public function toArray($data, Context $context = null): array
public function toArray($data, ?Context $context = null): array
{
return $this->objectToArray($data, false, $context);
}
Expand All @@ -79,7 +79,7 @@ public function toArray($data, Context $context = null): array
* Version or groups are currently not implemented for deserialization and
* passing a context with one of those values set will lead to an Exception.
*/
public function fromArray(array $data, string $type, Context $context = null): mixed
public function fromArray(array $data, string $type, ?Context $context = null): mixed
{
return $this->arrayToObject($data, $type, $context);
}
Expand Down
8 changes: 4 additions & 4 deletions src/SerializerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface SerializerInterface
* @throws UnsupportedFormatException if $format is not supported
* @throws UnsupportedTypeException if no generated function is available for the class of $data
*/
public function serialize(mixed $data, string $format, Context $context = null): string;
public function serialize(mixed $data, string $format, ?Context $context = null): string;

/**
* Convert a string representation to an object.
Expand All @@ -44,7 +44,7 @@ public function serialize(mixed $data, string $format, Context $context = null):
* @throws UnsupportedFormatException if $format is not supported
* @throws UnsupportedTypeException if there is no generated function available for $type
*/
public function deserialize(string $data, string $type, string $format, Context $context = null): mixed;
public function deserialize(string $data, string $type, string $format, ?Context $context = null): mixed;

/**
* Convert an object to an array.
Expand All @@ -57,7 +57,7 @@ public function deserialize(string $data, string $type, string $format, Context
* @throws Exception if anything else goes wrong
* @throws UnsupportedTypeException if no generated function is available for the class of $data
*/
public function toArray(mixed $data, Context $context = null): array;
public function toArray(mixed $data, ?Context $context = null): array;

/**
* Convert an array to an object.
Expand All @@ -71,5 +71,5 @@ public function toArray(mixed $data, Context $context = null): array;
* @throws Exception if anything else goes wrong
* @throws UnsupportedTypeException if there is no generated function available for $type
*/
public function fromArray(array $data, string $type, Context $context = null): mixed;
public function fromArray(array $data, string $type, ?Context $context = null): mixed;
}
2 changes: 1 addition & 1 deletion src/Template/Deserialization.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function renderAssignDateTimeToField(bool $immutable, string $modelPath,
/**
* @param list<string>|string $formats
*/
public function renderAssignDateTimeFromFormat(bool $immutable, string $modelPath, string $jsonPath, array|string $formats, string $timezone = null): string
public function renderAssignDateTimeFromFormat(bool $immutable, string $modelPath, string $jsonPath, array|string $formats, ?string $timezone = null): string
{
if (\is_string($formats)) {
@trigger_error('Passing a string for argument $formats is deprecated, please pass an array of strings instead', \E_USER_DEPRECATED);
Expand Down

0 comments on commit 16ee2ed

Please sign in to comment.