Skip to content
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

Use return types and phpdoc #178

Closed
wants to merge 11 commits into from
Closed

Conversation

whikloj
Copy link
Collaborator

@whikloj whikloj commented Jul 20, 2023

This is to add some documentation (as I understand it) and types to arguments and functions.

This should have no impact on the code...except possibly for ACK/NACK.

It appears that Apollo sends a "ack" header on MESSAGE frames which is not part of the spec. That seems to have impacted the base Protocol class which was looking for this ack header in the Protocol::getAckFrame function.

Also but unrelated the in Protocol::getNackFrame a message-id header was being sent on all "nack" messages and was overwriting what may have been set previously.

Copy link
Member

@staabm staabm left a comment

Choose a reason for hiding this comment

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

I like adding native types. It will require a new major version I guess, as adding parameter types can be a breaking change for existing code

@whikloj
Copy link
Collaborator Author

whikloj commented Nov 8, 2023

Hey @staabm,

I am good with making a new major release for this change. If you have time to review and merge this, we can cut a 6.0.0 release

@staabm
Copy link
Member

staabm commented Nov 9, 2023

I will have a closer look in the next view days

@staabm
Copy link
Member

staabm commented Nov 10, 2023

to make sure phpstan reports nullability issues we need either raise the phpstan level (which would also bring in a lot of other non-nullability related errors) or we enable nullability checking separately

see https://twitter.com/markusstaab/status/1710201565087256893

@@ -90,11 +90,11 @@ public function testAckVersionTwo()
$instance = $this->getProtocol(Version::VERSION_1_2);

$actual = $instance->getAckFrame(
new Frame(null, ['message-id' => 'id-value', 'ack' => 'ack-id-value']),
Copy link
Member

Choose a reason for hiding this comment

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

are these test-changes related to the type changes, or could be separated because unrelated?

Copy link
Member

@staabm staabm left a comment

Choose a reason for hiding this comment

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

github bug

@@ -149,17 +149,17 @@ public function setObserver(ConnectionObserver $observer)
*
* @return FrameFactory
*/
public function getFactory()
public function getFactory(): ?FrameFactory
Copy link
Member

Choose a reason for hiding this comment

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

the property is not-nullable

Suggested change
public function getFactory(): ?FrameFactory
public function getFactory(): FrameFactory

maybe we should add a native property type (maybe as a followup; and only for private properties)

@@ -46,7 +46,7 @@ function ($command, array $headers, $body) {
* @param boolean $legacyMode stomp 1.0 mode (headers)
* @return Frame
*/
public function createFrame($command, array $headers, $body, $legacyMode)
public function createFrame($command, array $headers, $body, $legacyMode): Frame
Copy link
Member

Choose a reason for hiding this comment

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

adding return type in non-final classes is BC breaking for subclasses -> we really need a new major.

it might be useful to declare some classes final in case we don't want people to subclass them (followup PR)

@@ -363,7 +363,7 @@ protected function getConnection()
*
* @return array
Copy link
Member

Choose a reason for hiding this comment

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

it would be great to add key/value types to array-return types (followup PR)

@@ -199,7 +199,7 @@ public function __construct($brokerUri, $connectionTimeout = 1, array $context =
*
* @param callable|null $waitCallback
Copy link
Member

Choose a reason for hiding this comment

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

having callable signatures would also be awesome (followup PR)

Comment on lines +114 to 120
public function getNackFrame(Frame $frame, ?string $transactionId = null, ?bool $requeue = null): Frame
{
if ($this->getVersion() === Version::VERSION_1_0) {
throw new StompException('Stomp Version 1.0 has no support for NACK Frames.');
}
$nack = $this->createFrame('NACK');
$nack = parent::getNackFrame($frame, $transactionId);
if ($requeue !== null) {
$nack->addHeaders(['requeue' => $requeue ? 'true' : 'false']);
}
$nack['transaction'] = $transactionId;
if ($this->hasVersion(Version::VERSION_1_2)) {
$nack['id'] = $frame->getMessageId();
} else {
$nack['message-id'] = $frame->getMessageId();
if ($this->hasVersion(Version::VERSION_1_1)) {
$nack['subscription'] = $frame['subscription'];
}
}

$nack['message-id'] = $frame->getMessageId();
return $nack;
Copy link
Member

Choose a reason for hiding this comment

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

this looks like a change which should be done in a separate PR?
(without the type additions)

@whikloj
Copy link
Collaborator Author

whikloj commented Nov 10, 2023

What I discovered when starting this is that almost everything allowed null, because null gets passed around as defaults and in tests.

Adding types caused these nulls to cause errors so tests and codestyle and phpstan would not pass.

So I'm going to close this and consider removing all the uses of/acceptance of null first.

Then try types again. I will consider the other comments in the other PRs

@whikloj whikloj closed this Nov 10, 2023
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

2 participants