Skip to content

Commit

Permalink
chore: Apply php:cs recommendations
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>

[skip ci]
  • Loading branch information
artonge committed Aug 28, 2024
1 parent e1d1189 commit 10727b4
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions apps/files/lib/BackgroundJob/ScanFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function runScanner(string $user): void {
* @return string|false
*/
private function getUserToScan() {
if ($this->connection->getShardDefinition("filecache")) {
if ($this->connection->getShardDefinition('filecache')) {
// for sharded filecache, the "LIMIT" from the normal query doesn't work

// first we try it with a "LEFT JOIN" on mounts, this is fast, but might return a storage that isn't mounted.
Expand All @@ -82,7 +82,7 @@ private function getUserToScan() {
->where($query->expr()->lt('f.size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('f.parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->setMaxResults(10)
->groupBy("f.storage")
->groupBy('f.storage')
->runAcrossAllShards();

$result = $query->executeQuery();
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/DeleteOrphanedSharesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function shardingCleanup(): void {
$this->atomic(function () use ($deletedFiles, $deleteQb) {
$deleteQb->setParameter('ids', $deletedFiles, IQueryBuilder::PARAM_INT_ARRAY);
$deleted = $deleteQb->executeStatement();
$this->logger->debug("{deleted} orphaned share(s) deleted", [
$this->logger->debug('{deleted} orphaned share(s) deleted', [
'app' => 'DeleteOrphanedSharesJob',
'deleted' => $deleted,
]);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/DB/ArrayResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function fetch(int $fetchMode = PDO::FETCH_ASSOC) {
PDO::FETCH_ASSOC => $row,
PDO::FETCH_NUM => array_values($row),
PDO::FETCH_COLUMN => current($row),
default => throw new \InvalidArgumentException("Fetch mode not supported for array result"),
default => throw new \InvalidArgumentException('Fetch mode not supported for array result'),
};

}
Expand All @@ -51,7 +51,7 @@ public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array {
PDO::FETCH_COLUMN => array_map(function ($row) {
return current($row);
}, $this->rows),
default => throw new \InvalidArgumentException("Fetch mode not supported for array result"),
default => throw new \InvalidArgumentException('Fetch mode not supported for array result'),
};
}

Expand Down
8 changes: 4 additions & 4 deletions lib/private/DB/QueryBuilder/Partitioned/JoinCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function __construct(
* @return JoinCondition
*/
public static function merge(array $conditions): JoinCondition {
$fromColumn = "";
$toColumn = "";
$fromColumn = '';
$toColumn = '';
$fromAlias = null;
$toAlias = null;
$fromConditions = [];
Expand Down Expand Up @@ -99,9 +99,9 @@ private static function parseSubCondition($condition, string $join, string $alia
$isSubCondition = self::isExtraCondition($condition);
if ($isSubCondition) {
if (self::mentionsAlias($condition, $fromAlias)) {
return new JoinCondition("", null, "", null, [$condition], []);
return new JoinCondition('', null, '', null, [$condition], []);
} else {
return new JoinCondition("", null, "", null, [], [$condition]);
return new JoinCondition('', null, '', null, [], [$condition]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ public function executeQuery(?IDBConnection $connection = null): IResult {
}, false);
if ($hasNonLeftJoins) {
if (is_int($this->limit)) {
throw new InvalidPartitionedQueryException("Limit is not allowed in partitioned queries");
throw new InvalidPartitionedQueryException('Limit is not allowed in partitioned queries');
}
if (is_int($this->offset)) {
throw new InvalidPartitionedQueryException("Offset is not allowed in partitioned queries");
throw new InvalidPartitionedQueryException('Offset is not allowed in partitioned queries');
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public function __construct(
private ShardConnectionManager $shardConnectionManager,
) {
if (PHP_INT_SIZE < 8) {
throw new \Exception("sharding is only supported with 64bit php");
throw new \Exception('sharding is only supported with 64bit php');
}
}

private function getCache(): IMemcache {
if(is_null($this->cache)) {
$cache = $this->cacheFactory->createDistributed("shared_autoincrement");
$cache = $this->cacheFactory->createDistributed('shared_autoincrement');
if ($cache instanceof IMemcache) {
$this->cache = $cache;
} else {
Expand All @@ -61,15 +61,15 @@ public function getNextPrimaryKey(ShardDefinition $shardDefinition, int $shard):
$next = $this->getNextInner($shardDefinition);
if ($next !== null) {
if ($next > ShardDefinition::MAX_PRIMARY_KEY) {
throw new \Exception("Max primary key of " . ShardDefinition::MAX_PRIMARY_KEY . " exceeded");
throw new \Exception('Max primary key of ' . ShardDefinition::MAX_PRIMARY_KEY . ' exceeded');
}
// we encode the shard the primary key was originally inserted into to allow guessing the shard by primary key later on
return ($next << 8) | $shard;
} else {
$retries++;
}
}
throw new \Exception("Failed to get next primary key");
throw new \Exception('Failed to get next primary key');
}

/**
Expand All @@ -88,7 +88,7 @@ private function getNextInner(ShardDefinition $shardDefinition): ?int {
// if that is not the case we find the highest used id in the database increment it, and save it in the cache

// prevent inc from returning `1` if the key doesn't exist by setting it to a non-numeric value
$cache->add($shardDefinition->table, "empty-placeholder", self::TTL);
$cache->add($shardDefinition->table, 'empty-placeholder', self::TTL);
$next = $cache->inc($shardDefinition->table);

if ($cache instanceof IMemcacheTTL) {
Expand All @@ -101,7 +101,7 @@ private function getNextInner(ShardDefinition $shardDefinition): ?int {
return $next;
} elseif (is_int($next)) {
// we hit the edge case, so invalidate the cached value
if (!$cache->cas($shardDefinition->table, $next, "empty-placeholder")) {
if (!$cache->cas($shardDefinition->table, $next, 'empty-placeholder')) {
// someone else is changing the value concurrently, give up and retry
return null;
}
Expand All @@ -110,7 +110,7 @@ private function getNextInner(ShardDefinition $shardDefinition): ?int {
// discard the encoded initial shard
$current = $this->getMaxFromDb($shardDefinition) >> 8;
$next = max($current, self::MIN_VALID_KEY) + 1;
if ($cache->cas($shardDefinition->table, "empty-placeholder", $next)) {
if ($cache->cas($shardDefinition->table, 'empty-placeholder', $next)) {
return $next;
}

Expand All @@ -120,11 +120,11 @@ private function getNextInner(ShardDefinition $shardDefinition): ?int {
return $next;
} elseif(is_int($next)) {
// key got cleared, invalidate and retry
$cache->cas($shardDefinition->table, $next, "empty-placeholder");
$cache->cas($shardDefinition->table, $next, 'empty-placeholder');
return null;
} else {
// cleanup any non-numeric value other than the placeholder if that got stored somehow
$cache->ncad($shardDefinition->table, "empty-placeholder");
$cache->ncad($shardDefinition->table, 'empty-placeholder');
// retry
return null;
}
Expand All @@ -140,7 +140,7 @@ private function getMaxFromDb(ShardDefinition $shardDefinition): int {
$query = $connection->getQueryBuilder();
$query->select($shardDefinition->primaryKey)
->from($shardDefinition->table)
->orderBy($shardDefinition->primaryKey, "DESC")
->orderBy($shardDefinition->primaryKey, 'DESC')
->setMaxResults(1);
$result = $query->executeQuery()->fetchOne();
if ($result) {
Expand Down
8 changes: 4 additions & 4 deletions lib/private/DB/QueryBuilder/Sharded/CrossShardMoveHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public function loadItems(IDBConnection $connection, string $table, string $prim
$query = $connection->getQueryBuilder();
$query->select('*')
->from($table)
->where($query->expr()->in($primaryColumn, $query->createParameter("keys")));
->where($query->expr()->in($primaryColumn, $query->createParameter('keys')));

$chunks = array_chunk($primaryKeys, 1000);

$results = [];
foreach ($chunks as $chunk) {
$query->setParameter("keys", $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->setParameter('keys', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$results = array_merge($results, $query->execute()->fetchAll());
}

Expand Down Expand Up @@ -151,11 +151,11 @@ public function updateItems(IDBConnection $connection, string $table, string $sh
public function deleteItems(IDBConnection $connection, string $table, string $primaryColumn, array $primaryKeys): void {
$query = $connection->getQueryBuilder();
$query->delete($table)
->where($query->expr()->in($primaryColumn, $query->createParameter("keys")));
->where($query->expr()->in($primaryColumn, $query->createParameter('keys')));
$chunks = array_chunk($primaryKeys, 1000);

foreach ($chunks as $chunk) {
$query->setParameter("keys", $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->setParameter('keys', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->executeStatement();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/QueryBuilder/Sharded/ShardDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
public array $shards = [],
) {
if (count($this->shards) >= self::MAX_SHARDS) {
throw new \Exception("Only allowed maximum of " . self::MAX_SHARDS . " shards allowed");
throw new \Exception('Only allowed maximum of ' . self::MAX_SHARDS . ' shards allowed');
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/DB/QueryBuilder/Sharded/ShardQueryRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function executeQuery(
if ($cmp === 0) {
continue;
}
if ($sort['order'] === "DESC") {
if ($sort['order'] === 'DESC') {
$cmp = -$cmp;
}
return $cmp;
Expand Down Expand Up @@ -166,7 +166,7 @@ public function executeQuery(
*/
public function executeStatement(IQueryBuilder $query, bool $allShards, array $shardKeys, array $primaryKeys): int {
if ($query->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT) {
throw new \Exception("insert queries need special handling");
throw new \Exception('insert queries need special handling');
}

$shards = $this->getShards($allShards, $shardKeys);
Expand Down
10 changes: 5 additions & 5 deletions lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder {
private ?int $updateShardKey = null;
private ?int $limit = null;
private ?int $offset = null;
/** @var array{column: string, order: string}[] */
/** @var array{column: string, order: string}[] */
private array $sortList = [];
private string $mainTable = '';

Expand Down Expand Up @@ -276,13 +276,13 @@ public function setFirstResult($firstResult) {
}

public function addOrderBy($sort, $order = null) {
$this->registerOrder((string) $sort, (string)$order ?? "ASC");
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
return parent::orderBy($sort, $order);
}

public function orderBy($sort, $order = null) {
$this->sortList = [];
$this->registerOrder((string) $sort, (string)$order ?? "ASC");
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
return parent::orderBy($sort, $order);
}

Expand Down Expand Up @@ -329,7 +329,7 @@ public function validate(): void {
}
if ($this->shardDefinition && !$this->allShards) {
if (empty($this->getShardKeys()) && empty($this->getPrimaryKeys())) {
throw new InvalidShardedQueryException("No shard key or primary key set for query");
throw new InvalidShardedQueryException('No shard key or primary key set for query');
}
}
if ($this->shardDefinition && $this->updateShardKey) {
Expand All @@ -347,7 +347,7 @@ public function validate(): void {
}, $oldShardKeys)));
$newShard = $this->shardDefinition->getShardForKey((int)$newShardKey);
if ($oldShards === [$newShard]) {
throw new InvalidShardedQueryException("Update statement would move rows to a different shard");
throw new InvalidShardedQueryException('Update statement would move rows to a different shard');
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@ private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache
$sourceConnection = $helper->getConnection($shardDefinition, $sourceCache->getNumericStorageId());
$targetConnection = $helper->getConnection($shardDefinition, $this->getNumericStorageId());

$cacheItems = $helper->loadItems($sourceConnection, "filecache", "fileid", $fileIds);
$extendedItems = $helper->loadItems($sourceConnection, "filecache_extended", "fileid", $fileIds);
$metadataItems = $helper->loadItems($sourceConnection, "files_metadata", "file_id", $fileIds);
$cacheItems = $helper->loadItems($sourceConnection, 'filecache', 'fileid', $fileIds);
$extendedItems = $helper->loadItems($sourceConnection, 'filecache_extended', 'fileid', $fileIds);
$metadataItems = $helper->loadItems($sourceConnection, 'files_metadata', 'file_id', $fileIds);

// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
$removeEncryptedFlag = ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper()) && !$this->hasEncryptionWrapper();
Expand All @@ -1246,9 +1246,9 @@ private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache
$targetConnection->beginTransaction();

try {
$helper->saveItems($targetConnection, "filecache", $cacheItems);
$helper->saveItems($targetConnection, "filecache_extended", $extendedItems);
$helper->saveItems($targetConnection, "files_metadata", $metadataItems);
$helper->saveItems($targetConnection, 'filecache', $cacheItems);
$helper->saveItems($targetConnection, 'filecache_extended', $extendedItems);
$helper->saveItems($targetConnection, 'files_metadata', $metadataItems);
} catch (\Exception $e) {
$targetConnection->rollback();
throw $e;
Expand All @@ -1257,9 +1257,9 @@ private function moveFromStorageSharded(ShardDefinition $shardDefinition, ICache
$sourceConnection->beginTransaction();

try {
$helper->deleteItems($sourceConnection, "filecache", "fileid", $fileIds);
$helper->deleteItems($sourceConnection, "filecache_extended", "fileid", $fileIds);
$helper->deleteItems($sourceConnection, "files_metadata", "file_id", $fileIds);
$helper->deleteItems($sourceConnection, 'filecache', 'fileid', $fileIds);
$helper->deleteItems($sourceConnection, 'filecache_extended', 'fileid', $fileIds);
$helper->deleteItems($sourceConnection, 'files_metadata', 'file_id', $fileIds);
} catch (\Exception $e) {
$targetConnection->rollback();
$sourceConnection->rollBack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function getBuilder(string $platform): IQueryBuilder {
public function testParseCondition(string $platform): void {
$query = $this->getBuilder($platform);
$param1 = $query->createNamedParameter('files');
$param2 = $query->createNamedParameter("test");
$param2 = $query->createNamedParameter('test');
$condition = $query->expr()->andX(
$query->expr()->eq('tagmap.categoryid', 'tag.id'),
$query->expr()->eq('tag.type', $param1),
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testValidateWithNoKey() {

$this->expectException(InvalidShardedQueryException::class);
$query->validate();
$this->fail("exception expected");
$this->fail('exception expected');
}

public function testValidateNonSharedTable() {
Expand All @@ -114,7 +114,7 @@ public function testGetShardKeyMultipleSingleParam() {
$query->expr()->eq('storage', $query->createNamedParameter(10, IQueryBuilder::PARAM_INT)),
$query->expr()->andX(
$query->expr()->eq('storage', $query->createNamedParameter(11, IQueryBuilder::PARAM_INT)),
$query->expr()->like('path', $query->createNamedParameter("foo/%"))
$query->expr()->like('path', $query->createNamedParameter('foo/%'))
)
)
));
Expand Down
14 changes: 7 additions & 7 deletions tests/lib/Files/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,17 @@ public function testMoveFromCache() {
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar'];
$folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];

$this->cache2->put("folder", $folderData);
$this->cache2->put("folder/sub", $data);
$this->cache2->put('folder', $folderData);
$this->cache2->put('folder/sub', $data);


$this->cache->moveFromCache($this->cache2, "folder", "targetfolder");
$this->cache->moveFromCache($this->cache2, 'folder', 'targetfolder');

$this->assertFalse($this->cache2->inCache("folder"));
$this->assertFalse($this->cache2->inCache("folder/sub"));
$this->assertFalse($this->cache2->inCache('folder'));
$this->assertFalse($this->cache2->inCache('folder/sub'));

$this->assertTrue($this->cache->inCache("targetfolder"));
$this->assertTrue($this->cache->inCache("targetfolder/sub"));
$this->assertTrue($this->cache->inCache('targetfolder'));
$this->assertTrue($this->cache->inCache('targetfolder/sub'));
}

public function testGetIncomplete() {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Preview/BackgroundCleanupJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testCleanupSystemCron() {

public function testCleanupAjax() {
if ($this->connection->getShardDefinition('filecache')) {
$this->markTestSkipped("ajax cron is not supported for sharded setups");
$this->markTestSkipped('ajax cron is not supported for sharded setups');
return;
}
$files = $this->setup11Previews();
Expand Down Expand Up @@ -179,7 +179,7 @@ public function testCleanupAjax() {

public function testOldPreviews() {
if ($this->connection->getShardDefinition('filecache')) {
$this->markTestSkipped("old previews are not supported for sharded setups");
$this->markTestSkipped('old previews are not supported for sharded setups');
return;
}
$appdata = \OC::$server->getAppDataDir('preview');
Expand Down
12 changes: 6 additions & 6 deletions tests/preseed-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@

if (getenv('SHARDING') == '1') {
$CONFIG['dbsharding'] = [
"filecache" => [
"shards" => [
'filecache' => [
'shards' => [
[
"port" => 5001,
'port' => 5001,
],
[
"port" => 5002,
'port' => 5002,
],
[
"port" => 5003,
'port' => 5003,
],
[
"port" => 5004,
'port' => 5004,
],
]
]
Expand Down

0 comments on commit 10727b4

Please sign in to comment.