[Live] Fix nullable DateTime hydration with empty value

by @1ed

Some issues have been detected in this pull request

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/symfony/ux/1901/dc3360199647ea750f7e28c79c805f38d587bfdd/cs.diff | patch -p0
diff -ru src/LiveComponent/src/LiveComponentHydrator.php src/LiveComponent/src/LiveComponentHydrator.php
--- src/LiveComponent/src/LiveComponentHydrator.php	2024-06-09 22:31:32.737914059 +0000
+++ src/LiveComponent/src/LiveComponentHydrator.php	2024-06-09 22:31:36.913061189 +0000
@@ -532,7 +532,7 @@
             }
 
             if ('' === $value) {
-                return $allowsNull ? null : throw new BadRequestHttpException(sprintf('The model path "%s" was sent invalid date data "%s". Setting empty date value is not allowed, send a non-empty value or make the property nullable.', $propertyPathForError, $value, $dateFormat)) ;
+                return $allowsNull ? null : throw new BadRequestHttpException(sprintf('The model path "%s" was sent invalid date data "%s". Setting empty date value is not allowed, send a non-empty value or make the property nullable.', $propertyPathForError, $value, $dateFormat));
             }
 
             if (null !== $dateFormat) {
diff -ru src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php
--- src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php	2024-06-09 22:31:32.975922446 +0000
+++ src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php	2024-06-09 22:31:45.771373351 +0000
@@ -316,7 +316,7 @@
             })
                 ->mountWith(['createdAt' => $date])
                 ->userUpdatesProps(['createdAt' => ''])
-                ->assertObjectAfterHydration(function (object $object) use ($date) {
+                ->assertObjectAfterHydration(function (object $object) {
                     self::assertNull($object->createdAt);
                 })
             ;

0
Common Typos

0
File Permissions

0
Merge Commits

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

curl https://fabbot.io/patch/symfony/ux/1901/dc3360199647ea750f7e28c79c805f38d587bfdd/exception_messages.diff | patch -p0
diff -ru src/LiveComponent/src/LiveComponentHydrator.php src/LiveComponent/src/LiveComponentHydrator.php
--- src/LiveComponent/src/LiveComponentHydrator.php	2024-06-09 22:31:32.737914059 +0000
+++ src/LiveComponent/src/LiveComponentHydrator.php	2024-06-09 22:31:46.499399006 +0000
@@ -101,7 +101,7 @@
                     } catch (NoSuchPropertyException $e) {
                         throw new \LogicException(sprintf('The writable path "%s" does not exist on the "%s" property of the "%s" component.', $path, $propertyName, $component::class), 0, $e);
                     } catch (PropertyAccessExceptionInterface $e) {
-                        throw new \LogicException(sprintf('The writable path "%s" on the "%s" property of the "%s" component could not be read: %s', $path, $propertyName, $component::class, $e->getMessage()), 0, $e);
+                        throw new \LogicException(sprintf('The writable path "%s" on the "%s" property of the "%s" component could not be read: "%s".', $path, $propertyName, $component::class, $e->getMessage()), 0, $e);
                     }
 
                     // TODO: maybe we allow support the same types as LiveProps later
@@ -182,7 +182,7 @@
              */
             if ($dehydratedUpdatedProps->hasPropValue($frontendName)) {
                 if (!$propMetadata->isIdentityWritable()) {
-                    throw new HydrationException(sprintf('The model "%s" was sent for update, but it is not writable. Try adding "writable: true" to the $%s property in %s.', $frontendName, $propMetadata->getName(), $component::class));
+                    throw new HydrationException(sprintf('The model "%s" was sent for update, but it is not writable. Try adding "writable: true" to the $%s property in "%s".', $frontendName, $propMetadata->getName(), $component::class));
                 }
                 try {
                     $propertyValue = $this->hydrateValue(
@@ -321,7 +321,7 @@
             'int' => (int) $value,
             'float' => (float) $value,
             'bool' => self::coerceStringToBoolean($value),
-            default => throw new \LogicException(sprintf('Cannot coerce value "%s" to type "%s"', $value, $type)),
+            default => throw new \LogicException(sprintf('Cannot coerce value "%s" to type "%s".', $value, $type)),
         };
     }
 
@@ -348,7 +348,7 @@
     private function verifyChecksum(array $identifierPops, string $error = 'Invalid checksum sent when updating the live component.'): void
     {
         if (!\array_key_exists(self::CHECKSUM_KEY, $identifierPops)) {
-            throw new HydrationException(sprintf('Missing %s. key', self::CHECKSUM_KEY));
+            throw new HydrationException(sprintf('Missing "%s". key.', self::CHECKSUM_KEY));
         }
         $sentChecksum = $identifierPops[self::CHECKSUM_KEY];
         unset($identifierPops[self::CHECKSUM_KEY]);
@@ -452,7 +452,7 @@
                 $collectionClass = $propMetadata->collectionValueType()->getClassName();
                 foreach ($value as $key => $objectItem) {
                     if (!$objectItem instanceof $collectionClass) {
-                        throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array. We determined the array is full of %s objects, but at least on key had a different value of %s', $propMetadata->getName(), $parentObject::class, $collectionClass, get_debug_type($objectItem)));
+                        throw new \LogicException(sprintf('The LiveProp "%s" on component "%s" is an array. We determined the array is full of "%s" objects, but at least on key had a different value of "%s".', $propMetadata->getName(), $parentObject::class, $collectionClass, get_debug_type($objectItem)));
                     }
 
                     $value[$key] = $this->dehydrateObjectValue($objectItem, $collectionClass, $propMetadata->getFormat(), $parentObject);
@@ -605,7 +605,7 @@
 
         if (\count($extraSentWritablePaths) > 0) {
             // we could show multiple fields here in the message
-            throw new HydrationException(sprintf('The model "%s.%s" was sent for update, but it is not writable. Try adding "writable: [\'%s\']" to the $%s property in %s.', $frontendPropName, $extraSentWritablePaths[0], $extraSentWritablePaths[0], $propMetadata->getName(), $componentClass));
+            throw new HydrationException(sprintf('The model "%s.%s" was sent for update, but it is not writable. Try adding "writable: [\'%s\']" to the $%s property in "%s".', $frontendPropName, $extraSentWritablePaths[0], $extraSentWritablePaths[0], $propMetadata->getName(), $componentClass));
         }
 
         return $writablePaths;

0
Usage of void in test files

0
Use ::class whenever possible

0
Deprecation Messages