Add CS job (#1024)

* Add CS job

* Apply PHP71Migration ruleset
This commit is contained in:
Fran Moreno
2023-01-18 19:02:26 +01:00
committed by GitHub
parent 113145f306
commit d6dc6e51e1
29 changed files with 71 additions and 42 deletions
+28
View File
@@ -0,0 +1,28 @@
name: Linters
on:
push:
branches:
- main
- v2.**
pull_request:
jobs:
php-cs-fixer:
name: linter
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP with Composer and extensions
with:
php-version: 8.1
tools: php-cs-fixer
uses: shivammathur/setup-php@v2
- name: Run php-cs-fixer
run: php-cs-fixer fix --diff --dry-run --allow-risky=yes --using-cache=no
+1
View File
@@ -13,6 +13,7 @@ EOS;
return (new PhpCsFixer\Config)
->setUsingCache(false)
->setRules([
'@PHP71Migration' => true,
'header_comment' => ['header' => $PREDIS_HEADER],
'@Symfony' => true,
'phpdoc_separation' => false,
+1 -1
View File
@@ -54,7 +54,7 @@ class NaiveDistributor implements DistributorInterface, HashGeneratorInterface
public function getBySlot($slot)
{
return isset($this->nodes[$slot]) ? $this->nodes[$slot] : null;
return $this->nodes[$slot] ?? null;
}
public function getByHash($hash)
+1 -1
View File
@@ -36,7 +36,7 @@ function zpop($client, $key)
];
$client->transaction($options, function ($tx) use ($key, &$element) {
@list($element) = $tx->zrange($key, 0, 0);
@[$element] = $tx->zrange($key, 0, 0);
if (isset($element)) {
$tx->multi(); // With CAS, MULTI *must* be explicitly invoked.
@@ -118,7 +118,7 @@ abstract class CursorBasedIterator implements Iterator
*/
protected function fetch()
{
list($cursor, $elements) = $this->executeCommand();
[$cursor, $elements] = $this->executeCommand();
if (!$cursor) {
$this->fetchmore = false;
+1 -1
View File
@@ -33,7 +33,7 @@ class BITOP extends RedisCommand
public function setArguments(array $arguments)
{
if (count($arguments) === 3 && is_array($arguments[2])) {
list($operation, $destination) = $arguments;
[$operation, $destination] = $arguments;
$arguments = $arguments[2];
array_unshift($arguments, $operation, $destination);
}
+1 -1
View File
@@ -33,7 +33,7 @@ class BLPOP extends RedisCommand
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[0])) {
list($arguments, $timeout) = $arguments;
[$arguments, $timeout] = $arguments;
array_push($arguments, $timeout);
}
+1 -1
View File
@@ -33,7 +33,7 @@ class BRPOP extends RedisCommand
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[0])) {
list($arguments, $timeout) = $arguments;
[$arguments, $timeout] = $arguments;
array_push($arguments, $timeout);
}
+1 -1
View File
@@ -63,7 +63,7 @@ class CLIENT extends RedisCommand
$client = [];
foreach (explode(' ', $clientData) as $kv) {
@list($k, $v) = explode('=', $kv);
@[$k, $v] = explode('=', $kv);
$client[$k] = $v;
}
+4 -4
View File
@@ -62,7 +62,7 @@ class INFO extends RedisCommand
continue;
}
list($k, $v) = $this->parseRow($row);
[$k, $v] = $this->parseRow($row);
$current[$k] = $v;
}
@@ -81,7 +81,7 @@ class INFO extends RedisCommand
continue;
}
list($k, $v) = $this->parseRow($row);
[$k, $v] = $this->parseRow($row);
$info[$k] = $v;
}
@@ -97,7 +97,7 @@ class INFO extends RedisCommand
*/
protected function parseRow($row)
{
list($k, $v) = explode(':', $row, 2);
[$k, $v] = explode(':', $row, 2);
if (preg_match('/^db\d+$/', $k)) {
$v = $this->parseDatabaseStats($v);
@@ -118,7 +118,7 @@ class INFO extends RedisCommand
$db = [];
foreach (explode(',', $str) as $dbvar) {
list($dbvk, $dbvv) = explode('=', $dbvar);
[$dbvk, $dbvv] = explode('=', $dbvar);
$db[trim($dbvk)] = $dbvv;
}
+2 -2
View File
@@ -37,8 +37,8 @@ class ZRANGEBYLEX extends ZRANGE
$limit = array_change_key_case($opts['LIMIT'], CASE_UPPER);
$finalizedOpts[] = 'LIMIT';
$finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0];
$finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1];
$finalizedOpts[] = $limit['OFFSET'] ?? $limit[0];
$finalizedOpts[] = $limit['COUNT'] ?? $limit[1];
}
return $finalizedOpts;
+2 -2
View File
@@ -37,8 +37,8 @@ class ZRANGEBYSCORE extends ZRANGE
$limit = array_change_key_case($opts['LIMIT'], CASE_UPPER);
$finalizedOpts[] = 'LIMIT';
$finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0];
$finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1];
$finalizedOpts[] = $limit['OFFSET'] ?? $limit[0];
$finalizedOpts[] = $limit['COUNT'] ?? $limit[1];
}
return array_merge($finalizedOpts, parent::prepareOptions($options));
+3 -3
View File
@@ -285,7 +285,7 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
foreach ($response as $slots) {
// We only support master servers for now, so we ignore subsequent
// elements in the $slots array identifying slaves.
list($start, $end, $master) = $slots;
[$start, $end, $master] = $slots;
if ($master[0] === '') {
$this->slotmap->setSlots($start, $end, (string) $connection);
@@ -461,7 +461,7 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
*/
protected function onMovedResponse(CommandInterface $command, $details)
{
list($slot, $connectionID) = explode(' ', $details, 2);
[$slot, $connectionID] = explode(' ', $details, 2);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
@@ -487,7 +487,7 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
*/
protected function onAskResponse(CommandInterface $command, $details)
{
list($slot, $connectionID) = explode(' ', $details, 2);
[$slot, $connectionID] = explode(' ', $details, 2);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
@@ -375,7 +375,7 @@ class MasterSlaveReplication implements ReplicationInterface
continue;
}
list($k, $v) = explode(':', $row, 2);
[$k, $v] = explode(':', $row, 2);
$info[$k] = $v;
}
+1 -1
View File
@@ -166,7 +166,7 @@ class Consumer implements Iterator
};
$event = preg_replace_callback('/ \(db (\d+)\) | \[(\d+) (.*?)\] /', $callback, $event, 1);
@list($timestamp, $command, $arguments) = explode(' ', $event, 3);
@[$timestamp, $command, $arguments] = explode(' ', $event, 3);
return (object) [
'timestamp' => (float) $timestamp,
+1 -1
View File
@@ -41,7 +41,7 @@ class Error implements ErrorInterface
*/
public function getErrorType()
{
list($errorType) = explode(' ', $this->getMessage(), 2);
[$errorType] = explode(' ', $this->getMessage(), 2);
return $errorType;
}
+1 -1
View File
@@ -26,7 +26,7 @@ class ServerException extends PredisException implements ErrorInterface
*/
public function getErrorType()
{
list($errorType) = explode(' ', $this->getMessage(), 2);
[$errorType] = explode(' ', $this->getMessage(), 2);
return $errorType;
}
+1 -1
View File
@@ -75,7 +75,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase
public function assertRedisCommand($expected, $actual, string $message = ''): void
{
if (is_array($expected)) {
@list($command, $arguments) = $expected;
@[$command, $arguments] = $expected;
} else {
$command = $expected;
$arguments = null;
+3 -3
View File
@@ -1268,9 +1268,9 @@ class ClientTest extends PredisTestCase
{
$defaults = $this->getDefaultParametersArray();
$scheme = isset($parameters['scheme']) ? $parameters['scheme'] : $defaults['scheme'];
$host = isset($parameters['host']) ? $parameters['host'] : $defaults['host'];
$port = isset($parameters['port']) ? $parameters['port'] : $defaults['port'];
$scheme = $parameters['scheme'] ?? $defaults['scheme'];
$host = $parameters['host'] ?? $defaults['host'];
$port = $parameters['port'] ?? $defaults['port'];
unset($parameters['scheme'], $parameters['host'], $parameters['port']);
$uriString = "$scheme://$host:$port/?";
@@ -29,7 +29,7 @@ class KetamaRingTest extends PredisDistributorTestCase
{
/** @var HashGeneratorInterface */
$ring = $this->getDistributorInstance();
list(, $hash) = unpack('V', md5('foobar', true));
[, $hash] = unpack('V', md5('foobar', true));
$this->assertEquals($hash, $ring->hash('foobar'));
}
+1 -1
View File
@@ -310,7 +310,7 @@ BUFFER;
$command = $this->getCommand();
$this->assertIsArray($info = $redis->executeCommand($command));
$this->assertArrayHasKey('redis_version', isset($info['Server']) ? $info['Server'] : $info);
$this->assertArrayHasKey('redis_version', $info['Server'] ?? $info);
}
/**
+1 -1
View File
@@ -98,7 +98,7 @@ class SETRANGE_Test extends PredisCommandTestCase
$this->assertSame(4, $redis->setrange('key:binary', 0, pack('i', -2147483648)));
list($unpacked) = array_values(unpack('i', $redis->get('key:binary')));
[$unpacked] = array_values(unpack('i', $redis->get('key:binary')));
$this->assertEquals(-2147483648, $unpacked);
}
@@ -121,8 +121,8 @@ class UNSUBSCRIBE_Test extends PredisCommandTestCase
$this->assertSame(['subscribe', 'channel:foo', 1], $redis->subscribe('channel:foo'));
$this->assertSame(['subscribe', 'channel:bar', 2], $redis->subscribe('channel:bar'));
list($_, $unsubscribed1, $_) = $redis->unsubscribe();
list($_, $unsubscribed2, $_) = $redis->getConnection()->read();
[$_, $unsubscribed1, $_] = $redis->unsubscribe();
[$_, $unsubscribed2, $_] = $redis->getConnection()->read();
$this->assertSameValues(['channel:foo', 'channel:bar'], [$unsubscribed1, $unsubscribed2]);
$this->assertSame('echoed', $redis->echo('echoed'));
@@ -260,7 +260,7 @@ class AggregateTest extends PredisTestCase
*/
public function ___AggregateConnectionSkipCreationOnConnectionInstance(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();
/** @var ClusterInterface|MockObject */
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock();
@@ -285,7 +285,7 @@ class AggregateTest extends PredisTestCase
*/
public function ___AggregateConnectionWithMixedParameters(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();
/** @var ClusterInterface|MockObject */
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock();
+3 -3
View File
@@ -439,7 +439,7 @@ class FactoryTest extends PredisTestCase
*/
public function testDefineConnectionWithFQN(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();
$parameters = new Parameters(['scheme' => 'foobar']);
$factory = new Factory();
@@ -455,7 +455,7 @@ class FactoryTest extends PredisTestCase
*/
public function testDefineConnectionWithCallable(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();
$parameters = new Parameters(['scheme' => 'foobar']);
$factory = new Factory();
@@ -527,7 +527,7 @@ class FactoryTest extends PredisTestCase
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Unknown connection scheme: 'test'");
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();
$factory = new Factory();
+3 -3
View File
@@ -415,9 +415,9 @@ class ParametersTest extends PredisTestCase
{
$defaults = $this->getDefaultParametersArray();
$scheme = isset($parameters['scheme']) ? $parameters['scheme'] : $defaults['scheme'];
$host = isset($parameters['host']) ? $parameters['host'] : $defaults['host'];
$port = isset($parameters['port']) ? $parameters['port'] : $defaults['port'];
$scheme = $parameters['scheme'] ?? $defaults['scheme'];
$host = $parameters['host'] ?? $defaults['host'];
$port = $parameters['port'] ?? $defaults['port'];
unset($parameters['scheme'], $parameters['host'], $parameters['port']);
$uriString = "$scheme://$host:$port/?";
@@ -989,7 +989,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
$replication
->getReplicationStrategy()
->setCommandReadOnly('exists', function ($cmd) {
list($arg1) = $cmd->getArguments();
[$arg1] = $cmd->getArguments();
return $arg1 === 'foo';
});
+1 -1
View File
@@ -541,7 +541,7 @@ class PipelineTest extends PredisTestCase
throw new InvalidArgumentException("Expected ECHO, got {$id}");
}
list($echoed) = $command->getArguments();
[$echoed] = $command->getArguments();
return $echoed;
};
+1 -1
View File
@@ -940,7 +940,7 @@ class MultiExecTest extends PredisTestCase
return true;
case 'ECHO':
@list($trigger) = $command->getArguments();
@[$trigger] = $command->getArguments();
if (strpos($trigger, 'ERR ') === 0) {
throw new Response\ServerException($trigger);
}