Skip to content

551 ramsey UUID en ramsey UUID doctrine#434

Merged
ilaria-orlando merged 6 commits intomasterfrom
551-ramsey-uuid-en-ramsey-uuid-doctrine
Mar 23, 2026
Merged

551 ramsey UUID en ramsey UUID doctrine#434
ilaria-orlando merged 6 commits intomasterfrom
551-ramsey-uuid-en-ramsey-uuid-doctrine

Conversation

@ilaria-orlando
Copy link
Copy Markdown

@ilaria-orlando ilaria-orlando commented Mar 19, 2026

Type

  • Enhancement

Pull request description

Replace ramsey/uuid and ramsey/doctrine/uuid by symfony/uuid for MediaLibrary, MediaGallery, MediaGroupMediaItem and MediaGroup

Summary by Sourcery

Migrate MediaLibrary and related domains from ramsey/uuid to Symfony's UID UUID implementation and centralize UUID database handling.

Enhancements:

  • Replace ramsey/uuid and ramsey/uuid-doctrine usage in media domain models and handlers with Symfony\Component\Uid\Uuid.
  • Introduce a custom Doctrine DBAL uuid type that integrates Symfony UUIDs with database serialization.
  • Adjust JSON serialization of media entities to expose UUIDs as RFC 4122 strings instead of objects.

Build:

  • Update composer dependencies to remove ramsey/uuid packages and require symfony/uid.
  • Reconfigure Doctrine DBAL type mappings to use the new custom uuid type instead of ramsey's implementation.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 19, 2026

Reviewer's Guide

Replaces ramsey/uuid and its Doctrine integration with Symfony Uid-based UUIDs across MediaLibrary domain objects, introduces a custom Doctrine DBAL UUID type, and updates JSON/form serialization and configuration to work with Symfony\Component\Uid\Uuid while removing the ramsey dependencies.

Class diagram for updated MediaGroup and MediaGroupMediaItem UUID handling

classDiagram
    class MediaGroup {
        - Uuid id
        - Type type
        + private __construct(Uuid id, Type type)
        + static create(Type type) MediaGroup
        + static createFromId(Uuid id, Type type) MediaGroup
        + getId() Uuid
        + getType() Type
        + jsonSerialize() array
    }

    class MediaGroupMediaItem {
        - Uuid id
        - MediaGroup group
        - MediaItem item
        - DateTime createdOn
        - int sequence
        + private __construct(MediaGroup group, MediaItem item, int sequence)
        + static create(MediaGroup group, MediaItem item, int sequence) MediaGroupMediaItem
        + jsonSerialize() array
        + getId() Uuid
    }

    class MediaGroupDataTransferObject {
        - Uuid id
    }

    class MediaGroupType {
        - MessageBusSupportingMiddleware bus
        + private getMediaGroupFromMediaGroupData(array mediaGroupData) MediaGroup
        + private getMediaGroupTransformFunction() callable
    }

    class SaveMediaGroupHandler {
        - MediaItemRepository mediaItemRepository
        + __construct(MediaItemRepository mediaItemRepository)
    }

    class MediaGallery {
        - MediaGroup mediaGroup
    }

    class Uuid {
        + static v4() Uuid
        + static fromString(string value) Uuid
        + static isValid(string value) bool
        + toRfc4122() string
    }

    MediaGroup "1" o-- "*" MediaGroupMediaItem : contains
    MediaGroupMediaItem "1" --> "1" MediaGroup : group
    MediaGroupMediaItem "1" --> "1" MediaItem : item
    MediaGallery "1" --> "1" MediaGroup : references
    MediaGroupDataTransferObject "1" --> "1" Uuid : id
    MediaGroupType "1" --> "1" MediaGroup : builds
    SaveMediaGroupHandler "1" --> "1" MediaItemRepository : uses
    MediaGroup "1" --> "1" Uuid : id
    MediaGroupMediaItem "1" --> "1" Uuid : id
Loading

Class diagram for new Common Doctrine UuidType

classDiagram
    class GuidType {
    }

    class UuidType {
        + const NAME
        + convertToPHPValue(mixed value, AbstractPlatform platform) Uuid
        + convertToDatabaseValue(mixed value, AbstractPlatform platform) string
        + getName() string
        + requiresSQLCommentHint(AbstractPlatform platform) bool
        + getMappedDatabaseTypes(AbstractPlatform platform) string[]
    }

    class Uuid {
        + static fromString(string value) Uuid
        + static isValid(string value) bool
        + toRfc4122() string
    }

    class AbstractPlatform {
    }

    class ConversionException {
        + static conversionFailed(mixed value, string type) ConversionException
    }

    UuidType --|> GuidType
    UuidType --> Uuid : converts
    UuidType --> AbstractPlatform : db platform
    UuidType --> ConversionException : throws
Loading

Flow diagram for UuidType database and PHP value conversion

flowchart LR
    subgraph Database
        DBValue["UUID column value (string or NULL)"]
    end

    subgraph "PHP\nDoctrine DBAL"
        UuidTypeInstance["Common\\Doctrine\\Type\\UuidType"]
        PHPValue["PHP value (Symfony Uuid or null)"]
    end

    DBValue -->|read from DB| UuidTypeInstance
    UuidTypeInstance -->|convertToPHPValue\n- if value is Uuid: return as is\n- if empty or non string: return null\n- else Uuid from string or throw ConversionException| PHPValue

    PHPValue -->|write to DB| UuidTypeInstance
    UuidTypeInstance -->|convertToDatabaseValue\n- if null or empty: null\n- if Uuid: toRfc4122\n- if string or stringable and Uuid is valid: string\n- else: ConversionException| DBValue
Loading

File-Level Changes

Change Details Files
Switch MediaGroupMediaItem entity to Symfony Uuid and manual v4 assignment.
  • Replace Ramsey Uuid imports with Symfony\Component\Uid\Uuid.
  • Remove Doctrine custom UUID generator annotations and keep column as type uuid.
  • Assign UUID in constructor using Uuid::v4().
  • Change jsonSerialize to output RFC4122 string for id.
  • Update getId() return type from int to Uuid.
src/Backend/Modules/MediaLibrary/Domain/MediaGroupMediaItem/MediaGroupMediaItem.php
Refactor MediaGroup entity to use Symfony Uuid for identity.
  • Swap Ramsey Uuid and UuidInterface usage for Symfony Uid\Uuid.
  • Generate new IDs with Uuid::v4() in factory.
  • Update createFromId and getId signatures to use Symfony Uuid.
  • Keep Doctrine column mapping as type uuid for compatibility with new DBAL type.
src/Backend/Modules/MediaLibrary/Domain/MediaGroup/MediaGroup.php
Introduce shared Doctrine DBAL UUID type backed by Symfony Uuid.
  • Add Common\Doctrine\Type\UuidType extending GuidType with Symfony Uuid conversion.
  • Implement convertToPHPValue and convertToDatabaseValue validating and normalizing UUIDs to RFC4122 strings.
  • Ensure SQL comment hints and mapping for uuid DB type name.
  • Wire the custom uuid type into global and MediaLibrary-specific Doctrine configuration.
src/Common/Doctrine/Type/UuidType.php
app/config/doctrine.yml
src/Backend/Modules/MediaLibrary/Resources/config/doctrine.yml
Adjust MediaLibrary DTOs, form types, and command handlers to Symfony Uuid and string serialization.
  • Replace Ramsey Uuid imports with Symfony Uid\Uuid in MediaGroup form type, DTO, and SaveMediaGroupHandler.
  • Change MediaGroupType form transform output so mediaGroup id is serialized to RFC4122 string.
  • Ensure MediaGroup-related code now consistently works with Symfony Uuid instances.
src/Backend/Modules/MediaLibrary/Domain/MediaGroup/MediaGroupType.php
src/Backend/Modules/MediaLibrary/Domain/MediaGroup/Command/SaveMediaGroupHandler.php
src/Backend/Modules/MediaLibrary/Domain/MediaGroup/MediaGroupDataTransferObject.php
Update dependencies to drop ramsey/uuid in favor of symfony/uid.
  • Remove ramsey/uuid and ramsey/uuid-doctrine from composer.json requirements.
  • Add symfony/uid as a new dependency.
  • Clean up unused Ramsey Uuid import from MediaGallery entity.
composer.json
src/Backend/Modules/MediaGalleries/Domain/MediaGallery/MediaGallery.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In MediaGroupMediaItem, consider adding a Uuid typed property for $id (as done in MediaGroup) instead of relying only on a docblock, to keep UUID handling consistent and benefit from static analysis.
  • In Common\Doctrine\Type\UuidType::convertToPHPValue, returning null for non-string, non-null values may mask data issues; consider throwing a ConversionException in that branch so invalid database values are surfaced explicitly.
  • The symfony/uid dependency is currently required as "*" in composer.json; tightening this to a specific major/minor constraint (e.g. ^6.0 or ^7.0) will reduce the risk of unexpected breaking changes on update.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `MediaGroupMediaItem`, consider adding a `Uuid` typed property for `$id` (as done in `MediaGroup`) instead of relying only on a docblock, to keep UUID handling consistent and benefit from static analysis.
- In `Common\Doctrine\Type\UuidType::convertToPHPValue`, returning `null` for non-string, non-null values may mask data issues; consider throwing a `ConversionException` in that branch so invalid database values are surfaced explicitly.
- The `symfony/uid` dependency is currently required as `"*"` in `composer.json`; tightening this to a specific major/minor constraint (e.g. `^6.0` or `^7.0`) will reduce the risk of unexpected breaking changes on update.

## Individual Comments

### Comment 1
<location path="src/Common/Doctrine/Type/UuidType.php" line_range="32-37" />
<code_context>
+
+    public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
+    {
+        if ($value === null || $value === '') {
+            return null;
+        }
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Treating empty-string values as null in convertToDatabaseValue may mask invalid inputs.

Because `convertToDatabaseValue` maps both `null` and `''` to `null`, an empty string ID from the application will be stored as `NULL` instead of failing conversion. This can hide invalid input and violate NOT NULL expectations. Consider only treating `null` as `null` and letting `''` go through normal validation so it raises a `ConversionException` if it’s not a valid UUID.

```suggestion
    public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
    {
        if ($value === null) {
            return null;
        }

```
</issue_to_address>

### Comment 2
<location path="composer.json" line_range="62-63" />
<code_context>
         "twig/string-extra": "^3.23",
-        "twig/inky-extra": "^3.23"
+        "twig/inky-extra": "^3.23",
+        "symfony/uid": "*"
     },
     "require-dev": {
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Use a bounded version constraint for symfony/uid instead of a wildcard.

Using "*" for `symfony/uid` makes installs non-deterministic and risks unexpected breaking changes when a new major version is released. Please align this with the rest of the Symfony stack by using a bounded constraint (e.g. `^6.0`).

```suggestion
        "twig/inky-extra": "^3.23",
        "symfony/uid": "^6.0"
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +32 to +37
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if ($value === null || $value === '') {
return null;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Treating empty-string values as null in convertToDatabaseValue may mask invalid inputs.

Because convertToDatabaseValue maps both null and '' to null, an empty string ID from the application will be stored as NULL instead of failing conversion. This can hide invalid input and violate NOT NULL expectations. Consider only treating null as null and letting '' go through normal validation so it raises a ConversionException if it’s not a valid UUID.

Suggested change
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if ($value === null || $value === '') {
return null;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if ($value === null) {
return null;
}

@ilaria-orlando ilaria-orlando merged commit c1fd78b into master Mar 23, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants