Skip to content

Commit 382c756

Browse files
committed
Merge branch 'master' into 9.x
2 parents 2b7b45e + 3327b51 commit 382c756

8 files changed

+29
-84
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ExampleCommand extends Command
8686
{
8787
use WithoutOverlapping;
8888
89-
protected $mutexStrategy = 'mysql';
89+
protected string $mutexStrategy = 'mysql';
9090
9191
// ...
9292
}
@@ -125,7 +125,7 @@ class ExampleCommand extends Command
125125
use WithoutOverlapping;
126126

127127
// In milliseconds
128-
protected $mutexTimeout = 3000;
128+
protected ?int $mutexTimeout = 3000;
129129

130130
// ...
131131
}

src/Mutex.php

+8-24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\Cache;
77
use Illuminate\Support\Facades\Redis as RedisFacade;
88
use NinjaMutex\Lock\FlockLock;
9+
use NinjaMutex\Lock\LockAbstract;
910
use NinjaMutex\Lock\MemcachedLock;
1011
use NinjaMutex\Lock\MySqlLock;
1112
use NinjaMutex\Lock\PhpRedisLock;
@@ -19,33 +20,25 @@ class Mutex
1920
{
2021
/**
2122
* The console command.
22-
*
23-
* @var \Illuminate\Console\Command
2423
*/
25-
private $command;
24+
private Command $command;
2625

2726
/**
2827
* The NinjaMutex.
29-
*
30-
* @var \NinjaMutex\Mutex
3128
*/
32-
private $ninjaMutex;
29+
private NinjaMutex $ninjaMutex;
3330

3431
/**
3532
* The NinjaMutex lock.
36-
*
37-
* @var \NinjaMutex\Lock\LockAbstract
3833
*/
39-
private $ninjaMutexLock;
34+
private LockAbstract $ninjaMutexLock;
4035

4136
/**
4237
* Create a new instance of the mutex.
43-
*
44-
* @param \Illuminate\Console\Command|\Illuminated\Console\WithoutOverlapping $command
45-
* @return void
4638
*/
4739
public function __construct(Command $command)
4840
{
41+
/** @var WithoutOverlapping $command */
4942
$this->command = $command;
5043

5144
$mutexName = $command->getMutexName();
@@ -55,10 +48,8 @@ public function __construct(Command $command)
5548

5649
/**
5750
* Get the NinjaMutex lock.
58-
*
59-
* @return \NinjaMutex\Lock\LockAbstract
6051
*/
61-
public function getNinjaMutexLock()
52+
public function getNinjaMutexLock(): LockAbstract
6253
{
6354
if (!empty($this->ninjaMutexLock)) {
6455
return $this->ninjaMutexLock;
@@ -88,11 +79,8 @@ public function getNinjaMutexLock()
8879

8980
/**
9081
* Get the redis lock.
91-
*
92-
* @param string $client
93-
* @return \NinjaMutex\Lock\LockAbstract
9482
*/
95-
private function getRedisLock($client)
83+
private function getRedisLock(string $client): LockAbstract
9684
{
9785
$redis = RedisFacade::connection()->client();
9886

@@ -103,12 +91,8 @@ private function getRedisLock($client)
10391

10492
/**
10593
* Forward method calls to NinjaMutex.
106-
*
107-
* @param string $method
108-
* @param mixed $parameters
109-
* @return mixed
11094
*/
111-
public function __call($method, $parameters)
95+
public function __call(string $method, mixed $parameters): mixed
11296
{
11397
return call_user_func_array([$this->ninjaMutex, $method], $parameters);
11498
}

src/WithoutOverlapping.php

+9-32
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ trait WithoutOverlapping
99
{
1010
/**
1111
* Overwrite the console command initialization.
12-
*
13-
* @param \Symfony\Component\Console\Input\InputInterface $input
14-
* @param \Symfony\Component\Console\Output\OutputInterface $output
15-
* @return void
1612
*/
17-
protected function initialize(InputInterface $input, OutputInterface $output)
13+
protected function initialize(InputInterface $input, OutputInterface $output): void
1814
{
1915
$this->initializeMutex();
2016

@@ -23,10 +19,8 @@ protected function initialize(InputInterface $input, OutputInterface $output)
2319

2420
/**
2521
* Initialize the mutex.
26-
*
27-
* @return void
2822
*/
29-
protected function initializeMutex()
23+
protected function initializeMutex(): void
3024
{
3125
$mutex = new Mutex($this);
3226

@@ -42,10 +36,8 @@ protected function initializeMutex()
4236
* Get the mutex strategy.
4337
*
4438
* Currently supported: "file", "mysql", "redis" and "memcached".
45-
*
46-
* @return string
4739
*/
48-
public function getMutexStrategy()
40+
public function getMutexStrategy(): string
4941
{
5042
return property_exists($this, 'mutexStrategy')
5143
? $this->mutexStrategy
@@ -56,11 +48,8 @@ public function getMutexStrategy()
5648
* Set the mutex strategy.
5749
*
5850
* Currently supported: "file", "mysql", "redis" and "memcached".
59-
*
60-
* @param string $strategy
61-
* @return void
6251
*/
63-
public function setMutexStrategy($strategy)
52+
public function setMutexStrategy(string $strategy): void
6453
{
6554
$this->mutexStrategy = $strategy;
6655
}
@@ -72,10 +61,8 @@ public function setMutexStrategy($strategy)
7261
* `0` - check without waiting;
7362
* `{milliseconds}` - check, and wait for a maximum of milliseconds specified;
7463
* `null` - wait, till running command finish its execution;
75-
*
76-
* @return int|null
7764
*/
78-
public function getMutexTimeout()
65+
public function getMutexTimeout(): int|null
7966
{
8067
return property_exists($this, 'mutexTimeout')
8168
? $this->mutexTimeout
@@ -89,21 +76,16 @@ public function getMutexTimeout()
8976
* `0` - check without waiting;
9077
* `{milliseconds}` - check, and wait for a maximum of milliseconds specified;
9178
* `null` - wait, till running command finish its execution;
92-
*
93-
* @param int|null $timeout
94-
* @return void
9579
*/
96-
public function setMutexTimeout($timeout)
80+
public function setMutexTimeout(int|null $timeout): void
9781
{
9882
$this->mutexTimeout = $timeout;
9983
}
10084

10185
/**
10286
* Get the mutex name.
103-
*
104-
* @return string
10587
*/
106-
public function getMutexName()
88+
public function getMutexName(): string
10789
{
10890
$name = $this->getName();
10991
$argumentsHash = md5(json_encode($this->argument()));
@@ -113,10 +95,8 @@ public function getMutexName()
11395

11496
/**
11597
* Get the mutex file storage path.
116-
*
117-
* @return string
11898
*/
119-
public function getMutexFileStorage()
99+
public function getMutexFileStorage(): string
120100
{
121101
return storage_path('app');
122102
}
@@ -125,11 +105,8 @@ public function getMutexFileStorage()
125105
* Release the mutex lock.
126106
*
127107
* Called automatically, because it's registered as a shutdown function.
128-
*
129-
* @param \Illuminated\Console\Mutex $mutex
130-
* @return void
131108
*/
132-
public function releaseMutexLock(Mutex $mutex)
109+
public function releaseMutexLock(Mutex $mutex): void
133110
{
134111
$mutex->releaseLock();
135112
}

tests/MutexTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Illuminated\Console\Tests;
44

5+
use Illuminate\Console\Command;
56
use Illuminate\Support\Facades\Cache;
67
use Illuminate\Support\Facades\Redis as RedisFacade;
78
use Illuminated\Console\Mutex;
89
use Illuminated\Console\Tests\App\Console\Commands\GenericCommand;
10+
use Mockery\Mock;
911
use NinjaMutex\Lock\FlockLock;
1012
use NinjaMutex\Lock\MemcachedLock;
1113
use NinjaMutex\Lock\MySqlLock;
@@ -18,15 +20,11 @@ class MutexTest extends TestCase
1820
{
1921
/**
2022
* The console command mock.
21-
*
22-
* @var \Mockery\Mock|\Illuminate\Console\Command
2323
*/
24-
private $command;
24+
private Mock|Command $command;
2525

2626
/**
2727
* Setup the test environment.
28-
*
29-
* @return void
3028
*/
3129
protected function setUp(): void
3230
{

tests/fixture/app/Console/Commands/GenericCommand.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class GenericCommand extends Command
1818

1919
/**
2020
* Handle the command.
21-
*
22-
* @return void
2321
*/
24-
public function handle()
22+
public function handle(): void
2523
{
2624
$this->info('Done!');
2725
}

tests/fixture/app/Console/Commands/MysqlStrategyCommand.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ class MysqlStrategyCommand extends Command
1818

1919
/**
2020
* The mutex strategy.
21-
*
22-
* @var string
2321
*/
24-
protected $mutexStrategy = 'mysql';
22+
protected string $mutexStrategy = 'mysql';
2523

2624
/**
2725
* Handle the command.
28-
*
29-
* @return void
3026
*/
31-
public function handle()
27+
public function handle(): void
3228
{
3329
$this->info('Done!');
3430
}

tests/fixture/app/Console/Commands/NullTimeoutCommand.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ class NullTimeoutCommand extends Command
1818

1919
/**
2020
* The mutex timeout.
21-
*
22-
* @var int|null
2321
*/
24-
protected $mutexTimeout;
22+
protected ?int $mutexTimeout = null;
2523

2624
/**
2725
* Handle the command.
28-
*
29-
* @return void
3026
*/
31-
public function handle()
27+
public function handle(): void
3228
{
3329
$this->info('Done!');
3430
}

tests/fixture/app/Console/Commands/TimeoutCommand.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ class TimeoutCommand extends Command
1818

1919
/**
2020
* The mutex timeout.
21-
*
22-
* @var int|null
2321
*/
24-
protected $mutexTimeout = 3000;
22+
protected ?int $mutexTimeout = 3000;
2523

2624
/**
2725
* Handle the command.
28-
*
29-
* @return void
3026
*/
31-
public function handle()
27+
public function handle(): void
3228
{
3329
$this->info('Done!');
3430
}

0 commit comments

Comments
 (0)