Skip to content

Add int ranges to AMQP typings #3146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

ben-challis
Copy link
Contributor

@ben-challis ben-challis commented Jun 10, 2024

I haven't changed the setters as this is more of an annoyance to call site. It will trigger a runtime error if out of bounds. Happy to update setters as well if preferred!

@@ -72,10 +72,10 @@
'AMQPChannel::__construct' => ['void', 'connection'=>'AMQPConnection'],
'AMQPChannel::basicRecover' => ['void', 'requeue='=>'bool'],
'AMQPChannel::commitTransaction' => ['void'],
'AMQPChannel::getChannelId' => ['int'],
'AMQPChannel::getChannelId' => ['int<1,65535>'],
Copy link
Contributor Author

@ben-challis ben-challis Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is defined as a 16bit unsigned int in the spec, but setting to 0 triggers an error always, so cannot be returned from the getter.

'AMQPChannel::getConnection' => ['AMQPConnection'],
'AMQPChannel::getPrefetchCount' => ['int'],
'AMQPChannel::getPrefetchSize' => ['int'],
'AMQPChannel::getPrefetchCount' => ['int<0,65535>'],
Copy link
Contributor Author

@ben-challis ben-challis Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly a 16bit unsigned int, zero signifies no prefetch.

'AMQPChannel::getPrefetchCount' => ['int'],
'AMQPChannel::getPrefetchSize' => ['int'],
'AMQPChannel::getPrefetchCount' => ['int<0,65535>'],
'AMQPChannel::getPrefetchSize' => ['int<0,max>'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Octets, zero signifying maximum possible.

@@ -87,12 +87,12 @@
'AMQPConnection::disconnect' => ['void'],
'AMQPConnection::getHost' => ['string'],
'AMQPConnection::getLogin' => ['string'],
'AMQPConnection::getMaxChannels' => ['int'],
'AMQPConnection::getMaxChannels' => ['int<1,65535>'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, a channel of 0 is invalid, despite being a 16bit unsigned int.

@@ -121,7 +121,7 @@
'AMQPEnvelope::getHeader' => ['mixed', 'headerName'=>'string'],
'AMQPEnvelope::getHeaders' => ['array<string,mixed>'],
'AMQPEnvelope::getMessageId' => ['string|null'],
'AMQPEnvelope::getPriority' => ['int'],
'AMQPEnvelope::getPriority' => ['int<0,max>'],
Copy link
Contributor Author

@ben-challis ben-challis Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMQP spec defines that a priority MAY be 0-10, where 0 is "default". Above 10 is undefined. RabbitMQ supports up to 255, this value is capped to the maximum supported by the queue, hence leaving it leniant.

@thg2k
Copy link
Contributor

thg2k commented Jun 11, 2024

@ondrejmirtes Can we have some coding style directives on the function map signatures? I always use int<0, max> (with space) as I find it more readable and it matches the official describe of the type, but if you prefer it without space it's also fine. As long as we use the same style in the whole file.

Maybe we add a couple of lines on top of the file saying this? I also would like to see a specification on whether to use int<1, max> or positive-int. To be onest, I prefer the former as with the latter I always wonder if zero is included or not.

@ondrejmirtes ondrejmirtes merged commit 601995d into phpstan:1.11.x Jun 11, 2024
220 of 221 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@ondrejmirtes
Copy link
Member

Can we have some coding style directives

I don't care too much about formatting inside these types. Whatever works, use that :)

@ben-challis ben-challis deleted the int-ranges-amqp branch June 11, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants