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
32 changes: 11 additions & 21 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
name: static analysis

on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'

paths: &paths
- '.github/workflows/static.yml'
- 'src/**'
- 'psalm*.xml'
- 'composer.json'
push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'

name: static analysis
branches: ['master']
paths: *paths

permissions:
contents: read
Expand All @@ -30,6 +20,6 @@ jobs:
with:
extensions: pdo, pdo_pgsql
os: >-
["ubuntu-latest"]
['ubuntu-latest']
php: >-
["8.1"]
['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"phpunit/phpunit": "^9.6.35",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.3|^6.0"
"vimeo/psalm": "^4.30 || ^5.26.1 || ^6.16.1"
},
"autoload": {
"psr-4": {
Expand All @@ -56,6 +56,7 @@
},
"scripts": {
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
"test-watch": "phpunit-watcher watch",
"psalm": "psalm"
}
}
7 changes: 7 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
ensureOverrideAttribute="false"
strictBinaryOperands="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
8 changes: 7 additions & 1 deletion src/PgsqlMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
*/
public function __construct(string $name, PDO $connection)
{
// Converts a string into two 16-bit integer keys using the SHA1 hash function.
/**
* Converts a string into two 16-bit integer keys using the SHA1 hash function.
*
* @psalm-suppress PossiblyFalseArgument `unpack()` never returns `false` here because `sha1(...)` with raw
* output always returns a 20-byte string, which is more than enough for the 4 bytes required by the 'n2' format
* (two unsigned 16-bit big-endian integers).
*/
$this->lockKeys = array_values(unpack('n2', sha1($name, true)));
$this->connection = $connection;

Expand All @@ -45,7 +51,7 @@
*
* @see https://www.postgresql.org/docs/13/functions-admin.html
*/
protected function acquireLock(int $timeout = 0): bool

Check warning on line 54 in src/PgsqlMutex.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ * * @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 54 in src/PgsqlMutex.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ * * @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]);
Expand Down