Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @implements DataTransformerInterface<Collection, array>
* @implements DataTransformerInterface<Collection|array, array>
*/
class CollectionToArrayTransformer implements DataTransformerInterface
{
/**
* Transforms a collection into an array.
*
* @throws TransformationFailedException
*/
public function transform(mixed $collection): mixed
{
if (null === $collection) {
Expand All @@ -48,9 +43,6 @@ public function transform(mixed $collection): mixed
return $collection->toArray();
}

/**
* Transforms an array into a collection.
*/
public function reverseTransform(mixed $array): Collection
{
if ('' === $array || null === $array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public function __construct(
}
}

/**
* Transforms a Boolean into a string.
*
* @param bool $value Boolean value
*
* @throws TransformationFailedException if the given value is not a Boolean
*/
public function transform(mixed $value): ?string
{
if (null === $value) {
Expand All @@ -57,13 +50,6 @@ public function transform(mixed $value): ?string
return $value ? $this->trueValue : null;
}

/**
* Transforms a string into a Boolean.
*
* @param string $value String value
*
* @throws TransformationFailedException if the given value is not a string
*/
public function reverseTransform(mixed $value): bool
{
if (\in_array($value, $this->falseValues, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public function __construct(
) {
}

/**
* @throws TransformationFailedException if the given value is not an array
*/
public function transform(mixed $array): array
{
if (null === $array) {
Expand All @@ -43,11 +40,6 @@ public function transform(mixed $array): array
return $this->choiceList->getValuesForChoices($array);
}

/**
* @throws TransformationFailedException if the given value is not an array
* or if no matching choice could be
* found for some given value
*/
public function reverseTransform(mixed $array): array
{
if (null === $array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataTransformer;

use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;

/**
* Passes a value through multiple value transformers.
Expand All @@ -31,18 +30,6 @@ public function __construct(
) {
}

/**
* Passes the value through the transform() method of all nested transformers.
*
* The transformers receive the value in the same order as they were passed
* to the constructor. Each transformer receives the result of the previous
* transformer as input. The output of the last transformer is returned
* by this method.
*
* @param mixed $value The original value
*
* @throws TransformationFailedException
*/
public function transform(mixed $value): mixed
{
foreach ($this->transformers as $transformer) {
Expand All @@ -52,19 +39,6 @@ public function transform(mixed $value): mixed
return $value;
}

/**
* Passes the value through the reverseTransform() method of all nested
* transformers.
*
* The transformers receive the value in the reverse order as they were passed
* to the constructor. Each transformer receives the result of the previous
* transformer as input. The output of the last transformer is returned
* by this method.
*
* @param mixed $value The transformed value
*
* @throws TransformationFailedException
*/
public function reverseTransform(mixed $value): mixed
{
for ($i = \count($this->transformers) - 1; $i >= 0; --$i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ public function __construct(
$this->fields = $fields ?? ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'];
}

/**
* Transforms a normalized date interval into an interval array.
*
* @param \DateInterval $dateInterval Normalized date interval
*
* @throws UnexpectedTypeException if the given value is not a \DateInterval instance
*/
public function transform(mixed $dateInterval): array
{
if (null === $dateInterval) {
Expand Down Expand Up @@ -97,14 +90,6 @@ public function transform(mixed $dateInterval): array
return array_intersect_key($result, array_flip($this->fields));
}

/**
* Transforms an interval array into a normalized date interval.
*
* @param array $value Interval array
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the value could not be transformed
*/
public function reverseTransform(mixed $value): ?\DateInterval
{
if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ public function __construct(
) {
}

/**
* Transforms a DateInterval object into a date string with the configured format.
*
* @param \DateInterval|null $value A DateInterval object
*
* @throws UnexpectedTypeException if the given value is not a \DateInterval instance
*/
public function transform(mixed $value): string
{
if (null === $value) {
Expand All @@ -55,14 +48,6 @@ public function transform(mixed $value): string
return $value->format($this->format);
}

/**
* Transforms a date string in the configured format into a DateInterval object.
*
* @param string $value An ISO 8601 or date string like date interval presentation
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the date interval could not be parsed
*/
public function reverseTransform(mixed $value): ?\DateInterval
{
if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
*/
final class DatePointToDateTimeTransformer implements DataTransformerInterface
{
/**
* Transforms a DatePoint into a DateTime object.
*
* @param DatePoint|null $value A DatePoint object
*
* @throws TransformationFailedException If the given value is not a DatePoint
*/
public function transform(mixed $value): ?\DateTime
{
if (null === $value) {
Expand All @@ -42,13 +35,6 @@ public function transform(mixed $value): ?\DateTime
return \DateTime::createFromImmutable($value);
}

/**
* Transforms a DateTime object into a DatePoint object.
*
* @param \DateTime|null $value A DateTime object
*
* @throws TransformationFailedException If the given value is not a \DateTime
*/
public function reverseTransform(mixed $value): ?DatePoint
{
if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
*/
final class DateTimeImmutableToDateTimeTransformer implements DataTransformerInterface
{
/**
* Transforms a DateTimeImmutable into a DateTime object.
*
* @param \DateTimeImmutable|null $value A DateTimeImmutable object
*
* @throws TransformationFailedException If the given value is not a \DateTimeImmutable
*/
public function transform(mixed $value): ?\DateTime
{
if (null === $value) {
Expand All @@ -43,13 +36,6 @@ public function transform(mixed $value): ?\DateTime
return \DateTime::createFromImmutable($value);
}

/**
* Transforms a DateTime object into a DateTimeImmutable object.
*
* @param \DateTime|null $value A DateTime object
*
* @throws TransformationFailedException If the given value is not a \DateTime
*/
public function reverseTransform(mixed $value): ?\DateTimeImmutable
{
if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ public function __construct(
$this->referenceDate = $referenceDate ?? new \DateTimeImmutable('1970-01-01 00:00:00');
}

/**
* Transforms a normalized date into a localized date.
*
* @param \DateTimeInterface $dateTime A DateTimeInterface object
*
* @throws TransformationFailedException If the given value is not a \DateTimeInterface
*/
public function transform(mixed $dateTime): array
{
if (null === $dateTime) {
Expand Down Expand Up @@ -95,14 +88,6 @@ public function transform(mixed $dateTime): array
return $result;
}

/**
* Transforms a localized date into a normalized date.
*
* @param array $value Localized date
*
* @throws TransformationFailedException If the given value is not an array,
* if the value could not be transformed
*/
public function reverseTransform(mixed $value): ?\DateTime
{
if (null === $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ public function __construct(?string $inputTimezone = null, ?string $outputTimezo
}

/**
* Transforms a \DateTime into a local date and time string.
*
* According to the HTML standard, the input string of a datetime-local
* input is an RFC3339 date followed by 'T', followed by an RFC3339 time.
* https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
*
* @param \DateTimeInterface $dateTime
* https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string.
*
* @throws TransformationFailedException If the given value is not an
* instance of \DateTime or \DateTimeInterface
* @throws \DateInvalidTimeZoneException
*/
public function transform(mixed $dateTime): string
{
Expand All @@ -61,16 +56,11 @@ public function transform(mixed $dateTime): string
}

/**
* Transforms a local date and time string into a \DateTime.
*
* When transforming back to DateTime the regex is slightly laxer, taking into
* account rules for parsing a local date and time string
* https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#parse-a-local-date-and-time-string
*
* @param string $dateTimeLocal Formatted string
* https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#parse-a-local-date-and-time-string.
*
* @throws TransformationFailedException If the given value is not a string,
* if the value could not be transformed
* @throws \DateInvalidTimeZoneException
*/
public function reverseTransform(mixed $dateTimeLocal): ?\DateTime
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ public function __construct(
$this->timeFormat = $timeFormat;
}

/**
* Transforms a normalized date into a localized date string/array.
*
* @param \DateTimeInterface $dateTime A DateTimeInterface object
*
* @throws TransformationFailedException if the given value is not a \DateTimeInterface
* or if the date could not be transformed
*/
public function transform(mixed $dateTime): string
{
if (null === $dateTime) {
Expand All @@ -96,14 +88,6 @@ public function transform(mixed $dateTime): string
return $value;
}

/**
* Transforms a localized date string/array into a normalized date.
*
* @param string $value Localized date string
*
* @throws TransformationFailedException if the given value is not a string,
* if the date could not be parsed
*/
public function reverseTransform(mixed $value): ?\DateTime
{
if (!\is_string($value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
*/
class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
{
/**
* Transforms a normalized date into a localized date.
*
* @param \DateTimeInterface $dateTime A DateTimeInterface object
*
* @throws TransformationFailedException If the given value is not a \DateTimeInterface
*/
public function transform(mixed $dateTime): string
public function transform(mixed $dateTime): ?string
{
if (null === $dateTime) {
return '';
Expand All @@ -45,14 +38,6 @@ public function transform(mixed $dateTime): string
return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c'));
}

/**
* Transforms a formatted string following RFC 3339 into a normalized date.
*
* @param string $rfc3339 Formatted string
*
* @throws TransformationFailedException If the given value is not a string,
* if the value could not be transformed
*/
public function reverseTransform(mixed $rfc3339): ?\DateTime
{
if (!\is_string($rfc3339)) {
Expand Down
Loading