Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ install:
- composer install --prefer-source

script:
- vendor/bin/psalm
- vendor/bin/phpunit
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "queue-interop/queue-interop",
"name": "zoon/queue-interop",
"type": "library",
"description": "Promoting the interoperability of MQs objects. Based on Java JMS",
"description": "Promoting the interoperability of MQs objects. Based on Java JMS, modernized with psalm typehints.",
"keywords": ["messaging", "queue", "jms", "mq", "message queue"],
"homepage": "https://github.com/queue-interop/queue-interop",
"homepage": "https://github.com/zoon/queue-interop",
"license": "MIT",
"require": {
"php": "^7.1.3 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"queue-interop/queue-spec": "^0.6@dev"
"queue-interop/queue-spec": "^0.6@dev",
"vimeo/psalm": "^4.7"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 8 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

interface Context
{
/**
* Create message
*
* @param string $body
* @param array<string, mixed> $properties
* @param array<string, mixed> $headers
* @return Message
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message;

public function createTopic(string $topicName): Topic;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/DeliveryDelayNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DeliveryDelayNotSupportedException extends Exception
*
* @return static
*/
public static function providerDoestNotSupportIt(int $code = 0, \Throwable $previous = null): self
public static function providerDoestNotSupportIt(int $code = 0, ?\Throwable $previous = null): self
{
return new static('The provider does not support delivery delay feature', $code, $previous);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

namespace Interop\Queue\Exception;

/**
* @psalm-consistent-constructor
*/
class Exception extends \Exception implements \Interop\Queue\Exception
{
public function __construct(string $message = "", int $code = 0, ?\Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
4 changes: 4 additions & 0 deletions src/Exception/InvalidDestinationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class InvalidDestinationException extends Exception
* @param mixed $destination
* @param string $class
*
* @template TClass
* @psalm-param class-string<TClass> $class
* @psalm-assert TClass $destination
*
* @throws static
*/
public static function assertDestinationInstanceOf($destination, string $class): void
Expand Down
4 changes: 4 additions & 0 deletions src/Exception/InvalidMessageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class InvalidMessageException extends Exception
* @param Message $message
* @param string $class
*
* @template TClass as Message
* @psalm-param class-string<TClass> $class
* @psalm-assert TClass $message
*
* @throws static
*/
public static function assertMessageInstanceOf(Message $message, string $class): void
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/PriorityNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PriorityNotSupportedException extends Exception
*
* @return static
*/
public static function providerDoestNotSupportIt(int $code = 0, \Throwable $previous = null): self
public static function providerDoestNotSupportIt(int $code = 0, ?\Throwable $previous = null): self
{
return new static('The provider does not support priority feature', $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/PurgeQueueNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PurgeQueueNotSupportedException extends Exception
*
* @return static
*/
public static function providerDoestNotSupportIt(int $code = 0, \Throwable $previous = null): self
public static function providerDoestNotSupportIt(int $code = 0, ?\Throwable $previous = null): self
{
return new static('The provider does not support purge queue.', $code, $previous);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SubscriptionConsumerNotSupportedException extends Exception
*
* @return static
*/
public static function providerDoestNotSupportIt(int $code = 0, \Throwable $previous = null): self
public static function providerDoestNotSupportIt(int $code = 0, ?\Throwable $previous = null): self
{
return new static('The provider does not support subscription consumer.', $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/TemporaryQueueNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TemporaryQueueNotSupportedException extends Exception
*
* @return static
*/
public static function providerDoestNotSupportIt(int $code = 0, \Throwable $previous = null): self
public static function providerDoestNotSupportIt(int $code = 0, ?\Throwable $previous = null): self
{
return new static('The provider does not support temporary queue feature', $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/TimeToLiveNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TimeToLiveNotSupportedException extends Exception
*
* @return static
*/
public static function providerDoestNotSupportIt(int $code = 0, \Throwable $previous = null): self
public static function providerDoestNotSupportIt(int $code = 0, ?\Throwable $previous = null): self
{
return new static('The provider does not support time to live feature', $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Impl/ConsumerVisibilityTimeoutTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getVisibilityTimeout(): ?int
* The duration (in seconds) that the received messages are hidden from subsequent retrieve
* requests after being retrieved by a ReceiveMessage request.
*/
public function setVisibilityTimeout(int $visibilityTimeout = null): void
public function setVisibilityTimeout(?int $visibilityTimeout = null): void
{
$this->visibilityTimeout = $visibilityTimeout;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Impl/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function isRedelivered(): bool
return $this->redelivered;
}

public function setCorrelationId(string $correlationId = null): void
public function setCorrelationId(?string $correlationId = null): void
{
$this->setHeader('correlation_id', $correlationId);
}
Expand All @@ -107,7 +107,7 @@ public function getCorrelationId(): ?string
return $this->getHeader('correlation_id');
}

public function setMessageId(string $messageId = null): void
public function setMessageId(?string $messageId = null): void
{
$this->setHeader('message_id', $messageId);
}
Expand All @@ -124,12 +124,12 @@ public function getTimestamp(): ?int
return null === $value ? null : (int) $value;
}

public function setTimestamp(int $timestamp = null): void
public function setTimestamp(?int $timestamp = null): void
{
$this->setHeader('timestamp', $timestamp);
}

public function setReplyTo(string $replyTo = null): void
public function setReplyTo(?string $replyTo = null): void
{
$this->setHeader('reply_to', $replyTo);
}
Expand Down
60 changes: 56 additions & 4 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,78 @@ public function getBody(): string;

public function setBody(string $body): void;

/**
* Set properties
*
* @param array<string, mixed> $properties
* @return void
*/
public function setProperties(array $properties): void;

/**
* Returns [name => value, ...]
* @return array<string, mixed>
*/
public function getProperties(): array;

/**
* Set property
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setProperty(string $name, $value): void;

/**
* Get property
*
* @param string $name
* @param mixed $default
*
* @return mixed
*
* @template TDefault
* @psalm-param TDefault $default
* @psalm-return TDefault|mixed
*/
public function getProperty(string $name, $default = null);

/**
* Set headers
*
* @param array<string, mixed> $headers
* @return void
*/
public function setHeaders(array $headers): void;

/**
* Returns [name => value, ...]
* @return array<string, mixed>
*/
public function getHeaders(): array;

/**
* Set header
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setHeader(string $name, $value): void;

/**
* Get header
*
* @param string $name
* @param mixed $default
*
* @return mixed
*
* @template TDefault
* @psalm-param TDefault $default
* @psalm-return TDefault|mixed
*/
public function getHeader(string $name, $default = null);

public function setRedelivered(bool $redelivered): void;
Expand All @@ -57,7 +109,7 @@ public function isRedelivered(): bool;
* A client can use the correlation header field to link one message with another.
* A typical use is to link a response message with its request message.
*/
public function setCorrelationId(string $correlationId = null): void;
public function setCorrelationId(?string $correlationId = null): void;

/**
* Gets the correlation ID for the message.
Expand All @@ -71,7 +123,7 @@ public function getCorrelationId(): ?string;
* Providers set this field when a message is sent.
* This method can be used to change the value for a message that has been received.
*/
public function setMessageId(string $messageId = null): void;
public function setMessageId(?string $messageId = null): void;

/**
* Gets the message Id.
Expand All @@ -94,7 +146,7 @@ public function getTimestamp(): ?int;
* Providers set this field when a message is sent.
* This method can be used to change the value for a message that has been received.
*/
public function setTimestamp(int $timestamp = null): void;
public function setTimestamp(?int $timestamp = null): void;

/**
* Sets the destination to which a reply to this message should be sent.
Expand All @@ -108,7 +160,7 @@ public function setTimestamp(int $timestamp = null): void;
* The client can use the CorrelationID header field for this purpose.

*/
public function setReplyTo(string $replyTo = null): void;
public function setReplyTo(?string $replyTo = null): void;

/**
* Gets the destination to which a reply to this message should be sent.
Expand Down
6 changes: 3 additions & 3 deletions src/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function send(Destination $destination, Message $message): void;
*
* @throws DeliveryDelayNotSupportedException if producer does not support delivery delay feature
*/
public function setDeliveryDelay(int $deliveryDelay = null): self;
public function setDeliveryDelay(?int $deliveryDelay = null): self;

/**
* Gets the minimum length of time in milliseconds that must elapse after a message is sent before the provider may deliver the message to a consumer.
Expand All @@ -45,7 +45,7 @@ public function getDeliveryDelay(): ?int;
*
* @throws PriorityNotSupportedException if producer does not support priority feature
*/
public function setPriority(int $priority = null): self;
public function setPriority(?int $priority = null): self;

/**
* Return the priority of messages that are sent using this Producer
Expand All @@ -65,7 +65,7 @@ public function getPriority(): ?int;
*
* @throws TimeToLiveNotSupportedException if producer does not support time to live feature
*/
public function setTimeToLive(int $timeToLive = null): self;
public function setTimeToLive(?int $timeToLive = null): self;

/**
* Returns the time to live of messages that are sent using this JMSProducer.
Expand Down