Skip to content

Commit

Permalink
Add CS job (predis#1024)
Browse files Browse the repository at this point in the history
* Add CS job

* Apply PHP71Migration ruleset
  • Loading branch information
franmomu authored Jan 18, 2023
1 parent 113145f commit d6dc6e5
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 42 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
return (new PhpCsFixer\Config)
->setUsingCache(false)
->setRules([
'@PHP71Migration' => true,
'header_comment' => ['header' => $PREDIS_HEADER],
'@Symfony' => true,
'phpdoc_separation' => false,
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_cluster_distributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getSlot($hash)

public function getBySlot($slot)
{
return isset($this->nodes[$slot]) ? $this->nodes[$slot] : null;
return $this->nodes[$slot] ?? null;
}

public function getByHash($hash)
Expand Down
2 changes: 1 addition & 1 deletion examples/transaction_using_cas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/Iterator/CursorBasedIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ abstract protected function executeCommand();
*/
protected function fetch()
{
list($cursor, $elements) = $this->executeCommand();
[$cursor, $elements] = $this->executeCommand();

if (!$cursor) {
$this->fetchmore = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Redis/BITOP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getId()
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Redis/BLPOP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getId()
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[0])) {
list($arguments, $timeout) = $arguments;
[$arguments, $timeout] = $arguments;
array_push($arguments, $timeout);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Redis/BRPOP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getId()
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[0])) {
list($arguments, $timeout) = $arguments;
[$arguments, $timeout] = $arguments;
array_push($arguments, $timeout);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Redis/CLIENT.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function parseClientList($data)
$client = [];

foreach (explode(' ', $clientData) as $kv) {
@list($k, $v) = explode('=', $kv);
@[$k, $v] = explode('=', $kv);
$client[$k] = $v;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Command/Redis/INFO.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function parseNewResponseFormat($lines)
continue;
}

list($k, $v) = $this->parseRow($row);
[$k, $v] = $this->parseRow($row);
$current[$k] = $v;
}

Expand All @@ -81,7 +81,7 @@ public function parseOldResponseFormat($lines)
continue;
}

list($k, $v) = $this->parseRow($row);
[$k, $v] = $this->parseRow($row);
$info[$k] = $v;
}

Expand All @@ -97,7 +97,7 @@ public function parseOldResponseFormat($lines)
*/
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);
Expand All @@ -118,7 +118,7 @@ protected function parseDatabaseStats($str)
$db = [];

foreach (explode(',', $str) as $dbvar) {
list($dbvk, $dbvv) = explode('=', $dbvar);
[$dbvk, $dbvv] = explode('=', $dbvar);
$db[trim($dbvk)] = $dbvv;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/Redis/ZRANGEBYLEX.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected function prepareOptions($options)
$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;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Redis/ZRANGEBYSCORE.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected function prepareOptions($options)
$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));
Expand Down
6 changes: 3 additions & 3 deletions src/Connection/Cluster/RedisCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function askSlotMap(NodeConnectionInterface $connection = null)
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);
Expand Down Expand Up @@ -461,7 +461,7 @@ protected function onErrorResponse(CommandInterface $command, ErrorResponseInter
*/
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);
Expand All @@ -487,7 +487,7 @@ protected function onMovedResponse(CommandInterface $command, $details)
*/
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);
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Replication/MasterSlaveReplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private function handleInfoResponse($response)
continue;
}

list($k, $v) = explode(':', $row, 2);
[$k, $v] = explode(':', $row, 2);
$info[$k] = $v;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Monitor/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private function getValue()
};

$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,
Expand Down
2 changes: 1 addition & 1 deletion src/Response/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getMessage()
*/
public function getErrorType()
{
list($errorType) = explode(' ', $this->getMessage(), 2);
[$errorType] = explode(' ', $this->getMessage(), 2);

return $errorType;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Response/ServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/PredisTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function isRedisCommand($command = null, ?array $arguments = null): Redis
public function assertRedisCommand($expected, $actual, string $message = ''): void
{
if (is_array($expected)) {
@list($command, $arguments) = $expected;
@[$command, $arguments] = $expected;
} else {
$command = $expected;
$arguments = null;
Expand Down
6 changes: 3 additions & 3 deletions tests/Predis/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,9 +1268,9 @@ protected function getParametersString(array $parameters): string
{
$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:https://$host:$port/?";
Expand Down
2 changes: 1 addition & 1 deletion tests/Predis/Cluster/Distributor/KetamaRingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testHash(): void
{
/** @var HashGeneratorInterface */
$ring = $this->getDistributorInstance();
list(, $hash) = unpack('V', md5('foobar', true));
[, $hash] = unpack('V', md5('foobar', true));

$this->assertEquals($hash, $ring->hash('foobar'));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Predis/Command/Redis/INFO_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function testReturnsAnArrayOfInfo(): void
$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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Predis/Command/Redis/SETRANGE_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testHandlesBinaryData(): void

$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);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Predis/Command/Redis/UNSUBSCRIBE_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function testUnsubscribesFromAllSubscribedChannels(): void
$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'));
Expand Down
4 changes: 2 additions & 2 deletions tests/Predis/Configuration/Option/AggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function testThrowsExceptionOnInstanceOfAggregateConnectionInterface(): v
*/
public function ___AggregateConnectionSkipCreationOnConnectionInstance(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();

/** @var ClusterInterface|MockObject */
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock();
Expand All @@ -285,7 +285,7 @@ public function ___AggregateConnectionSkipCreationOnConnectionInstance(): void
*/
public function ___AggregateConnectionWithMixedParameters(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();

/** @var ClusterInterface|MockObject */
$cluster = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock();
Expand Down
6 changes: 3 additions & 3 deletions tests/Predis/Connection/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public function testCreateUndefinedConnection(): void
*/
public function testDefineConnectionWithFQN(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();

$parameters = new Parameters(['scheme' => 'foobar']);
$factory = new Factory();
Expand All @@ -455,7 +455,7 @@ public function testDefineConnectionWithFQN(): void
*/
public function testDefineConnectionWithCallable(): void
{
list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();

$parameters = new Parameters(['scheme' => 'foobar']);
$factory = new Factory();
Expand Down Expand Up @@ -527,7 +527,7 @@ public function testDefineAndUndefineConnection(): void
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Unknown connection scheme: 'test'");

list(, $connectionClass) = $this->getMockConnectionClass();
[, $connectionClass] = $this->getMockConnectionClass();

$factory = new Factory();

Expand Down
6 changes: 3 additions & 3 deletions tests/Predis/Connection/ParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ protected function getParametersString(array $parameters): string
{
$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:https://$host:$port/?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ public function testAcceptsCallableToOverrideReadOnlyFlagForCommands(): void
$replication
->getReplicationStrategy()
->setCommandReadOnly('exists', function ($cmd) {
list($arg1) = $cmd->getArguments();
[$arg1] = $cmd->getArguments();

return $arg1 === 'foo';
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Predis/Pipeline/PipelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ protected function getReadCallback(): callable
throw new InvalidArgumentException("Expected ECHO, got {$id}");
}

list($echoed) = $command->getArguments();
[$echoed] = $command->getArguments();

return $echoed;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/Predis/Transaction/MultiExecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ protected function getExecuteCallback(
return true;

case 'ECHO':
@list($trigger) = $command->getArguments();
@[$trigger] = $command->getArguments();
if (strpos($trigger, 'ERR ') === 0) {
throw new Response\ServerException($trigger);
}
Expand Down

0 comments on commit d6dc6e5

Please sign in to comment.