Repository navigation
Replace Psalm with PHPStan #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| parameters: | ||
| level: max | ||
| paths: | ||
| - src |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| */ | ||
| final class PgsqlMutex extends Mutex | ||
| { | ||
| /** @var list<int> */ | ||
| private array $lockKeys; | ||
| private PDO $connection; | ||
|
|
||
|
|
@@ -31,12 +32,12 @@ | |
| * Decode the first eight hash bytes in big-endian order and normalize to PostgreSQL signed int4 keys. | ||
| * On 32-bit PHP, unpack() already returns signed integers for words with the high bit set. | ||
| * | ||
| * @psalm-suppress PossiblyFalseArgument `unpack()` never returns `false` here because `sha1(...)` with raw | ||
| * output always returns a 20-byte string, enough for the eight bytes required by the 'N2' format. | ||
| * `unpack()` never returns `false` here because `sha1(...)` with raw output always returns a 20-byte string, | ||
| * enough for the eight bytes required by the 'N2' format. | ||
| */ | ||
| $this->lockKeys = array_values(array_map( | ||
| static fn(int $key): int => $key > 0x7FFFFFFF ? $key - 0x100000000 : $key, | ||
| unpack('N2', sha1($name, true)), | ||
| static fn(int $key): int => $key > 0x7FFFFFFF ? $key - 0x100000000 : $key, // @phpstan-ignore argument.type | ||
|
Check warning on line 39 in src/PgsqlMutex.php
|
||
| unpack('N2', sha1($name, true)), // @phpstan-ignore argument.type | ||
| )); | ||
| $this->connection = $connection; | ||
|
|
||
|
|
@@ -55,14 +56,14 @@ | |
| * | ||
| * @see https://www.postgresql.org/docs/13/functions-admin.html | ||
| */ | ||
| protected function acquireLock(int $timeout = 0): bool | ||
|
Check warning on line 59 in src/PgsqlMutex.php
|
||
| { | ||
| $statement = $this->connection->prepare('SELECT pg_try_advisory_lock(:key1, :key2)'); | ||
| $statement->bindValue(':key1', $this->lockKeys[0]); | ||
| $statement->bindValue(':key2', $this->lockKeys[1]); | ||
| $statement->execute(); | ||
|
|
||
| return (bool) $statement->fetchColumn(); | ||
|
Check warning on line 66 in src/PgsqlMutex.php
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -77,6 +78,6 @@ | |
| $statement->bindValue(':key2', $this->lockKeys[1]); | ||
| $statement->execute(); | ||
|
|
||
| return (bool) $statement->fetchColumn(); | ||
|
Check warning on line 81 in src/PgsqlMutex.php
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Critical · Static analysis check fails
When the new PHPStan job analyzes
src/PgsqlMutex.php, pHPStan reports calls onPDOStatement|false:acquireLock()andreleaseLock()dereference the results ofPDO::prepare()without checking them. Since the new configuration scanssrcat maximum level, the static-analysis job fails.Check that each
PDO::prepare()result is not false before calling methods on it.Prompt for AI agents