Skip to content

Commit 29b6bc1

Browse files
authored
Update to PHP8 (#13)
1 parent eade44c commit 29b6bc1

5 files changed

Lines changed: 18 additions & 38 deletions

File tree

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"keywords": ["command-bus", "command", "service-bus", "laravel"],
66
"license": "MIT",
77
"require": {
8-
"php": "^7.2 || ^8.0",
8+
"php": "^8.0",
99
"ext-ctype": "*",
1010
"ext-posix": "*",
1111
"ext-pcntl": "*",
12-
"illuminate/support": ">=5.8",
13-
"illuminate/console": ">=5.8",
14-
"onliner/command-bus": "^0.4"
12+
"illuminate/support": ">=6.0",
13+
"illuminate/console": ">=6.0",
14+
"onliner/command-bus": "^1.0"
1515
},
1616
"autoload": {
1717
"psr-4": {

src/Console/CommandBusProcessCommand.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ class CommandBusProcessCommand extends Command
1919
protected $name = 'commands:process';
2020
protected $description = '';
2121

22-
/**
23-
* @var Consumer|AMQPConsumer
24-
*/
25-
private $consumer;
22+
private ?Consumer $consumer = null;
2623

2724
/**
2825
* @return array<array>
@@ -98,11 +95,7 @@ private function subscribeSignals(): void
9895

9996
foreach ([SIGINT, SIGTERM] as $signal) {
10097
pcntl_signal($signal, function () {
101-
if (!$this->consumer) {
102-
return;
103-
}
104-
105-
$this->consumer->stop();
98+
$this->consumer?->stop();
10699
});
107100
}
108101
}

src/Factory/SerializerFactory.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ class SerializerFactory
1919
*/
2020
public static function create(string $type, array $options = []): Serializer
2121
{
22-
switch ($type) {
23-
case 'native':
24-
return new Serializer\NativeSerializer();
25-
default:
26-
throw new Exception\UnknownSerializerException($type);
27-
}
22+
return match ($type) {
23+
'native' => new Serializer\NativeSerializer(),
24+
default => throw new Exception\UnknownSerializerException($type),
25+
};
2826
}
2927
}

src/Factory/TransportFactory.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ class TransportFactory
1414
{
1515
public const DEFAULT = 'memory://memory';
1616

17-
/**
18-
* @var Container
19-
*/
20-
private $container;
21-
2217
/**
2318
* @param Container $container
2419
*/
25-
public function __construct(Container $container)
20+
public function __construct(private Container $container)
2621
{
27-
$this->container = $container;
2822
}
2923

3024
/**
@@ -41,7 +35,7 @@ public function default(): Transport
4135
*
4236
* @return Transport
4337
*/
44-
public function create(string $key, $config): Transport
38+
public function create(string $key, string|array $config): Transport
4539
{
4640
if (is_array($config) && array_key_exists('url', $config)) {
4741
return $this->createFromUrl($config['url'], $config['options'] ?? []);
@@ -72,13 +66,10 @@ public function create(string $key, $config): Transport
7266
*/
7367
private function createFromUrl(string $url, array $options = []): Transport
7468
{
75-
switch (parse_url($url, PHP_URL_SCHEME)) {
76-
case 'amqp':
77-
return AMQPTransport::create($url, $options);
78-
case 'memory':
79-
return new Transport\MemoryTransport();
80-
default:
81-
throw new Exception\BadTransportException($url);
82-
}
69+
return match (parse_url($url, PHP_URL_SCHEME)) {
70+
'amqp' => AMQPTransport::create($url, $options),
71+
'memory' => new Transport\MemoryTransport(),
72+
default => throw new Exception\BadTransportException($url),
73+
};
8374
}
8475
}

src/Providers/CommandBusProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ private function registerTransportConnection(string $key, $config): string
172172
{
173173
$name = sprintf('onliner.commandbus.transport.%s', $key);
174174

175-
$this->app->singleton($name, function (Container $app) use ($key, $config) {
176-
return (new TransportFactory($app))->create($key, $config);
177-
});
175+
$this->app->singleton($name, fn(Container $app) => (new TransportFactory($app))->create($key, $config));
178176

179177
return $name;
180178
}

0 commit comments

Comments
 (0)