Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.2", "8.3", "8.4"]
php: ["8.2", "8.3", "8.4", "8.5"]
deps: ["highest"]
include:
- php: "8.2"
Expand Down
45 changes: 45 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* Shared php-cs-fixer configuration for every InitPHP package (ADR-005).
*
* This file is identical in all repositories as `.php-cs-fixer.dist.php`.
* The only package-specific part is the two lines below; scripts/check-cs-config.sh
* ignores exactly those two lines when it compares a package with this template.
* Keep each of them on a single line.
*/
$excludeDirs = [];
$excludePaths = [];

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->name('*.php');

foreach ($excludeDirs as $excludeDir) {
$finder->exclude($excludeDir);
}

foreach ($excludePaths as $excludePath) {
$finder->notPath($excludePath);
}

return (new PhpCsFixer\Config())
->setRiskyAllowed(false)
->setRules([
'@PER-CS' => true,
'@PHP8x2Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],
'single_quote' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'],
],
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache');
22 changes: 0 additions & 22 deletions .php-cs-fixer.php

This file was deleted.

34 changes: 24 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@ All notable changes to `initphp/queue` are documented here. The format is based
on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] — 2.0
## [Unreleased]

### Changed (breaking)

- Code style moved to PER-CS (php-cs-fixer, shared `.php-cs-fixer.dist.php`,
replacing the previous PSR-12 configuration); the codebase has been
reformatted accordingly.
- Requires PHP `^8.2` (unchanged); CI now covers PHP 8.2, 8.3, 8.4 and 8.5.

## [2.1.0] - 2026-06-21

### Added

- **Opt-in idempotent consumption.** A new `IdempotencyStore` contract
(`Contracts/IdempotencyStore.php`) with an in-memory reference implementation
(`InMemoryIdempotencyStore`) lets the `Dispatcher` dedupe at-least-once
redeliveries, processing a message **at most once**. Enable it by passing an
`IdempotencyOptions` to the `Dispatcher`; the dedup key derives from a custom
resolver, the envelope's `meta.id`, or its `trace_id`, and is recorded only
after a handler succeeds (a throwing handler stays retryable). Disabled by
default — existing behaviour is unchanged. Bring a durable, atomic store
(Redis/PDO) for fleet-wide deduplication; see the README.

## [2.0.0] - 2026-06-08

### Changed (breaking)

Expand Down Expand Up @@ -45,12 +68,3 @@ Bugs from `1.x` that no longer exist in the new design:
and **RabbitMQ** (AMQP), each paired with the SDK's publish side.
- A thin `Producer` facade over `EnvelopeCodec` + a `Transport`.
- A `bin/queue` CLI worker entry point.
- **Opt-in idempotent consumption.** A new `IdempotencyStore` contract
(`Contracts/IdempotencyStore.php`) with an in-memory reference implementation
(`InMemoryIdempotencyStore`) lets the `Dispatcher` dedupe at-least-once
redeliveries, processing a message **at most once**. Enable it by passing an
`IdempotencyOptions` to the `Dispatcher`; the dedup key derives from a custom
resolver, the envelope's `meta.id`, or its `trace_id`, and is recorded only
after a handler succeeds (a throwing handler stays retryable). Disabled by
default — existing behaviour is unchanged. Bring a durable, atomic store
(Redis/PDO) for fleet-wide deduplication; see the README.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"mockery/mockery": "^1.6",
"predis/predis": "^2.2",
"php-amqplib/php-amqplib": "^3.5",
"friendsofphp/php-cs-fixer": "^3.65"
"friendsofphp/php-cs-fixer": "^3.88"
},
"suggest": {
"ext-pdo": "Required by the PDO (database-backed) transport.",
Expand Down
3 changes: 1 addition & 2 deletions src/Consumer/Outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ private function __construct(
public readonly OutcomeKind $kind,
public readonly string $reason = '',
public readonly ?Throwable $exception = null,
) {
}
) {}

/** Handled successfully. */
public static function ack(): self
Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/ConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@
* These are bugs to fix in code, not transient runtime failures, so they are
* never retried or dead-lettered — they surface immediately.
*/
final class ConfigurationException extends QueueException
{
}
final class ConfigurationException extends QueueException {}
4 changes: 1 addition & 3 deletions src/Exceptions/QueueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
* `babelqueue/php-sdk` and the runtime (worker, transport, routing) errors
* thrown here.
*/
class QueueException extends BabelQueueException
{
}
class QueueException extends BabelQueueException {}
3 changes: 1 addition & 2 deletions src/Message/ReceivedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function __construct(
private readonly string $rawBody,
private readonly array $envelope,
private readonly mixed $receipt,
) {
}
) {}

/**
* The message URN — its language-agnostic identity. Accepts the inbound
Expand Down
3 changes: 1 addition & 2 deletions src/Producer/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ final class Producer
public function __construct(
private readonly Transport $transport,
private readonly string $defaultQueue = 'default',
) {
}
) {}

/**
* Publish a {@see PolyglotJob}. Its URN and payload come from the job; an
Expand Down
2 changes: 1 addition & 1 deletion tests/Consumer/DispatcherIdempotencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function test_a_custom_key_resolver_overrides_the_default_identity(): voi
$map = (new HandlerMap())->register(self::URN, $handler);
$options = new IdempotencyOptions(
$store,
keyResolver: static fn (ReceivedMessage $m): string => (string) ($m->getData()['order_id'] ?? ''),
keyResolver: static fn(ReceivedMessage $m): string => (string) ($m->getData()['order_id'] ?? ''),
);
$dispatcher = new Dispatcher($map, idempotency: $options);

Expand Down
26 changes: 7 additions & 19 deletions tests/Consumer/WorkerResilienceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private function envelope(): string
public function test_a_reserve_error_is_logged_and_the_loop_keeps_going(): void
{
$events = [];
$transport = new class () implements ConsumerTransport {
$transport = new class implements ConsumerTransport {
public int $reserveCalls = 0;

public function reserve(string $queue, float $timeout = 5.0): ?ReceivedMessage
Expand All @@ -39,17 +39,11 @@ public function reserve(string $queue, float $timeout = 5.0): ?ReceivedMessage
return null;
}

public function ack(ReceivedMessage $message): void
{
}
public function ack(ReceivedMessage $message): void {}

public function release(ReceivedMessage $message, string $payload, int $delaySeconds = 0): void
{
}
public function release(ReceivedMessage $message, string $payload, int $delaySeconds = 0): void {}

public function deadLetter(ReceivedMessage $message, string $payload): void
{
}
public function deadLetter(ReceivedMessage $message, string $payload): void {}
};

$worker = new Worker(
Expand All @@ -74,9 +68,7 @@ public function test_a_processing_error_is_logged_without_crashing_the_worker():
$transport = new class ($this->envelope()) implements ConsumerTransport {
private bool $served = false;

public function __construct(private readonly string $raw)
{
}
public function __construct(private readonly string $raw) {}

public function reserve(string $queue, float $timeout = 5.0): ?ReceivedMessage
{
Expand All @@ -93,13 +85,9 @@ public function ack(ReceivedMessage $message): void
throw new RuntimeException('ack failed');
}

public function release(ReceivedMessage $message, string $payload, int $delaySeconds = 0): void
{
}
public function release(ReceivedMessage $message, string $payload, int $delaySeconds = 0): void {}

public function deadLetter(ReceivedMessage $message, string $payload): void
{
}
public function deadLetter(ReceivedMessage $message, string $payload): void {}
};

$worker = new Worker(
Expand Down
2 changes: 1 addition & 1 deletion tests/Routing/HandlerMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function test_non_handler_class_is_rejected_on_resolve(): void

public function test_a_concrete_handler_can_be_used_via_resolver(): void
{
$handler = new class () implements Handler {
$handler = new class implements Handler {
public bool $ran = false;

public function handle(InboundMessage $message): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Support/ArrayTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ final class ArrayTransport implements Transport, ConsumerTransport

private int $receiptSeq = 0;

public function __construct(private readonly string $defaultQueue = 'default')
{
}
public function __construct(private readonly string $defaultQueue = 'default') {}

public function publish(string $payload, ?string $queue = null): ?string
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/InMemoryRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function zrangebyscore(string $key, string $min, string $max): array

$matching = array_filter(
$this->zsets[$key] ?? [],
static fn (float $score): bool => $score >= $low && $score <= $high,
static fn(float $score): bool => $score >= $low && $score <= $high,
);
asort($matching);

Expand Down
2 changes: 1 addition & 1 deletion tests/Support/RecordingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function handle(InboundMessage $message): void
*/
public function payloads(): array
{
return array_map(static fn (InboundMessage $m): array => $m->getData(), $this->handled);
return array_map(static fn(InboundMessage $m): array => $m->getData(), $this->handled);
}
}
3 changes: 1 addition & 2 deletions tests/Support/SampleJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function __construct(
private readonly string $urn = 'urn:babel:orders:created',
private readonly array $payload = ['order_id' => 1042],
private readonly ?string $traceId = null,
) {
}
) {}

public function getBabelUrn(): string
{
Expand Down
4 changes: 1 addition & 3 deletions tests/Support/ThrowingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ final class ThrowingHandler implements Handler
{
public int $calls = 0;

public function __construct(private readonly string $message = 'handler failed')
{
}
public function __construct(private readonly string $message = 'handler failed') {}

public function handle(InboundMessage $message): void
{
Expand Down
Loading