@@ -1987,6 +1987,15 @@ private function normalizeCollectionAttributeSizes(Document $collection): Docume
19871987 return $ collection ;
19881988 }
19891989
1990+ private function getSize (string $ type , int |string |null $ size ): int |string
1991+ {
1992+ if ($ type === self ::VAR_BIGINT ) {
1993+ return (string )($ size ?? 0 );
1994+ }
1995+
1996+ return (int )($ size ?? 0 );
1997+ }
1998+
19901999 /**
19912000 * Get Collection Size
19922001 *
@@ -2146,8 +2155,9 @@ public function deleteCollection(string $id): bool
21462155 * @throws StructureException
21472156 * @throws Exception
21482157 */
2149- public function createAttribute (string $ collection , string $ id , string $ type , int $ size , bool $ required , mixed $ default = null , bool $ signed = true , bool $ array = false , ?string $ format = null , array $ formatOptions = [], array $ filters = []): bool
2158+ public function createAttribute (string $ collection , string $ id , string $ type , int | string $ size , bool $ required , mixed $ default = null , bool $ signed = true , bool $ array = false , ?string $ format = null , array $ formatOptions = [], array $ filters = []): bool
21502159 {
2160+ $ size = $ this ->getSize ($ type , $ size );
21512161 $ collection = $ this ->silent (fn () => $ this ->getCollection ($ collection ));
21522162
21532163 if ($ collection ->isEmpty ()) {
@@ -2231,7 +2241,7 @@ public function createAttribute(string $collection, string $id, string $type, in
22312241 '$id ' => ID ::custom ($ id ),
22322242 'key ' => $ id ,
22332243 'type ' => $ type ,
2234- 'size ' => $ type === self :: VAR_BIGINT ? ( string ) $ size : $ size ,
2244+ 'size ' => $ this -> getSize ( $ type , $ size) ,
22352245 'required ' => $ required ,
22362246 'default ' => $ default ,
22372247 'signed ' => $ signed ,
@@ -2355,6 +2365,7 @@ public function createAttributes(string $collection, array $attributes): bool
23552365 $ existsInSchema = false ;
23562366
23572367 try {
2368+ $ attribute ['size ' ] = $ this ->getSize ($ attribute ['type ' ], $ attribute ['size ' ]);
23582369 $ attributeDocument = $ this ->validateAttribute (
23592370 $ collection ,
23602371 $ attribute ['$id ' ],
@@ -2411,7 +2422,7 @@ public function createAttributes(string $collection, array $attributes): bool
24112422 '$id ' => ID ::custom ($ attribute ['$id ' ]),
24122423 'key ' => $ attribute ['$id ' ],
24132424 'type ' => $ attribute ['type ' ],
2414- 'size ' => $ attribute ['size ' ],
2425+ 'size ' => $ this -> getSize ( $ attribute ['type ' ], $ attribute [ ' size ' ]) ,
24152426 'required ' => $ attribute ['required ' ],
24162427 'default ' => $ attribute ['default ' ],
24172428 'signed ' => $ attribute ['signed ' ],
@@ -2514,7 +2525,7 @@ private function validateAttribute(
25142525 Document $ collection ,
25152526 string $ id ,
25162527 string $ type ,
2517- int $ size ,
2528+ int | string $ size ,
25182529 bool $ required ,
25192530 mixed $ default ,
25202531 bool $ signed ,
@@ -2528,7 +2539,7 @@ private function validateAttribute(
25282539 '$id ' => ID ::custom ($ id ),
25292540 'key ' => $ id ,
25302541 'type ' => $ type ,
2531- 'size ' => $ type === self :: VAR_BIGINT ? ( string ) $ size : $ size ,
2542+ 'size ' => $ this -> getSize ( $ type , $ size) ,
25322543 'required ' => $ required ,
25332544 'default ' => $ default ,
25342545 'signed ' => $ signed ,
@@ -2870,7 +2881,7 @@ public function updateAttributeDefault(string $collection, string $id, mixed $de
28702881 * @return Document
28712882 * @throws Exception
28722883 */
2873- public function updateAttribute (string $ collection , string $ id , ?string $ type = null , ? int $ size = null , ?bool $ required = null , mixed $ default = null , ?bool $ signed = null , ?bool $ array = null , ?string $ format = null , ?array $ formatOptions = null , ?array $ filters = null , ?string $ newKey = null ): Document
2884+ public function updateAttribute (string $ collection , string $ id , ?string $ type = null , int | string | null $ size = null , ?bool $ required = null , mixed $ default = null , ?bool $ signed = null , ?bool $ array = null , ?string $ format = null , ?array $ formatOptions = null , ?array $ filters = null , ?string $ newKey = null ): Document
28742885 {
28752886 $ collectionDoc = $ this ->silent (fn () => $ this ->getCollection ($ collection ));
28762887
@@ -2906,6 +2917,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
29062917 || !\is_null ($ newKey );
29072918 $ type ??= $ attribute ->getAttribute ('type ' );
29082919 $ size ??= $ attribute ->getAttribute ('size ' );
2920+ $ size = $ this ->getSize ($ type , $ size );
29092921 $ signed ??= $ attribute ->getAttribute ('signed ' );
29102922 $ required ??= $ attribute ->getAttribute ('required ' );
29112923 $ default ??= $ attribute ->getAttribute ('default ' );
@@ -3070,7 +3082,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
30703082 ->setAttribute ('$id ' , $ newKey ?? $ id )
30713083 ->setattribute ('key ' , $ newKey ?? $ id )
30723084 ->setAttribute ('type ' , $ type )
3073- ->setAttribute ('size ' , $ type === self :: VAR_BIGINT ? ( string ) $ size : $ size )
3085+ ->setAttribute ('size ' , $ this -> getSize ( $ type , $ size) )
30743086 ->setAttribute ('signed ' , $ signed )
30753087 ->setAttribute ('array ' , $ array )
30763088 ->setAttribute ('format ' , $ format )
@@ -3194,7 +3206,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
31943206 $ collection ,
31953207 $ newKey ?? $ id ,
31963208 $ originalType ,
3197- $ originalSize ,
3209+ ( int ) $ originalSize ,
31983210 $ originalSigned ,
31993211 $ originalArray ,
32003212 $ originalKey ,
0 commit comments