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

Code before:
                if (!($uuid = ($this->create)()) instanceof UuidV4) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence is not a UuidV4: "%s" given.', get_debug_type($uuid)));
                }

                return $uuid;
            }
        };
    }

    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__));
        }


Review comment (bug):
to help static analyzers:
```suggestion
                if (!($uuid = ($this->create)()) instanceof TimeBasedUidInterface || !$uuid instanceof Uuid) {
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence is not a TimeBasedUidInterface nor a Uuid: "%s" given.', get_debug_type($uuid)));
```

Code after:
                    throw new InvalidArgumentException(\sprintf('Next UUID in sequence is not a UuidV4: "%s" given.', get_debug_type($uuid)));
                }

                return $uuid;
            }
        };
    }

    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,