entity; } /** @param object|class-string $entity */ public static function lockFailed(object|string $entity): self { return new self('The optimistic lock on an entity failed.', $entity); } public static function lockFailedVersionMismatch( object $entity, int|string|DateTimeInterface $expectedLockVersion, int|string|DateTimeInterface $actualLockVersion, ): self { $expectedLockVersion = $expectedLockVersion instanceof DateTimeInterface ? $expectedLockVersion->getTimestamp() : $expectedLockVersion; $actualLockVersion = $actualLockVersion instanceof DateTimeInterface ? $actualLockVersion->getTimestamp() : $actualLockVersion; return new self('The optimistic lock failed, version ' . $expectedLockVersion . ' was expected, but is actually ' . $actualLockVersion, $entity); } public static function notVersioned(string $entityName): self { return new self('Cannot obtain optimistic lock on unversioned entity ' . $entityName, null); } }