Skip to content

Commit af70e2e

Browse files
committed
phpstan fixes and adding phpstan to github actions
1 parent 0e916fb commit af70e2e

File tree

16 files changed

+69
-175
lines changed

16 files changed

+69
-175
lines changed

.github/workflows/tests.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ jobs:
2626
- name: Run phpcs
2727
run: vendor/bin/phpcs --standard=phpcs.xml -v -p -s --colors
2828

29+
phpstan:
30+
runs-on: ubuntu-latest
31+
name: Code Style
32+
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
39+
- name: Install dependencies
40+
run: composer install --no-interaction --prefer-dist --ignore-platform-req=ext-zookeeper --ignore-platform-req=ext-memcached
41+
42+
- name: Run phpstan
43+
run: vendor/bin/phpstan analyse --memory-limit=1024M
44+
2945
test:
3046
runs-on: ubuntu-latest
3147

examples/src/RedisLotteryQueue/Controller.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace App\RedisLotteryQueue;
66

77
use App\Infrastructure\ClientIdCookieSubscriber;
8-
use App\RedisLotteryQueue\Internal\RedisLotteryQueueSimulation;
98
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
109
use Symfony\Component\HttpFoundation\JsonResponse;
1110
use Symfony\Component\HttpFoundation\Request;
@@ -47,9 +46,6 @@ public function success(): Response
4746
#[Route('/redis-lottery-queue/start', methods: [Request::METHOD_POST])]
4847
public function start(Request $request, RedisLotteryQueueService $service): JsonResponse
4948
{
50-
// Queue simulation only - pre-seed
51-
$this->simulation->seedOnce();
52-
5349
$clientId = (string) $request->attributes->get(ClientIdCookieSubscriber::ATTRIBUTE);
5450
$result = $service->start($clientId);
5551

examples/src/RedisLotteryQueue/Internal/RedisLotteryQueueSimulation.php

Lines changed: 0 additions & 90 deletions
This file was deleted.

examples/src/RedisLotteryQueue/RedisLotteryQueueService.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace App\RedisLotteryQueue;
66

77
use App\Factory\AirlockFactory;
8-
use App\RedisLotteryQueue\Internal\RedisLotteryQueueSimulation;
98
use Clegginabox\Airlock\EntryResult;
109
use Clegginabox\Airlock\QueueAirlock;
1110

@@ -15,7 +14,6 @@ final class RedisLotteryQueueService
1514

1615
public function __construct(
1716
private readonly AirlockFactory $airlockFactory,
18-
private readonly RedisLotteryQueueSimulation $simulation,
1917
) {
2018
$this->airlock = $this->airlockFactory->redisLotteryQueue();
2119
}
@@ -36,13 +34,8 @@ private function tryAdmit(string $clientId, int $holdSeconds = 15): EntryResult
3634

3735
if ($result->isAdmitted()) {
3836
$token = $result->getToken();
37+
return $result;
3938

40-
/**
41-
* Handle the user being admitted here
42-
*/
43-
44-
// Queue simulation only - handle success
45-
$this->simulation->onSuccess($token, $clientId, $holdSeconds);
4639
}
4740

4841
return $result;

src/Bridge/Symfony/AirlockBundle.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Bridge/Symfony/Seal/SymfonyLockSeal.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Clegginabox\Airlock\Seal\ReleasableSeal;
1010
use Clegginabox\Airlock\Seal\Seal;
1111
use Clegginabox\Airlock\Seal\SealToken;
12-
use Symfony\Component\Lock\Exception\LockConflictedException;
13-
use Symfony\Component\Lock\Exception\LockExpiredException;
1412
use Symfony\Component\Lock\Key;
1513
use Symfony\Component\Lock\LockFactory;
1614
use Symfony\Component\Lock\LockInterface;
@@ -70,29 +68,27 @@ public function refresh(SealToken $token, ?float $ttlInSeconds = null): SealToke
7068
$lock->refresh($effectiveTtl);
7169

7270
return $token;
73-
} catch (LockExpiredException | LockConflictedException $e) {
74-
throw new LeaseExpiredException((string) $token, $e->getMessage());
7571
} catch (Throwable $e) {
7672
throw new LeaseExpiredException((string) $token, 'Unexpected error: ' . $e->getMessage());
7773
}
7874
}
7975

8076
public function isExpired(SymfonyLockToken $token): bool
8177
{
82-
return $this->resolveLock($token)?->isExpired() ?? true;
78+
return $this->resolveLock($token)->isExpired();
8379
}
8480

8581
public function isAcquired(SymfonyLockToken $token): bool
8682
{
87-
return $this->resolveLock($token)?->isAcquired() ?? false;
83+
return $this->resolveLock($token)->isAcquired();
8884
}
8985

9086
public function getRemainingLifetime(SymfonyLockToken $token): ?float
9187
{
92-
return $this->resolveLock($token)?->getRemainingLifetime();
88+
return $this->resolveLock($token)->getRemainingLifetime();
9389
}
9490

95-
private function resolveLock(SymfonyLockToken $token): ?LockInterface
91+
private function resolveLock(SymfonyLockToken $token): LockInterface
9692
{
9793
return $this->factory->createLockFromKey(
9894
$token->getKey(),

src/Bridge/Symfony/Seal/SymfonySemaphoreSeal.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ public function refresh(SealToken $token, ?float $ttlInSeconds = null): SymfonyS
8989

9090
public function isExpired(SymfonySemaphoreToken $token): bool
9191
{
92-
return $this->resolveSemaphore($token)?->isExpired() ?? true;
92+
return $this->resolveSemaphore($token)->isExpired();
9393
}
9494

9595
public function isAcquired(SymfonySemaphoreToken $token): bool
9696
{
97-
return $this->resolveSemaphore($token)?->isAcquired() ?? false;
97+
return $this->resolveSemaphore($token)->isAcquired();
9898
}
9999

100100
public function getRemainingLifetime(SymfonySemaphoreToken $token): ?float
101101
{
102-
return $this->resolveSemaphore($token)?->getRemainingLifetime();
102+
return $this->resolveSemaphore($token)->getRemainingLifetime();
103103
}
104104

105-
private function resolveSemaphore(SymfonySemaphoreToken $token): ?SemaphoreInterface
105+
private function resolveSemaphore(SymfonySemaphoreToken $token): SemaphoreInterface
106106
{
107107
return $this->factory->createSemaphoreFromKey(
108108
$token->getKey(),

src/OpportunisticAirlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function release(SealToken $token): void
4040
$this->seal->release($token);
4141
}
4242

43-
public function refresh(SealToken $token, ?float $ttlInSeconds = null): ?SealToken
43+
public function refresh(SealToken $token, ?float $ttlInSeconds = null): SealToken
4444
{
4545
return $this->seal->refresh($token, $ttlInSeconds);
4646
}

src/Queue/Storage/Fifo/InMemoryFifoQueueStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function addToBack(string $identifier): int
1717
$this->queue[] = $identifier;
1818
}
1919

20-
return $this->getPosition($identifier);
20+
return $this->getPosition($identifier) ?? -1;
2121
}
2222

2323
public function remove(string $identifier): void

src/QueueAirlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function release(SealToken $token): void
6767
$this->notifier->notify($nextPassenger, $this->topicFor($nextPassenger));
6868
}
6969

70-
public function refresh(SealToken $token, ?float $ttlInSeconds = null): ?SealToken
70+
public function refresh(SealToken $token, ?float $ttlInSeconds = null): SealToken
7171
{
7272
return $this->seal->refresh($token, $ttlInSeconds);
7373
}

0 commit comments

Comments
 (0)