Skip to content

Commit

Permalink
cs + all stan
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 3, 2024
1 parent 4840288 commit e1b12c3
Show file tree
Hide file tree
Showing 27 changed files with 62 additions and 158 deletions.
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ parameters:
identifier: if.condNotBoolean
message: '~^Only booleans are allowed in an if condition, mixed given\.$~'
count: 1
-
path: 'src/mutex/TransactionalMutex.php'
identifier: if.condNotBoolean
message: '~^Only booleans are allowed in an if condition, mixed given\.$~'
count: 1
3 changes: 0 additions & 3 deletions src/exception/DeadlineException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

namespace malkusch\lock\exception;

/**
* Deadline exception.
*/
class DeadlineException extends \RuntimeException implements PhpLockException {}
4 changes: 1 addition & 3 deletions src/exception/MutexException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
class MutexException extends \RuntimeException implements PhpLockException
{
/**
* @var int not enough redis servers
*/
/** @var int not enough redis servers */
public const REDIS_NOT_ENOUGH_SERVERS = 1;
}
4 changes: 1 addition & 3 deletions src/mutex/CASMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
*/
class CASMutex extends Mutex
{
/**
* @var Loop the loop
*/
/** @var Loop the loop */
private $loop;

/**
Expand Down
12 changes: 3 additions & 9 deletions src/mutex/FlockMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ class FlockMutex extends LockMutex
*/
public const STRATEGY_BUSY = 3;

/**
* @var resource the file handle
*/
/** @var resource the file handle */
private $fileHandle;

/**
* @var float
*/
/** @var float */
private $timeout;

/**
* @var self::STRATEGY_*
*/
/** @var self::STRATEGY_* */
private $strategy;

/**
Expand Down
4 changes: 1 addition & 3 deletions src/mutex/MemcachedMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*/
class MemcachedMutex extends SpinlockMutex
{
/**
* @var \Memcached the connected Memcached API
*/
/** @var \Memcached the connected Memcached API */
private $memcache;

/**
Expand Down
12 changes: 3 additions & 9 deletions src/mutex/MySQLMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

class MySQLMutex extends LockMutex
{
/**
* @var \PDO
*/
/** @var \PDO */
private $pdo;

/**
* @var string
*/
/** @var string */
private $name;
/**
* @var float
*/
/** @var float */
private $timeout;

public function __construct(\PDO $PDO, string $name, float $timeout = 0)
Expand Down
12 changes: 3 additions & 9 deletions src/mutex/PgAdvisoryLockMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@

class PgAdvisoryLockMutex extends LockMutex
{
/**
* @var \PDO
*/
/** @var \PDO */
private $pdo;

/**
* @var int
*/
/** @var int */
private $key1;

/**
* @var int
*/
/** @var int */
private $key2;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/mutex/RedisMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ abstract class RedisMutex extends SpinlockMutex implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var string the random value token for key identification
*/
/** @var string the random value token for key identification */
private $token;

/**
* @var array the Redis APIs
*/
/** @var array the Redis APIs */
private $redisAPIs;

/**
Expand Down
4 changes: 1 addition & 3 deletions src/mutex/SemaphoreMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*/
class SemaphoreMutex extends LockMutex
{
/**
* @var \SysvSemaphore|resource the semaphore id
*/
/** @var \SysvSemaphore|resource the semaphore id */
private $semaphore;

/**
Expand Down
20 changes: 5 additions & 15 deletions src/mutex/SpinlockMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,19 @@
*/
abstract class SpinlockMutex extends LockMutex
{
/**
* The prefix for the lock key.
*/
/** The prefix for the lock key. */
private const PREFIX = 'lock_';

/**
* @var float the timeout in seconds a lock may live
*/
/** @var float the timeout in seconds a lock may live */
private $timeout;

/**
* @var Loop the loop
*/
/** @var Loop the loop */
private $loop;

/**
* @var string the lock key
*/
/** @var string the lock key */
private $key;

/**
* @var float the timestamp when the lock was acquired
*/
/** @var float the timestamp when the lock was acquired */
private $acquired;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/mutex/TransactionalMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
*/
class TransactionalMutex extends Mutex
{
/**
* @var \PDO the PDO
*/
/** @var \PDO the PDO */
private $pdo;

/**
* @var Loop the loop
*/
/** @var Loop the loop */
private $loop;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/util/DoubleCheckedLocking.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
*/
class DoubleCheckedLocking
{
/**
* @var Mutex the mutex
*/
/** @var Mutex the mutex */
private $mutex;

/**
* @var callable(): bool the check
*/
/** @var callable(): bool the check */
private $check;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/util/Loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ class Loop
*/
private const MAXIMUM_WAIT_US = 5e5; // 0.50 seconds

/**
* @var float the timeout in seconds
*/
/** @var float the timeout in seconds */
private $timeout;

/**
* @var bool true while code execution is repeating
*/
/** @var bool true while code execution is repeating */
private $looping = false;

/**
Expand Down
6 changes: 2 additions & 4 deletions src/util/PcntlTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/
final class PcntlTimeout
{
/**
* @var int Timeout in seconds
*/
/** @var int Timeout in seconds */
private $timeout;

/**
Expand Down Expand Up @@ -80,7 +78,7 @@ public function timeBoxed(callable $code)
}

$oldAlarm = pcntl_alarm($this->timeout);
if ($oldAlarm != 0) {
if ($oldAlarm !== 0) {
throw new LockAcquireException('Existing alarm was not expected');
}

Expand Down
3 changes: 0 additions & 3 deletions tests/mutex/CASMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

/**
* Tests for CASMutex.
*/
class CASMutexTest extends TestCase
{
use PHPMock;
Expand Down
10 changes: 3 additions & 7 deletions tests/mutex/FlockMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@

class FlockMutexTest extends TestCase
{
/**
* @var FlockMutex
*/
/** @var FlockMutex */
private $mutex;

/**
* @var string
*/
/** @var string */
private $file;

protected function setUp(): void
Expand All @@ -44,7 +40,7 @@ public function testCodeExecutedOutsideLockIsNotThrown(int $strategy)
{
$this->mutex->strategy = $strategy; // @phpstan-ignore property.private

self::assertTrue($this->mutex->synchronized(static function (): bool {
self::assertTrue($this->mutex->synchronized(static function (): bool { // @phpstan-ignore staticMethod.alreadyNarrowedType
usleep(1100 * 1000);

return true;
Expand Down
7 changes: 1 addition & 6 deletions tests/mutex/LockMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Tests for LockMutex.
*/
class LockMutexTest extends TestCase
{
/**
* @var MockObject|LockMutex The SUT
*/
/** @var MockObject|LockMutex The SUT */
private $mutex;

protected function setUp(): void
Expand Down
8 changes: 2 additions & 6 deletions tests/mutex/MemcachedMutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@
*/
class MemcachedMutexTest extends TestCase
{
/**
* @var \Memcached|MockObject
*/
/** @var \Memcached|MockObject */
protected $memcached;

/**
* @var MemcachedMutex
*/
/** @var MemcachedMutex */
private $mutex;

protected function setUp(): void
Expand Down
14 changes: 5 additions & 9 deletions tests/mutex/MutexConcurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
*/
class MutexConcurrencyTest extends TestCase
{
/**
* @var array
*/
private static $temporaryFiles = [];
/**
* @var \PDO|null the pdo instance
*/
/** @var array */
protected static $temporaryFiles = [];
/** @var \PDO|null the pdo instance */
private $pdo;

public static function tearDownAfterClass(): void
Expand Down Expand Up @@ -235,15 +231,15 @@ public static function provideExecutionIsSerializedWhenLockedCases(): iterable
'flockWithTimoutPcntl' => [static function ($timeout = 3) use ($filename): Mutex {
$file = fopen($filename, 'w');
$lock = Liberator::liberate(new FlockMutex($file, $timeout));
$lock->strategy = FlockMutex::STRATEGY_PCNTL; // @phpstan-ignore property.private
$lock->strategy = FlockMutex::STRATEGY_PCNTL; // @phpstan-ignore property.notFound

return $lock->popsValue();
}],

'flockWithTimoutBusy' => [static function ($timeout = 3) use ($filename): Mutex {
$file = fopen($filename, 'w');
$lock = Liberator::liberate(new FlockMutex($file, $timeout));
$lock->strategy = FlockMutex::STRATEGY_BUSY; // @phpstan-ignore property.private
$lock->strategy = FlockMutex::STRATEGY_BUSY; // @phpstan-ignore property.notFound

return $lock->popsValue();
}],
Expand Down
4 changes: 2 additions & 2 deletions tests/mutex/MutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public function provideMutexFactoriesCases(): iterable
'flockWithTimoutPcntl' => [static function (): Mutex {
$file = fopen(vfsStream::url('test/lock'), 'w');
$lock = Liberator::liberate(new FlockMutex($file, 3));
$lock->strategy = FlockMutex::STRATEGY_PCNTL; // @phpstan-ignore property.private
$lock->strategy = FlockMutex::STRATEGY_PCNTL; // @phpstan-ignore property.notFound

return $lock->popsValue();
}],

'flockWithTimoutBusy' => [static function ($timeout = 3): Mutex {
$file = fopen(vfsStream::url('test/lock'), 'w');
$lock = Liberator::liberate(new FlockMutex($file, 3));
$lock->strategy = FlockMutex::STRATEGY_BUSY; // @phpstan-ignore property.private
$lock->strategy = FlockMutex::STRATEGY_BUSY; // @phpstan-ignore property.notFound

return $lock->popsValue();
}],
Expand Down
Loading

0 comments on commit e1b12c3

Please sign in to comment.