Skip to content

Commit

Permalink
refacto some converters useless methods
Browse files Browse the repository at this point in the history
  • Loading branch information
clementtalleu committed Jun 7, 2024
1 parent 8bffe7b commit e19f884
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 34 deletions.
5 changes: 4 additions & 1 deletion src/Om/Converters/AbstractDateTimeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ public function supportsConversion(string $type, mixed $data): bool

abstract public function revert($data, string $type): \DateTime;

abstract public function supportsReversion(string $type, mixed $value): bool;
public function supportsReversion(string $type, mixed $value): bool
{
return $type === 'DateTime' || $type === 'DateTimeInterface';
}
}
5 changes: 4 additions & 1 deletion src/Om/Converters/AbstractDateTimeImmutableConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ public function supportsConversion(string $type, mixed $data): bool

abstract public function revert($data, string $type): \DateTimeImmutable;

abstract public function supportsReversion(string $type, mixed $value): bool;
public function supportsReversion(string $type, mixed $value): bool
{
return $type === 'DateTimeImmutable';
}
}
5 changes: 1 addition & 4 deletions src/Om/Converters/AbstractObjectConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public function supportsConversion(string $type, mixed $data): bool

abstract public function revert($data, string $type): mixed;

public function supportsReversion(string $type, mixed $value): bool
{
return class_exists($type) && !in_array($type, AbstractDateTimeConverter::DATETYPES_NAMES);
}
abstract public function supportsReversion(string $type, mixed $value): bool;

protected function extractPropertyValue(Property $propertyAttribute, \ReflectionProperty $property, object $data): mixed
{
Expand Down
9 changes: 0 additions & 9 deletions src/Om/Converters/HashModel/DateTimeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,4 @@ public function revert($data, string $type): \DateTime

return new \DateTime($data);
}

public function supportsReversion(string $type, mixed $value): bool
{
if ($type === 'DateTime' || $type === 'DateTimeInterface') {
return true;
}

return false;
}
}
9 changes: 0 additions & 9 deletions src/Om/Converters/HashModel/DateTimeImmutableConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,4 @@ public function revert($data, string $type): \DateTimeImmutable

return new \DateTimeImmutable($data);
}

public function supportsReversion(string $type, mixed $value): bool
{
if ($type === 'DateTimeImmutable') {
return true;
}

return false;
}
}
5 changes: 0 additions & 5 deletions src/Om/Converters/JsonModel/DateTimeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,4 @@ public function revert($data, string $type): \DateTime
{
return new \DateTime($data['date'], new \DateTimeZone($data['timezone']));
}

public function supportsReversion(string $type, mixed $value): bool
{
return $type === 'DateTime' || $type === 'DateTimeInterface';
}
}
5 changes: 0 additions & 5 deletions src/Om/Converters/JsonModel/DateTimeImmutableConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,4 @@ public function revert($data, string $type): \DateTimeImmutable
{
return new \DateTimeImmutable($data['date'], new \DateTimeZone($data['timezone']));
}

public function supportsReversion(string $type, mixed $value): bool
{
return $type === 'DateTimeImmutable';
}
}

0 comments on commit e19f884

Please sign in to comment.