Skip to content

Commit 734518b

Browse files
committed
Upgrade language level to php 7.4, add strong type hints, update dependencies and make PHPUnit tests compatible
1 parent bfe79be commit 734518b

27 files changed

+4698
-706
lines changed

.php_cs.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->notPath('vendor')
5+
->in(__DIR__)
6+
->name('*.php')
7+
->ignoreDotFiles(true)
8+
->ignoreVCS(true);
9+
10+
return PhpCsFixer\Config::create()
11+
->setFinder($finder)
12+
->setRiskyAllowed(false)
13+
->setRules([
14+
'@Symfony' => true,
15+
'@PSR2' => true,
16+
'array_syntax' => ['syntax' => 'short'],
17+
'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => true],
18+
'concat_space' => ['spacing' => 'one'],
19+
'heredoc_to_nowdoc' => true,
20+
'no_multiline_whitespace_before_semicolons' => true,
21+
'no_unused_imports' => true,
22+
'no_useless_return' => true,
23+
'not_operator_with_successor_space' => true,
24+
'ordered_imports' => true,
25+
'phpdoc_add_missing_param_annotation' => true,
26+
'phpdoc_order' => true,
27+
'unary_operator_spaces' => false
28+
]
29+
);

bin/redis-server.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
use Clue\Redis\Protocol\Model\ModelInterface;
36
use Clue\Redis\Server\Client;
47
use Clue\Redis\Server\Factory;
58
use Clue\Redis\Server\Server;
6-
use Clue\Redis\Protocol\Model\ModelInterface;
79

810
require __DIR__ . '/../vendor/autoload.php';
911

@@ -12,40 +14,40 @@
1214

1315
// read port definition from command args
1416
$port = 6379;
15-
if (isset($argv[2]) && $argv[1] === '--port') {
16-
$port = (int)$argv[2];
17+
if (isset($argv[2]) && '--port' === $argv[1]) {
18+
$port = (int) $argv[2];
1719
}
1820

1921
$address = '0.0.0.0:' . $port;
2022
$debug = false;
2123

22-
$factory->createServer($address)->then(function(Server $server) use ($address, $debug) {
24+
$factory->createServer($address)->then(function (Server $server) use ($address, $debug): void {
2325
echo 'server listening on ' . $address . '!' . PHP_EOL;
2426

2527
echo 'you can now connect to this server via redis-cli, redis-benchmark or any other redis client' . PHP_EOL;
2628

2729
if ($debug) {
2830
echo 'Debugging is turned on, this will significantly decrease performance' . PHP_EOL;
2931

30-
$server->on('connection', function ($client) {
32+
$server->on('connection', function (Client $client): void {
3133
echo 'client connected' . PHP_EOL;
3234
});
3335

34-
$server->on('error', function ($error, $client) {
36+
$server->on('error', function ($error, Client $client): void {
3537
echo 'ERROR: ' . $error->getMessage() . PHP_EOL;
3638
});
3739

3840
$server->on('request', function (ModelInterface $request, Client $client) {
3941
echo $client->getRequestDebug($request) . PHP_EOL;
4042
});
4143

42-
$server->on('disconnection', function ($client) {
44+
$server->on('disconnection', function (Client $client): void {
4345
echo 'client disconnected' . PHP_EOL;
4446
});
4547
} else {
4648
echo 'Debugging is turned off, so you should not see any further output' . PHP_EOL;
4749
}
48-
}, function ($e) {
50+
}, function (\Throwable $e): void {
4951
fwrite(STDERR, 'ERROR: Unable to start listening server: ' . $e->getMessage() . PHP_EOL);
5052
});
5153

composer.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=5.3",
14+
"php": ">=7.4",
1515
"react/promise": "~1.0|~2.0",
1616
"react/socket": "0.3.*|0.4.*",
1717
"react/event-loop": "0.3.*|0.4.*",
1818
"clue/redis-protocol": "0.3.*",
1919
"evenement/evenement": "~1.0|~2.0"
2020
},
2121
"autoload": {
22-
"psr-4": { "Clue\\Redis\\Server\\": "src" }
22+
"psr-4": {
23+
"Clue\\Redis\\Server\\": "src"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Clue\\Redis\\Server\\Tests\\": "tests"
29+
}
2330
},
2431
"bin": [
2532
"bin/redis-server.php"
26-
]
33+
],
34+
"require-dev": {
35+
"phpunit/phpunit": "^9",
36+
"friendsofphp/php-cs-fixer": "^2.16"
37+
}
2738
}

0 commit comments

Comments
 (0)