Skip to content

Commit 9b81f8a

Browse files
committed
Fix EventStream toString() / hashCode() / compareTo()
1 parent cb6b881 commit 9b81f8a

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Model Context Protocol change log
33

44
## ?.?.? / ????-??-??
55

6+
* Fixed `io.modelcontextprotocol.EventStream` implementation when
7+
given input stream does not also implement `lang.Value`
8+
(@thekid)
69
* Fixed initialization being rerun on first call when invoking the
710
`initialize()` method manually
811
(@thekid)

src/main/php/io/modelcontextprotocol/EventStream.class.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Traversable;
44
use io\streams\{InputStream, StringReader};
55
use text\json\StringInput;
6+
use util\Objects;
67

78
/** @test io.modelcontextprotocol.unittest.EventStreamTest */
89
class EventStream extends Outcome {
@@ -37,10 +38,10 @@ public function value() {
3738
}
3839

3940
/** @return string */
40-
public function toString() { return nameof($this).'('.$this->stream->toString().')'; }
41+
public function toString() { return nameof($this).'('.Objects::stringOf($this->stream).')'; }
4142

4243
/** @return string */
43-
public function hashCode() { return 'S'.$this->stream->hashCode(); }
44+
public function hashCode() { return 'S'.Objects::hashOf($this->stream); }
4445

4546
/**
4647
* Comparison
@@ -50,7 +51,7 @@ public function hashCode() { return 'S'.$this->stream->hashCode(); }
5051
*/
5152
public function compareTo($value) {
5253
return $value instanceof self
53-
? $this->stream->compareTo($value->stream)
54+
? Objects::compare($this->stream, $value->stream)
5455
: 1
5556
;
5657
}

0 commit comments

Comments
 (0)