{"record":{"id":"097c42898fc4623f","repo":"ramsey/uuid","slug":"fields-used-to-create-a-uuidv1-must-represent-a-ve","errorCode":null,"errorMessage":"Fields used to create a UuidV1 must represent a version 1 (time-based) UUID","messagePattern":"Fields used to create a UuidV1 must represent a version 1 \\(time-based\\) UUID","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Rfc4122/UuidV1.php","lineNumber":51,"sourceCode":"    use TimeTrait;\n\n    /**\n     * Creates a version 1 (Gregorian time) UUID\n     *\n     * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID\n     * @param NumberConverterInterface $numberConverter The number converter to use for converting hex values to/from integers\n     * @param CodecInterface $codec The codec to use when encoding or decoding UUID strings\n     * @param TimeConverterInterface $timeConverter The time converter to use for converting timestamps extracted from a\n     *     UUID to unix timestamps\n     */\n    public function __construct(\n        Rfc4122FieldsInterface $fields,\n        NumberConverterInterface $numberConverter,\n        CodecInterface $codec,\n        TimeConverterInterface $timeConverter,\n    ) {\n        if ($fields->getVersion() !== Uuid::UUID_TYPE_TIME) {\n            throw new InvalidArgumentException(\n                'Fields used to create a UuidV1 must represent a version 1 (time-based) UUID',\n            );\n        }\n\n        parent::__construct($fields, $numberConverter, $codec, $timeConverter);\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":59,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Rfc4122/UuidV1.php#L33-L59","documentation":"Rfc4122\\UuidV1's constructor verifies that the given fields report version 1 (UUID_TYPE_TIME) before delegating to the parent; fields carrying any other version throw InvalidArgumentException. This keeps the concrete classes internally consistent — a UuidV1 instance must actually be a Gregorian time-based UUID.","triggerScenarios":"Directly calling new UuidV1($fields, $numberConverter, $codec, $timeConverter) with fields whose version nibble is not 1 — e.g. reusing fields decoded from a v4 string, or a DI container/test fixture autowiring the constructor. The factories (Uuid::uuid1(), Uuid::fromString() of a v1 value) never mismatch fields, so this is a manual-construction error.","commonSituations":"Custom codecs/builders that re-wrap fields into a specific version class; code copying the constructor pattern from docs with wrong fields; tests constructing version objects by hand; refactors that mix field sets across versions.","solutions":["Use factories instead: Uuid::uuid1(), or Uuid::fromString() on a known-v1 string, then assert instanceof UuidV1","If constructing manually, feed fields from a genuine v1 UUID (e.g. Uuid::uuid1()->getFields())","Check $fields->getVersion() === Uuid::UUID_TYPE_TIME before invoking the constructor"],"exampleFix":"// before\n$v1 = new \\Ramsey\\Uuid\\Rfc4122\\UuidV1($fields, $nc, $codec, $tc); // $fields is v4\n\n// after\nif ($fields->getVersion() !== \\Ramsey\\Uuid\\Uuid::UUID_TYPE_TIME) {\n    throw new InvalidArgumentException('fields must be version 1');\n}\n$v1 = new \\Ramsey\\Uuid\\Rfc4122\\UuidV1($fields, $nc, $codec, $tc);\n// or simply: $v1 = \\Ramsey\\Uuid\\Uuid::uuid1();","handlingStrategy":"validation","validationCode":"use Ramsey\\Uuid\\Uuid;\nif ($fields->getVersion() !== Uuid::UUID_TYPE_TIME) {\n    throw new InvalidArgumentException('UuidV1 requires version 1 fields');\n}\n$v1 = new \\Ramsey\\Uuid\\Rfc4122\\UuidV1($fields, $numberConverter, $codec, $timeConverter);","typeGuard":"function isVersion1Fields(\\Ramsey\\Uuid\\Rfc4122\\FieldsInterface $fields): bool\n{\n    return $fields->getVersion() === \\Ramsey\\Uuid\\Uuid::UUID_TYPE_TIME;\n}","tryCatchPattern":"try {\n    $v1 = new \\Ramsey\\Uuid\\Rfc4122\\UuidV1($fields, $nc, $codec, $tc);\n} catch (\\Ramsey\\Uuid\\Exception\\InvalidArgumentException $e) {\n    // fields/version mismatch; regenerate a true v1 instead\n    $v1 = \\Ramsey\\Uuid\\Uuid::uuid1();\n}","preventionTips":["Prefer Uuid::uuid1() and Uuid::fromString() over manual construction","When re-wrapping fields, always check getVersion() against the target class's version","Keep one source of truth for which fields feed which version class"],"tags":["php","ramsey-uuid","uuid-v1","argument-validation","manual-construction","rfc-9562"],"backgroundTag":"wrong-uuid-version-for-operation","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}