Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Komarev committed Aug 26, 2023
1 parent 45a0f4a commit 0930009
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/LockId/PostgresLockId.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

final class PostgresLockId
{
private const DB_INT_VALUE_MIN = 0;
private const DB_INT_VALUE_MAX = 9223372036854775807;
private const DB_INT32_VALUE_MAX = 2147483647;
private const DB_INT64_VALUE_MIN = 0;
private const DB_INT64_VALUE_MAX = 9223372036854775807;

public function __construct(
public readonly int $id,
public readonly string $humanReadableValue = '',
) {
if ($id < self::DB_INT_VALUE_MIN) {
if ($id < self::DB_INT64_VALUE_MIN) {
throw new InvalidArgumentException('Out of bound exception (id is too small)');
}
if ($id > self::DB_INT_VALUE_MAX) {
if ($id > self::DB_INT64_VALUE_MAX) {
throw new InvalidArgumentException('Out of bound exception (id is too big)');
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/Integration/Locker/PostgresAdvisoryLockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

final class PostgresAdvisoryLockerTest extends AbstractIntegrationTestCase
{
private const MIN_DB_INT_VALUE = 0;
private const MAX_DB_INT_VALUE = 9223372036854775807;
private const DB_INT64_VALUE_MIN = 0;
private const DB_INT64_VALUE_MAX = 9223372036854775807;

public function test_it_can_acquire_lock(): void
{
Expand All @@ -41,7 +41,7 @@ public function test_it_can_acquire_lock_with_smallest_lock_id(): void
{
$locker = $this->initLocker();
$dbConnection = $this->initPostgresPdoConnection();
$postgresLockId = new PostgresLockId(self::MIN_DB_INT_VALUE);
$postgresLockId = new PostgresLockId(self::DB_INT64_VALUE_MIN);

$isLockAcquired = $locker->acquireLock($dbConnection, $postgresLockId);

Expand All @@ -54,7 +54,7 @@ public function test_it_can_acquire_lock_with_biggest_lock_id(): void
{
$locker = $this->initLocker();
$dbConnection = $this->initPostgresPdoConnection();
$postgresLockId = new PostgresLockId(self::MAX_DB_INT_VALUE);
$postgresLockId = new PostgresLockId(self::DB_INT64_VALUE_MAX);

$isLockAcquired = $locker->acquireLock($dbConnection, $postgresLockId);

Expand Down
12 changes: 6 additions & 6 deletions test/Unit/LockId/PostgresLockIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@

final class PostgresLockIdTest extends AbstractUnitTestCase
{
private const MIN_DB_INT_VALUE = 0;
private const MAX_DB_INT_VALUE = 9223372036854775807;
private const DB_INT64_VALUE_MIN = 0;
private const DB_INT64_VALUE_MAX = 9223372036854775807;

public function test_it_can_create_postgres_lock_id_with_min_id(): void
{
$lockId = new PostgresLockId(self::MIN_DB_INT_VALUE);
$lockId = new PostgresLockId(self::DB_INT64_VALUE_MIN);

$this->assertSame(self::MIN_DB_INT_VALUE, $lockId->id);
$this->assertSame(self::DB_INT64_VALUE_MIN, $lockId->id);
}

public function test_it_can_create_postgres_lock_id_with_max_id(): void
{
$lockId = new PostgresLockId(self::MAX_DB_INT_VALUE);
$lockId = new PostgresLockId(self::DB_INT64_VALUE_MAX);

$this->assertSame(self::MAX_DB_INT_VALUE, $lockId->id);
$this->assertSame(self::DB_INT64_VALUE_MAX, $lockId->id);
}

public function test_it_can_create_postgres_lock_id_from_lock_id(): void
Expand Down

0 comments on commit 0930009

Please sign in to comment.