Repository: symfony/symfony
File: src/Symfony/Component/Uid/Factory/MockUuidFactory.php (PHP)

Code before:
    }

    public function timeBased(Uuid|string|null $node = null): TimeBasedUuidFactory
    {
        if (\is_string($node ??= $this->timeBasedNode)) {
            $node = Uuid::fromString($node);
        }

        return new class($this->create(...), $node) extends TimeBasedUuidFactory {
            public function __construct(
                private \Closure $create,
                private ?Uuid $node = null,
            ) {
            }

            public function create(?\DateTimeInterface $time = null): Uuid&TimeBasedUidInterface
            {
                if (!($uuid = ($this->create)()) instanceof TimeBasedUidInterface) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence is not a TimeBasedUidInterface: "%s" given.', get_debug_type($uuid)));
                }

                if (null !== $time && $uuid->getDateTime() !== $time) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence does not match the expected time: "%s" != "%s".', $uuid->getDateTime()->format('@U.uT'), $time->format('@U.uT')));
                }

                if (!$uuid instanceof UuidV1 && !$uuid instanceof UuidV6 && !$uuid instanceof UuidV7) {
                    return $uuid;
                }

                if (null !== $this->node && ($uuid instanceof UuidV1 || $uuid instanceof UuidV6) && $uuid->getNode() !== substr($this->node->toRfc4122(), -12)) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence does not match the expected node: "%s" != "%s".', $uuid->getNode(), substr($this->node->toRfc4122(), -12)));
                }

                return $uuid;
            }
        };
    }

    public function nameBased(Uuid|string|null $namespace = null): NameBasedUuidFactory
    {
        if (null === $namespace ??= $this->nameBasedNamespace) {
            throw new LogicException(\sprintf('A namespace should be defined when using "%s()".', __METHOD__));
        }

        return new class($this->create(...), $namespace) extends NameBasedUuidFactory {
            public function __construct(
                private \Closure $create,
                private Uuid|string $namespace,
            ) {
            }


Review comment (suggestion):
then the check below can be simplified:
```suggestion
                if (!$uuid instanceof UuidV1 && !$uuid instanceof UuidV6) {
```

Code after:

    public function timeBased(Uuid|string|null $node = null): TimeBasedUuidFactory
    {
        if (\is_string($node ??= $this->timeBasedNode)) {
            $node = Uuid::fromString($node);
        }

        return new class($this->create(...), $node) extends TimeBasedUuidFactory {
            public function __construct(
                private \Closure $create,
                private ?Uuid $node = null,
            ) {
            }

            public function create(?\DateTimeInterface $time = null): Uuid&TimeBasedUidInterface
            {
                $uuid = ($this->create)();

                if (!($uuid instanceof Uuid && $uuid instanceof TimeBasedUidInterface)) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence is not a Uuid and TimeBasedUidInterface: "%s" given.', get_debug_type($uuid)));
                }

                if (null !== $time && $uuid->getDateTime() !== $time) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence does not match the expected time: "%s" != "%s".', $uuid->getDateTime()->format('@U.uT'), $time->format('@U.uT')));
                }

                if (null !== $this->node && ($uuid instanceof UuidV1 || $uuid instanceof UuidV6) && $uuid->getNode() !== substr($this->node->toRfc4122(), -12)) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence does not match the expected node: "%s" != "%s".', $uuid->getNode(), substr($this->node->toRfc4122(), -12)));
                }

                return $uuid;
            }
        };
    }

    public function nameBased(Uuid|string|null $namespace = null): NameBasedUuidFactory
    {
        if (null === $namespace ??= $this->nameBasedNamespace) {
            throw new LogicException(\sprintf('A namespace should be defined when using "%s()".', __METHOD__));
        }

        return new class($this->create(...), $namespace) extends NameBasedUuidFactory {
            public function __construct(
                private \Closure $create,
                private Uuid|string $namespace,
            ) {
            }

            public function create(string $name): UuidV5|UuidV3
            {
                if (!($uuid = ($this->create)()) instanceof UuidV5 && !$uuid instanceof UuidV3) {