Skip to content

Commit 345056c

Browse files
committed
Include doc comments for stub generation
1 parent 7a56715 commit 345056c

5 files changed

Lines changed: 116 additions & 41 deletions

File tree

classes/Types.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ ZEND_ARG_OBJ_INFO(0, buffer, pmmp\\encoding\\ByteBufferWriter, 0)
3636
ZEND_ARG_ARRAY_INFO(0, values, 0)
3737
ZEND_END_ARG_INFO()
3838

39+
static const char* read_int_array_doc_comment = "/**\n\t * @return int[]\n\t * @phpstan-return list<int>\n\t */";
40+
static const char* read_float_array_doc_comment = "/**\n\t * @return float[]\n\t * @phpstan-return list<float>\n\t */";
41+
static const char* write_int_array_doc_comment = "/**\n\t * @param int[] $values\n\t * @phpstan-param list<int> $values\n\t */";
42+
static const char* write_float_array_doc_comment = "/**\n\t * @param float[] $values\n\t * @phpstan-param list<float> $values\n\t */";
43+
3944
template<typename TValue>
4045
static inline void zval_long_wrapper(zval* zv, TValue value) {
4146
ZVAL_LONG(zv, value);
@@ -246,8 +251,10 @@ ZEND_NAMED_FUNCTION(pmmp_encoding_private_constructor) {
246251

247252
#if PHP_VERSION_ID >= 80400
248253
#define BC_ZEND_RAW_FENTRY(zend_name, name, arg_info) ZEND_RAW_FENTRY(zend_name, name, arg_info, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC, NULL, NULL)
254+
#define BC_ZEND_RAW_FENTRY_WITH_DOC_COMMENT(zend_name, name, arg_info, doc_comment) ZEND_RAW_FENTRY(zend_name, name, arg_info, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC, NULL, doc_comment)
249255
#else
250256
#define BC_ZEND_RAW_FENTRY(zend_name, name, arg_info) ZEND_RAW_FENTRY(zend_name, name, arg_info, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
257+
#define BC_ZEND_RAW_FENTRY_WITH_DOC_COMMENT(zend_name, name, arg_info, doc_comment) ZEND_RAW_FENTRY(zend_name, name, arg_info, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
251258
#endif
252259

253260
#define TYPE_ENTRIES(zend_name, native_type, read_type, read_result_wrapper, arg_info_read, write_parameter_wrapper, write_type, arg_info_write) \
@@ -275,43 +282,49 @@ ZEND_NAMED_FUNCTION(pmmp_encoding_private_constructor) {
275282
arg_info_write \
276283
)
277284

278-
#define TYPE_ARRAY_ENTRIES(zend_name, native_type, read_complex_type, read_result_wrapper, write_parameter_wrapper, write_complex_type) \
279-
BC_ZEND_RAW_FENTRY( \
285+
#define TYPE_ARRAY_ENTRIES(zend_name, native_type, read_doc_comment, read_complex_type, read_result_wrapper, write_doc_comment, write_parameter_wrapper, write_complex_type) \
286+
BC_ZEND_RAW_FENTRY_WITH_DOC_COMMENT( \
280287
"read" zend_name "Array", \
281288
(zif_readTypeArray<native_type, read_complex_type, read_result_wrapper<native_type>>), \
282-
arginfo_read_array \
289+
arginfo_read_array, \
290+
read_doc_comment \
283291
) \
284292
\
285-
BC_ZEND_RAW_FENTRY( \
293+
BC_ZEND_RAW_FENTRY_WITH_DOC_COMMENT( \
286294
"write" zend_name "Array", \
287295
(zif_writeTypeArray<native_type, write_parameter_wrapper<native_type>, write_complex_type>), \
288-
arginfo_write_array \
296+
arginfo_write_array, \
297+
write_doc_comment \
289298
)
290299

291-
#define FIXED_TYPE_ARRAY_ENTRIES(zend_name, native_type, read_result_wrapper, write_parameter_wrapper, byte_order) \
300+
#define FIXED_TYPE_ARRAY_ENTRIES(zend_name, native_type, read_doc_comment, read_result_wrapper, write_doc_comment, write_parameter_wrapper, byte_order) \
292301
TYPE_ARRAY_ENTRIES( \
293302
zend_name, \
294303
native_type, \
304+
read_doc_comment, \
295305
(readFixedSizeTypeArray<native_type, byte_order>), \
296306
read_result_wrapper, \
307+
write_doc_comment, \
297308
write_parameter_wrapper, \
298309
(writeFixedSizeTypeArray<native_type, byte_order>) \
299310
)
300311

301-
#define COMPLEX_TYPE_ARRAY_ENTRIES(zend_name, native_type, read_element, read_result_wrapper, write_parameter_wrapper, write_element) \
312+
#define COMPLEX_TYPE_ARRAY_ENTRIES(zend_name, native_type, read_doc_comment, read_element, read_result_wrapper, write_doc_comment, write_parameter_wrapper, write_element) \
302313
TYPE_ARRAY_ENTRIES( \
303314
zend_name, \
304315
native_type, \
316+
read_doc_comment, \
305317
(readComplexTypeArray<native_type, read_element>), \
306318
read_result_wrapper, \
319+
write_doc_comment, \
307320
write_parameter_wrapper, \
308321
(writeComplexTypeArray<native_type, write_element>) \
309322
)
310323

311324
#define FIXED_INT_BASE_ENTRIES(zend_name, native_type, byte_order) \
312325
FIXED_TYPE_ENTRIES(zend_name, native_type, zend_parse_parameters_long_wrapper, zval_long_wrapper, arginfo_read_integer, arginfo_write_integer, byte_order) \
313326
\
314-
FIXED_TYPE_ARRAY_ENTRIES(zend_name, native_type, return_long_array, zend_parse_parameters_long_array_wrapper, byte_order)
327+
FIXED_TYPE_ARRAY_ENTRIES(zend_name, native_type, read_int_array_doc_comment, return_long_array, write_int_array_doc_comment, zend_parse_parameters_long_array_wrapper, byte_order)
315328

316329
#define FIXED_INT_ENTRIES(zend_name, unsigned_native_type, signed_native_type, byte_order) \
317330
FIXED_INT_BASE_ENTRIES("Unsigned" zend_name, unsigned_native_type, byte_order) \
@@ -320,7 +333,7 @@ ZEND_NAMED_FUNCTION(pmmp_encoding_private_constructor) {
320333

321334
#define FLOAT_ENTRIES(zend_name, native_type, byte_order) \
322335
FIXED_TYPE_ENTRIES(zend_name, native_type, zend_parse_parameters_double_wrapper, zval_double_wrapper, arginfo_read_float, arginfo_write_float, byte_order) \
323-
FIXED_TYPE_ARRAY_ENTRIES(zend_name, native_type, return_double_array, zend_parse_parameters_double_array_wrapper, byte_order)
336+
FIXED_TYPE_ARRAY_ENTRIES(zend_name, native_type, read_float_array_doc_comment, return_double_array, write_float_array_doc_comment, zend_parse_parameters_double_array_wrapper, byte_order)
324337

325338
#define COMPLEX_INT_ENTRIES(zend_name, native_type, read_type, write_type) \
326339
TYPE_ENTRIES( \
@@ -336,8 +349,10 @@ ZEND_NAMED_FUNCTION(pmmp_encoding_private_constructor) {
336349
COMPLEX_TYPE_ARRAY_ENTRIES( \
337350
zend_name, \
338351
native_type, \
352+
read_int_array_doc_comment, \
339353
read_type, \
340354
return_long_array, \
355+
write_int_array_doc_comment, \
341356
zend_parse_parameters_long_array_wrapper, \
342357
write_type \
343358
)

stubs/ByteBufferReader.stub.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@
1111
* @strict-properties
1212
*/
1313
final class ByteBufferReader{
14-
/**
14+
/** @genstubs-expose-comment-block
1515
* Constructs a new ByteBufferReader.
1616
* Offset will be initialized to 0.
1717
*/
1818
public function __construct(string $data){}
1919

20-
/**
20+
/** @genstubs-expose-comment-block
2121
* Returns the string (byte array) that the reader is reading.
2222
*/
2323
public function getData() : string{}
2424

25-
/**
25+
/** @genstubs-expose-comment-block
2626
* Reads $length raw bytes from the buffer at the current offset.
2727
* The internal offset will be updated by this operation.
2828
*
2929
* @throws DataDecodeException if there are not enough bytes available
3030
*/
3131
public function readByteArray(int $length) : string{}
3232

33-
/**
33+
/** @genstubs-expose-comment-block
3434
* Returns the current internal read offset (the position
3535
* from which the next read operation will start).
3636
*/
3737
public function getOffset() : int{}
3838

39-
/**
39+
/** @genstubs-expose-comment-block
4040
* Sets the internal read offset to the given value.
4141
* The offset must be within the bounds of the buffer
4242
* (0 <= offset <= used length).

stubs/ByteBufferReader_arginfo.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 8f3830b90fe252e654ecab89c16f352e654505f8 */
2+
* Stub hash: cf60f8c040fc3c12584760bd1db045b054100c6b */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_pmmp_encoding_ByteBufferReader___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
@@ -38,11 +38,31 @@ ZEND_METHOD(pmmp_encoding_ByteBufferReader, __unserialize);
3838
ZEND_METHOD(pmmp_encoding_ByteBufferReader, __debugInfo);
3939

4040
static const zend_function_entry class_pmmp_encoding_ByteBufferReader_methods[] = {
41-
ZEND_ME(pmmp_encoding_ByteBufferReader, __construct, arginfo_class_pmmp_encoding_ByteBufferReader___construct, ZEND_ACC_PUBLIC)
42-
ZEND_ME(pmmp_encoding_ByteBufferReader, getData, arginfo_class_pmmp_encoding_ByteBufferReader_getData, ZEND_ACC_PUBLIC)
43-
ZEND_ME(pmmp_encoding_ByteBufferReader, readByteArray, arginfo_class_pmmp_encoding_ByteBufferReader_readByteArray, ZEND_ACC_PUBLIC)
44-
ZEND_ME(pmmp_encoding_ByteBufferReader, getOffset, arginfo_class_pmmp_encoding_ByteBufferReader_getOffset, ZEND_ACC_PUBLIC)
45-
ZEND_ME(pmmp_encoding_ByteBufferReader, setOffset, arginfo_class_pmmp_encoding_ByteBufferReader_setOffset, ZEND_ACC_PUBLIC)
41+
#if (PHP_VERSION_ID >= 80400)
42+
ZEND_RAW_FENTRY("__construct", zim_pmmp_encoding_ByteBufferReader___construct, arginfo_class_pmmp_encoding_ByteBufferReader___construct, ZEND_ACC_PUBLIC, NULL, "/**\n * Constructs a new ByteBufferReader.\n * Offset will be initialized to 0.\n */")
43+
#else
44+
ZEND_RAW_FENTRY("__construct", zim_pmmp_encoding_ByteBufferReader___construct, arginfo_class_pmmp_encoding_ByteBufferReader___construct, ZEND_ACC_PUBLIC)
45+
#endif
46+
#if (PHP_VERSION_ID >= 80400)
47+
ZEND_RAW_FENTRY("getData", zim_pmmp_encoding_ByteBufferReader_getData, arginfo_class_pmmp_encoding_ByteBufferReader_getData, ZEND_ACC_PUBLIC, NULL, "/**\n * Returns the string (byte array) that the reader is reading.\n */")
48+
#else
49+
ZEND_RAW_FENTRY("getData", zim_pmmp_encoding_ByteBufferReader_getData, arginfo_class_pmmp_encoding_ByteBufferReader_getData, ZEND_ACC_PUBLIC)
50+
#endif
51+
#if (PHP_VERSION_ID >= 80400)
52+
ZEND_RAW_FENTRY("readByteArray", zim_pmmp_encoding_ByteBufferReader_readByteArray, arginfo_class_pmmp_encoding_ByteBufferReader_readByteArray, ZEND_ACC_PUBLIC, NULL, "/**\n * Reads $length raw bytes from the buffer at the current offset.\n * The internal offset will be updated by this operation.\n *\n * @throws DataDecodeException if there are not enough bytes available\n */")
53+
#else
54+
ZEND_RAW_FENTRY("readByteArray", zim_pmmp_encoding_ByteBufferReader_readByteArray, arginfo_class_pmmp_encoding_ByteBufferReader_readByteArray, ZEND_ACC_PUBLIC)
55+
#endif
56+
#if (PHP_VERSION_ID >= 80400)
57+
ZEND_RAW_FENTRY("getOffset", zim_pmmp_encoding_ByteBufferReader_getOffset, arginfo_class_pmmp_encoding_ByteBufferReader_getOffset, ZEND_ACC_PUBLIC, NULL, "/**\n * Returns the current internal read offset (the position\n * from which the next read operation will start).\n */")
58+
#else
59+
ZEND_RAW_FENTRY("getOffset", zim_pmmp_encoding_ByteBufferReader_getOffset, arginfo_class_pmmp_encoding_ByteBufferReader_getOffset, ZEND_ACC_PUBLIC)
60+
#endif
61+
#if (PHP_VERSION_ID >= 80400)
62+
ZEND_RAW_FENTRY("setOffset", zim_pmmp_encoding_ByteBufferReader_setOffset, arginfo_class_pmmp_encoding_ByteBufferReader_setOffset, ZEND_ACC_PUBLIC, NULL, "/**\n * Sets the internal read offset to the given value.\n * The offset must be within the bounds of the buffer\n * (0 <= offset <= used length).\n *\n * @throws \\ValueError if the offset is out of bounds\n */")
63+
#else
64+
ZEND_RAW_FENTRY("setOffset", zim_pmmp_encoding_ByteBufferReader_setOffset, arginfo_class_pmmp_encoding_ByteBufferReader_setOffset, ZEND_ACC_PUBLIC)
65+
#endif
4666
ZEND_ME(pmmp_encoding_ByteBufferReader, __serialize, arginfo_class_pmmp_encoding_ByteBufferReader___serialize, ZEND_ACC_PUBLIC)
4767
ZEND_ME(pmmp_encoding_ByteBufferReader, __unserialize, arginfo_class_pmmp_encoding_ByteBufferReader___unserialize, ZEND_ACC_PUBLIC)
4868
ZEND_ME(pmmp_encoding_ByteBufferReader, __debugInfo, arginfo_class_pmmp_encoding_ByteBufferReader___debugInfo, ZEND_ACC_PUBLIC)

stubs/ByteBufferWriter.stub.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
* @strict-properties
1212
*/
1313
final class ByteBufferWriter{
14-
/**
14+
/** @genstubs-expose-comment-block
1515
* Constructs a new ByteBufferWriter.
1616
* The provided string will be written at the start of the buffer as if readByteArray() was called.
1717
*/
1818
public function __construct(string $prefix = ""){}
1919

20-
/**
20+
/** @genstubs-expose-comment-block
2121
* Returns a string containing the written bytes.
2222
* Reserved memory is not included.
2323
*/
2424
public function getData() : string{}
2525

26-
/**
26+
/** @genstubs-expose-comment-block
2727
* Writes the given bytes to the buffer at the current offset.
2828
* The internal offset will be updated by this operation.
2929
*
@@ -34,13 +34,13 @@ public function getData() : string{}
3434
*/
3535
public function writeByteArray(string $value) : void{}
3636

37-
/**
37+
/** @genstubs-expose-comment-block
3838
* Returns the current internal write offset (the position
3939
* from which the next write operation will start).
4040
*/
4141
public function getOffset() : int{}
4242

43-
/**
43+
/** @genstubs-expose-comment-block
4444
* Sets the internal write offset to the given value.
4545
* The offset must be within the bounds of the buffer
4646
* (0 <= offset <= reserved length).
@@ -49,34 +49,34 @@ public function getOffset() : int{}
4949
*/
5050
public function setOffset(int $offset) : void{}
5151

52-
/**
52+
/** @genstubs-expose-comment-block
5353
* Returns the total number of bytes written.
5454
* This will always be less than or equal to the reserved length.
5555
*/
5656
public function getUsedLength() : int{}
5757

58-
/**
58+
/** @genstubs-expose-comment-block
5959
* Returns the number of bytes reserved by the ByteBuffer.
6060
* This value may be larger than the number of written bytes, as
6161
* some memory may be preallocated to avoid reallocations.
6262
*/
6363
public function getReservedLength() : int{}
6464

65-
/**
65+
/** @genstubs-expose-comment-block
6666
* Increases buffer capacity to the given value, if the capacity
6767
* is less than this amount. Useful to avoid extra reallocations
6868
* during large write operations when the needed capacity of the
6969
* buffer is known in advance.
7070
*/
7171
public function reserve(int $length) : void{}
7272

73-
/**
73+
/** @genstubs-expose-comment-block
7474
* Truncates the internal buffer to only the written part,
7575
* discarding any unused reserved memory.
7676
*/
7777
public function trim() : void{}
7878

79-
/**
79+
/** @genstubs-expose-comment-block
8080
* Clears all data from the buffer. The memory used is retained
8181
* as reserved memory.
8282
*/

0 commit comments

Comments
 (0)