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 .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/.styleci.yml export-ignore
/infection.json.dist export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
/phpstan.neon export-ignore
/tests export-ignore
/docs export-ignore

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '.github/workflows/mutation.yml'
- 'composer.json'
- 'infection.json.dist'
- 'psalm.xml'
- 'phpstan.neon'
push:
branches: ['master']
paths: *paths
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
paths: &paths
- '.github/workflows/static.yml'
- 'src/**'
- 'psalm*.xml'
- 'phpstan.neon'
- 'composer.json'
push:
branches: ['master']
Expand All @@ -15,11 +15,11 @@ permissions:
contents: read

jobs:
psalm:
uses: yiisoft/actions/.github/workflows/psalm.yml@master
phpstan:
uses: yiisoft/actions/.github/workflows/phpstan.yml@master

Copy link
Copy Markdown

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 on PDOStatement|false: acquireLock() and releaseLock() dereference the results of PDO::prepare() without checking them. Since the new configuration scans src at 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
In `.github/workflows/static.yml` at line 19:

**Static analysis check fails**

When the new PHPStan job analyzes `src/PgsqlMutex.php`, pHPStan reports calls on `PDOStatement|false`: `acquireLock()` and `releaseLock()` dereference the results of `PDO::prepare()` without checking them. Since the new configuration scans `src` at maximum level, the static-analysis job fails.

Check that each `PDO::prepare()` result is not false before calling methods on it.

with:
extensions: pdo, pdo_pgsql
os: >-
['ubuntu-latest']
php: >-
['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 1.2.1 under development

- no changes in this release.
- Chg #60: Replace Psalm with PHPStan (@vjik)

## 1.2.0 November 13, 2026

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[![Code Coverage](https://codecov.io/gh/yiisoft/mutex-pdo-pgsql/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/mutex-pdo-pgsql)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fmutex-pdo-pgsql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/mutex-pdo-pgsql/master)
[![static analysis](https://github.com/yiisoft/mutex-pdo-pgsql/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/mutex-pdo-pgsql/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/mutex-pdo-pgsql/coverage.svg)](https://shepherd.dev/github/yiisoft/mutex-pdo-pgsql)

This library provides a PostgreSQL mutex implementation for [yiisoft/mutex](https://github.com/yiisoft/mutex).

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.95",
"infection/infection": "^0.26.6 || ^0.27.10 || ^0.29.8 || ^0.35.8",
"phpstan/phpstan": "^2.3",
"phpunit/phpunit": "^9.6.35",
"rector/rector": "^2.8.3",
"shipmonk/composer-dependency-analyser": "^1.8",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30 || ^5.26.1 || ^6.16.1",
"yiisoft/code-style": "^1.1"
},
"autoload": {
Expand All @@ -61,7 +61,7 @@
"scripts": {
"cs-fix": "php-cs-fixer fix",
"dependency-analyser": "composer-dependency-analyser",
"psalm": "psalm",
"phpstan": "phpstan",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
Expand Down
4 changes: 2 additions & 2 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ The package tests are checked with [Infection](https://infection.github.io/) mut

## Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
The code is statically analyzed with [PHPStan](https://phpstan.org/). To run static analysis:

```shell
./vendor/bin/psalm
./vendor/bin/phpstan
```

## Dependencies
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src
18 changes: 0 additions & 18 deletions psalm.xml

This file was deleted.

9 changes: 5 additions & 4 deletions src/PgsqlMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
final class PgsqlMutex extends Mutex
{
/** @var list<int> */
private array $lockKeys;
private PDO $connection;

Expand All @@ -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

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": @@ @@ * 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, + static fn(int $key): int => $key >= 0x7fffffff ? $key - 0x100000000 : $key, // @PHPStan-Ignore argument.type unpack('N2', sha1($name, true)) ));
unpack('N2', sha1($name, true)), // @phpstan-ignore argument.type
));
$this->connection = $connection;

Expand All @@ -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

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ * * @see https://www.postgresql.org/docs/13/functions-admin.html */ - protected function acquireLock(int $timeout = 0): bool + protected function acquireLock(int $timeout = 1): bool { $statement = $this->connection->prepare('SELECT pg_try_advisory_lock(:key1, :key2)'); $statement->bindValue(':key1', $this->lockKeys[0]);

Check warning on line 59 in src/PgsqlMutex.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ * * @see https://www.postgresql.org/docs/13/functions-admin.html */ - protected function acquireLock(int $timeout = 0): bool + protected function acquireLock(int $timeout = -1): bool { $statement = $this->connection->prepare('SELECT pg_try_advisory_lock(:key1, :key2)'); $statement->bindValue(':key1', $this->lockKeys[0]);
{
$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

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "CastBool": @@ @@ $statement->bindValue(':key1', $this->lockKeys[0]); $statement->bindValue(':key2', $this->lockKeys[1]); $statement->execute(); - return (bool) $statement->fetchColumn(); + return $statement->fetchColumn(); } /** * {@inheritdoc}
}

/**
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "CastBool": @@ @@ $statement->bindValue(':key1', $this->lockKeys[0]); $statement->bindValue(':key2', $this->lockKeys[1]); $statement->execute(); - return (bool) $statement->fetchColumn(); + return $statement->fetchColumn(); } }
}
}