Skip to content
Closed
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
27 changes: 16 additions & 11 deletions src/Store/DoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@

private readonly HeadersSerializer $headersSerializer;

/** @var array{table_name: string, aggregate_id_type: 'string'|'uuid', locking: bool, lock_id: int, lock_timeout: int} */
/** @var array{table_name: string, aggregate_id_type: 'string'|'uuid', locking: bool, lock_id: int, lock_timeout: int, transactional: bool} */
private readonly array $config;

private bool $hasLock = false;

/** @param array{table_name?: string, aggregate_id_type?: 'string'|'uuid', locking?: bool, lock_id?: int, lock_timeout?: int} $config */
/** @param array{table_name?: string, aggregate_id_type?: 'string'|'uuid', locking?: bool, lock_id?: int, lock_timeout?: int, transactional: bool} $config */

Check failure on line 70 in src/Store/DoctrineDbalStore.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

InvalidParamDefault

src/Store/DoctrineDbalStore.php:70:16: InvalidParamDefault: Default value type array<never, never> for argument 4 of method Patchlevel\EventSourcing\Store\DoctrineDbalStore::__construct does not match the given type array{aggregate_id_type?: 'string'|'uuid', lock_id?: int, lock_timeout?: int, locking?: bool, table_name?: string, transactional: bool} (see https://psalm.dev/062)
public function __construct(
private readonly Connection $connection,
private readonly EventSerializer $eventSerializer,
HeadersSerializer|null $headersSerializer = null,
array $config = [],

Check failure on line 75 in src/Store/DoctrineDbalStore.php

View workflow job for this annotation

GitHub Actions / Static Analysis by PHPStan (locked, 8.3, ubuntu-latest)

Default value of the parameter #4 $config (array{}) of method Patchlevel\EventSourcing\Store\DoctrineDbalStore::__construct() is incompatible with type array{table_name?: string, aggregate_id_type?: 'string'|'uuid', locking?: bool, lock_id?: int, lock_timeout?: int, transactional: bool}.
) {
$this->headersSerializer = $headersSerializer ?? DefaultHeadersSerializer::createDefault();

Expand All @@ -82,6 +82,7 @@
'locking' => true,
'lock_id' => self::DEFAULT_LOCK_ID,
'lock_timeout' => -1,
'transactional' => true,
], $config);
}

Expand Down Expand Up @@ -298,17 +299,21 @@
*/
public function transactional(Closure $function): void
{
if ($this->config['transactional']) {
$function = function () use ($function): void {
$this->connection->transactional($function);
};
}

if ($this->hasLock || !$this->config['locking']) {
$this->connection->transactional($function);
$function();
} else {
$this->connection->transactional(function () use ($function): void {
$this->lock();
try {
$function();
} finally {
$this->unlock();
}
});
$this->lock();
try {
$function();
} finally {
$this->unlock();
}
}
}

Expand Down
Loading