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 <louis@chmn.me>
  • Loading branch information
artonge committed Aug 28, 2024
1 parent 9d02485 commit 84d3a0a
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 70 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/composer/composer/InstalledVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static function getRawData()
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
Expand Down Expand Up @@ -341,7 +341,7 @@ private static function getInstalled()
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
Expand Down
2 changes: 0 additions & 2 deletions lib/composer/composer/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Copyright (c) Nils Adermann, Jordi Boggiano

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -18,4 +17,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

69 changes: 66 additions & 3 deletions lib/composer/composer/installed.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
{
"packages": [],
"dev": false,
"dev-package-names": []
"packages": [
{
"name": "bamarni/composer-bin-plugin",
"version": "1.8.2",
"version_normalized": "1.8.2.0",
"source": {
"type": "git",
"url": "https://github.com/bamarni/composer-bin-plugin.git",
"reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880",
"reference": "92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880",
"shasum": ""
},
"require": {
"composer-plugin-api": "^2.0",
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"composer/composer": "^2.0",
"ext-json": "*",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpunit/phpunit": "^8.5 || ^9.5",
"symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
"symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
"symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0"
},
"time": "2022-10-31T08:38:03+00:00",
"type": "composer-plugin",
"extra": {
"class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin"
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Bamarni\\Composer\\Bin\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "No conflicts for your bin dependencies",
"keywords": [
"composer",
"conflict",
"dependency",
"executable",
"isolation",
"tool"
],
"support": {
"issues": "https://github.com/bamarni/composer-bin-plugin/issues",
"source": "https://github.com/bamarni/composer-bin-plugin/tree/1.8.2"
},
"install-path": "../bamarni/composer-bin-plugin"
}
],
"dev": true,
"dev-package-names": [
"bamarni/composer-bin-plugin"
]
}
15 changes: 12 additions & 3 deletions lib/composer/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'b99276fdfbac6b1ff243807b8b5b8161f0f67a24',
'reference' => '9d0248545d85d6a680f2c9507f1bcfe13e889535',
'type' => 'library',
'install_path' => __DIR__ . '/../../../',
'aliases' => array(),
'dev' => false,
'dev' => true,
),
'versions' => array(
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'b99276fdfbac6b1ff243807b8b5b8161f0f67a24',
'reference' => '9d0248545d85d6a680f2c9507f1bcfe13e889535',
'type' => 'library',
'install_path' => __DIR__ . '/../../../',
'aliases' => array(),
'dev_requirement' => false,
),
'bamarni/composer-bin-plugin' => array(
'pretty_version' => '1.8.2',
'version' => '1.8.2.0',
'reference' => '92fd7b1e6e9cdae19b0d57369d8ad31a37b6a880',
'type' => 'composer-plugin',
'install_path' => __DIR__ . '/../bamarni/composer-bin-plugin',
'aliases' => array(),
'dev_requirement' => true,
),
),
);
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
Loading

0 comments on commit 84d3a0a

Please sign in to comment.