diff --git a/README.md b/README.md index 9fddbe9..d6e729c 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ class ExampleCommand extends Command { use WithoutOverlapping; - protected $mutexStrategy = 'mysql'; + protected string $mutexStrategy = 'mysql'; // ... } @@ -125,7 +125,7 @@ class ExampleCommand extends Command use WithoutOverlapping; // In milliseconds - protected $mutexTimeout = 3000; + protected ?int $mutexTimeout = 3000; // ... } diff --git a/src/Mutex.php b/src/Mutex.php index 6060fe4..150535d 100644 --- a/src/Mutex.php +++ b/src/Mutex.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Redis as RedisFacade; use NinjaMutex\Lock\FlockLock; +use NinjaMutex\Lock\LockAbstract; use NinjaMutex\Lock\MemcachedLock; use NinjaMutex\Lock\MySqlLock; use NinjaMutex\Lock\PhpRedisLock; @@ -19,33 +20,25 @@ class Mutex { /** * The console command. - * - * @var \Illuminate\Console\Command */ - private $command; + private Command $command; /** * The NinjaMutex. - * - * @var \NinjaMutex\Mutex */ - private $ninjaMutex; + private NinjaMutex $ninjaMutex; /** * The NinjaMutex lock. - * - * @var \NinjaMutex\Lock\LockAbstract */ - private $ninjaMutexLock; + private LockAbstract $ninjaMutexLock; /** * Create a new instance of the mutex. - * - * @param \Illuminate\Console\Command|\Illuminated\Console\WithoutOverlapping $command - * @return void */ public function __construct(Command $command) { + /** @var WithoutOverlapping $command */ $this->command = $command; $mutexName = $command->getMutexName(); @@ -55,10 +48,8 @@ public function __construct(Command $command) /** * Get the NinjaMutex lock. - * - * @return \NinjaMutex\Lock\LockAbstract */ - public function getNinjaMutexLock() + public function getNinjaMutexLock(): LockAbstract { if (!empty($this->ninjaMutexLock)) { return $this->ninjaMutexLock; @@ -88,11 +79,8 @@ public function getNinjaMutexLock() /** * Get the redis lock. - * - * @param string $client - * @return \NinjaMutex\Lock\LockAbstract */ - private function getRedisLock($client) + private function getRedisLock(string $client): LockAbstract { $redis = RedisFacade::connection()->client(); @@ -103,12 +91,8 @@ private function getRedisLock($client) /** * Forward method calls to NinjaMutex. - * - * @param string $method - * @param mixed $parameters - * @return mixed */ - public function __call($method, $parameters) + public function __call(string $method, mixed $parameters): mixed { return call_user_func_array([$this->ninjaMutex, $method], $parameters); } diff --git a/src/WithoutOverlapping.php b/src/WithoutOverlapping.php index 7606694..d72cb1d 100644 --- a/src/WithoutOverlapping.php +++ b/src/WithoutOverlapping.php @@ -9,12 +9,8 @@ trait WithoutOverlapping { /** * Overwrite the console command initialization. - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - * @return void */ - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { $this->initializeMutex(); @@ -23,10 +19,8 @@ protected function initialize(InputInterface $input, OutputInterface $output) /** * Initialize the mutex. - * - * @return void */ - protected function initializeMutex() + protected function initializeMutex(): void { $mutex = new Mutex($this); @@ -42,10 +36,8 @@ protected function initializeMutex() * Get the mutex strategy. * * Currently supported: "file", "mysql", "redis" and "memcached". - * - * @return string */ - public function getMutexStrategy() + public function getMutexStrategy(): string { return property_exists($this, 'mutexStrategy') ? $this->mutexStrategy @@ -56,11 +48,8 @@ public function getMutexStrategy() * Set the mutex strategy. * * Currently supported: "file", "mysql", "redis" and "memcached". - * - * @param string $strategy - * @return void */ - public function setMutexStrategy($strategy) + public function setMutexStrategy(string $strategy): void { $this->mutexStrategy = $strategy; } @@ -72,10 +61,8 @@ public function setMutexStrategy($strategy) * `0` - check without waiting; * `{milliseconds}` - check, and wait for a maximum of milliseconds specified; * `null` - wait, till running command finish its execution; - * - * @return int|null */ - public function getMutexTimeout() + public function getMutexTimeout(): int|null { return property_exists($this, 'mutexTimeout') ? $this->mutexTimeout @@ -89,21 +76,16 @@ public function getMutexTimeout() * `0` - check without waiting; * `{milliseconds}` - check, and wait for a maximum of milliseconds specified; * `null` - wait, till running command finish its execution; - * - * @param int|null $timeout - * @return void */ - public function setMutexTimeout($timeout) + public function setMutexTimeout(int|null $timeout): void { $this->mutexTimeout = $timeout; } /** * Get the mutex name. - * - * @return string */ - public function getMutexName() + public function getMutexName(): string { $name = $this->getName(); $argumentsHash = md5(json_encode($this->argument())); @@ -113,10 +95,8 @@ public function getMutexName() /** * Get the mutex file storage path. - * - * @return string */ - public function getMutexFileStorage() + public function getMutexFileStorage(): string { return storage_path('app'); } @@ -125,11 +105,8 @@ public function getMutexFileStorage() * Release the mutex lock. * * Called automatically, because it's registered as a shutdown function. - * - * @param \Illuminated\Console\Mutex $mutex - * @return void */ - public function releaseMutexLock(Mutex $mutex) + public function releaseMutexLock(Mutex $mutex): void { $mutex->releaseLock(); } diff --git a/tests/MutexTest.php b/tests/MutexTest.php index 62671b6..7924223 100644 --- a/tests/MutexTest.php +++ b/tests/MutexTest.php @@ -2,10 +2,12 @@ namespace Illuminated\Console\Tests; +use Illuminate\Console\Command; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Redis as RedisFacade; use Illuminated\Console\Mutex; use Illuminated\Console\Tests\App\Console\Commands\GenericCommand; +use Mockery\Mock; use NinjaMutex\Lock\FlockLock; use NinjaMutex\Lock\MemcachedLock; use NinjaMutex\Lock\MySqlLock; @@ -18,15 +20,11 @@ class MutexTest extends TestCase { /** * The console command mock. - * - * @var \Mockery\Mock|\Illuminate\Console\Command */ - private $command; + private Mock|Command $command; /** * Setup the test environment. - * - * @return void */ protected function setUp(): void { diff --git a/tests/fixture/app/Console/Commands/GenericCommand.php b/tests/fixture/app/Console/Commands/GenericCommand.php index 8ab3451..000b8f1 100644 --- a/tests/fixture/app/Console/Commands/GenericCommand.php +++ b/tests/fixture/app/Console/Commands/GenericCommand.php @@ -18,10 +18,8 @@ class GenericCommand extends Command /** * Handle the command. - * - * @return void */ - public function handle() + public function handle(): void { $this->info('Done!'); } diff --git a/tests/fixture/app/Console/Commands/MysqlStrategyCommand.php b/tests/fixture/app/Console/Commands/MysqlStrategyCommand.php index 51de935..8e9bc9b 100644 --- a/tests/fixture/app/Console/Commands/MysqlStrategyCommand.php +++ b/tests/fixture/app/Console/Commands/MysqlStrategyCommand.php @@ -18,17 +18,13 @@ class MysqlStrategyCommand extends Command /** * The mutex strategy. - * - * @var string */ - protected $mutexStrategy = 'mysql'; + protected string $mutexStrategy = 'mysql'; /** * Handle the command. - * - * @return void */ - public function handle() + public function handle(): void { $this->info('Done!'); } diff --git a/tests/fixture/app/Console/Commands/NullTimeoutCommand.php b/tests/fixture/app/Console/Commands/NullTimeoutCommand.php index 9427542..ece8f3a 100644 --- a/tests/fixture/app/Console/Commands/NullTimeoutCommand.php +++ b/tests/fixture/app/Console/Commands/NullTimeoutCommand.php @@ -18,17 +18,13 @@ class NullTimeoutCommand extends Command /** * The mutex timeout. - * - * @var int|null */ - protected $mutexTimeout; + protected ?int $mutexTimeout = null; /** * Handle the command. - * - * @return void */ - public function handle() + public function handle(): void { $this->info('Done!'); } diff --git a/tests/fixture/app/Console/Commands/TimeoutCommand.php b/tests/fixture/app/Console/Commands/TimeoutCommand.php index ccc43b6..9d9833c 100644 --- a/tests/fixture/app/Console/Commands/TimeoutCommand.php +++ b/tests/fixture/app/Console/Commands/TimeoutCommand.php @@ -18,17 +18,13 @@ class TimeoutCommand extends Command /** * The mutex timeout. - * - * @var int|null */ - protected $mutexTimeout = 3000; + protected ?int $mutexTimeout = 3000; /** * Handle the command. - * - * @return void */ - public function handle() + public function handle(): void { $this->info('Done!'); }