Skip to content

Commit 2c6fcf1

Browse files
committed
coding style
1 parent 209b34b commit 2c6fcf1

27 files changed

Lines changed: 88 additions & 106 deletions

src/Bridges/DatabaseDI/DatabaseExtension.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ public function getConfigSchema(): Nette\Schema\Schema
4141
'reflection' => Expect::string(), // BC
4242
'conventions' => Expect::string('discovered'), // Nette\Database\Conventions\DiscoveredConventions
4343
'autowired' => Expect::bool(),
44-
])
45-
)->before(function ($val) {
46-
return is_array(reset($val)) || reset($val) === null
44+
]),
45+
)->before(fn($val) => is_array(reset($val)) || reset($val) === null
4746
? $val
48-
: ['default' => $val];
49-
});
47+
: ['default' => $val]);
5048
}
5149

5250

5351
public function loadConfiguration()
5452
{
5553
$autowired = true;
5654
foreach ($this->config as $name => $config) {
57-
$config->autowired = $config->autowired ?? $autowired;
55+
$config->autowired ??= $autowired;
5856
$autowired = false;
5957
$this->setupDatabase($config, $name);
6058
}

src/Database/Explorer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
Connection $connection,
3838
Structure $structure,
3939
Conventions $conventions = null,
40-
Nette\Caching\IStorage $cacheStorage = null
40+
Nette\Caching\IStorage $cacheStorage = null,
4141
) {
4242
$this->connection = $connection;
4343
$this->structure = $structure;
@@ -69,9 +69,7 @@ public function rollBack(): void
6969
*/
7070
public function transaction(callable $callback)
7171
{
72-
return $this->connection->transaction(function () use ($callback) {
73-
return $callback($this);
74-
});
72+
return $this->connection->transaction(fn() => $callback($this));
7573
}
7674

7775

src/Database/Helpers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public static function createDebugPanel(
289289
bool $explain,
290290
string $name,
291291
Tracy\Bar $bar,
292-
Tracy\BlueScreen $blueScreen
292+
Tracy\BlueScreen $blueScreen,
293293
): ?ConnectionPanel {
294294
return self::initializeTracy($connection, true, $name, $explain, $bar, $blueScreen);
295295
}
@@ -301,16 +301,16 @@ public static function initializeTracy(
301301
string $name = '',
302302
bool $explain = true,
303303
Tracy\Bar $bar = null,
304-
Tracy\BlueScreen $blueScreen = null
304+
Tracy\BlueScreen $blueScreen = null,
305305
): ?ConnectionPanel {
306-
$blueScreen = $blueScreen ?? Tracy\Debugger::getBlueScreen();
306+
$blueScreen ??= Tracy\Debugger::getBlueScreen();
307307
$blueScreen->addPanel([ConnectionPanel::class, 'renderException']);
308308

309309
if ($addBarPanel) {
310310
$panel = new ConnectionPanel($connection, $blueScreen);
311311
$panel->explain = $explain;
312312
$panel->name = $name;
313-
$bar = $bar ?? Tracy\Debugger::getBar();
313+
$bar ??= Tracy\Debugger::getBar();
314314
$bar->addPanel($panel);
315315
}
316316
return $panel ?? null;

src/Database/SqlPreprocessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function process(array $params, bool $useParams = false): array
113113
|/\*.*?\*/
114114
|--[^\n]*
115115
~Dsix',
116-
\Closure::fromCallable([$this, 'callback'])
116+
\Closure::fromCallable([$this, 'callback']),
117117
);
118118
} else {
119119
throw new Nette\InvalidArgumentException('There are more parameters than placeholders.');
@@ -220,7 +220,7 @@ private function formatValue($value, string $mode = null): string
220220
if (!is_array($value[0]) && !$value[0] instanceof Row) {
221221
throw new Nette\InvalidArgumentException(
222222
'Automaticaly detected multi-insert, but values aren\'t array. If you need try to change mode like "?['
223-
. implode('|', self::MODES) . ']". Mode "' . $mode . '" was used.'
223+
. implode('|', self::MODES) . ']". Mode "' . $mode . '" was used.',
224224
);
225225
}
226226
foreach ($value[0] as $k => $v) {
@@ -310,7 +310,7 @@ private function formatValue($value, string $mode = null): string
310310
throw new Nette\InvalidArgumentException("Unknown placeholder ?$mode.");
311311

312312
} else {
313-
throw new Nette\InvalidArgumentException('Unexpected type of parameter: ' . (is_object($value) ? get_class($value) : gettype($value)));
313+
throw new Nette\InvalidArgumentException('Unexpected type of parameter: ' . (is_object($value) ? $value::class : gettype($value)));
314314
}
315315
}
316316

src/Database/Structure.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ protected function loadStructure(): array
206206

207207
if (isset($structure['hasMany'])) {
208208
foreach ($structure['hasMany'] as &$table) {
209-
uksort($table, function ($a, $b): int {
210-
return strlen($a) <=> strlen($b);
211-
});
209+
uksort($table, fn($a, $b): int => strlen($a) <=> strlen($b));
212210
}
213211
}
214212

@@ -248,19 +246,15 @@ protected function analyzeForeignKeys(array &$structure, string $table): void
248246
$tmp = &$fksColumnsCounts[$foreignKey['name']];
249247
$tmp++;
250248
}
251-
usort($foreignKeys, function ($a, $b) use ($fksColumnsCounts): int {
252-
return $fksColumnsCounts[$b['name']] <=> $fksColumnsCounts[$a['name']];
253-
});
249+
usort($foreignKeys, fn($a, $b): int => $fksColumnsCounts[$b['name']] <=> $fksColumnsCounts[$a['name']]);
254250

255251
foreach ($foreignKeys as $row) {
256252
$structure['belongsTo'][$lowerTable][$row['local']] = $row['table'];
257253
$structure['hasMany'][strtolower($row['table'])][$table][] = $row['local'];
258254
}
259255

260256
if (isset($structure['belongsTo'][$lowerTable])) {
261-
uksort($structure['belongsTo'][$lowerTable], function ($a, $b): int {
262-
return strlen($a) <=> strlen($b);
263-
});
257+
uksort($structure['belongsTo'][$lowerTable], fn($a, $b): int => strlen($a) <=> strlen($b));
264258
}
265259
}
266260

src/Database/Table/GroupedSelection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
string $tableName,
4343
string $column,
4444
Selection $refTable,
45-
Nette\Caching\IStorage $cacheStorage = null
45+
Nette\Caching\IStorage $cacheStorage = null,
4646
) {
4747
$this->refTable = $refTable;
4848
$this->column = $column;

src/Database/Table/Selection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct(
9090
Explorer $explorer,
9191
Conventions $conventions,
9292
string $tableName,
93-
Nette\Caching\IStorage $cacheStorage = null
93+
Nette\Caching\IStorage $cacheStorage = null,
9494
) {
9595
$this->explorer = $this->context = $explorer;
9696
$this->conventions = $conventions;
@@ -890,7 +890,7 @@ public function update(iterable $data): int
890890

891891
return $this->explorer->queryArgs(
892892
$this->sqlBuilder->buildUpdateQuery(),
893-
array_merge([$data], $this->sqlBuilder->getParameters())
893+
array_merge([$data], $this->sqlBuilder->getParameters()),
894894
)->getRowCount();
895895
}
896896

src/Database/Table/SqlBuilder.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ public function buildSelectQuery(array $columns = null): string
184184
{
185185
if (!$this->order && ($this->limit !== null || $this->offset)) {
186186
$this->order = array_map(
187-
function ($col) { return "$this->tableName.$col"; },
188-
(array) $this->conventions->getPrimary($this->tableName)
187+
fn($col) => "$this->tableName.$col",
188+
(array) $this->conventions->getPrimary($this->tableName),
189189
);
190190
}
191191

@@ -239,7 +239,7 @@ public function getParameters(): array
239239
$this->parameters['where'],
240240
$this->parameters['group'],
241241
$this->parameters['having'],
242-
$this->parameters['order']
242+
$this->parameters['order'],
243243
);
244244
}
245245

@@ -562,7 +562,7 @@ protected function parseJoinConditions(&$joins, $joinConditions): array
562562
protected function getSortedJoins(string $table, &$leftJoinDependency, &$tableJoins, &$finalJoins): void
563563
{
564564
if (isset($this->expandingJoins[$table])) {
565-
$path = implode("' => '", array_map(function (string $value): string { return $this->reservedTableNames[$value]; }, array_merge(array_keys($this->expandingJoins), [$table])));
565+
$path = implode("' => '", array_map(fn(string $value): string => $this->reservedTableNames[$value], array_merge(array_keys($this->expandingJoins), [$table])));
566566
throw new Nette\InvalidArgumentException("Circular reference detected at left join conditions (tables '$path').");
567567
}
568568
if (isset($tableJoins[$table])) {
@@ -773,19 +773,17 @@ protected function buildQueryEnd(): string
773773

774774
protected function tryDelimite(string $s): string
775775
{
776-
return preg_replace_callback('#(?<=[^\w`"\[?:]|^)[a-z_][a-z0-9_]*(?=[^\w`"(\]]|$)#Di', function (array $m): string {
777-
return strtoupper($m[0]) === $m[0]
776+
return preg_replace_callback('#(?<=[^\w`"\[?:]|^)[a-z_][a-z0-9_]*(?=[^\w`"(\]]|$)#Di', fn(array $m): string => strtoupper($m[0]) === $m[0]
778777
? $m[0]
779-
: $this->driver->delimite($m[0]);
780-
}, $s);
778+
: $this->driver->delimite($m[0]), $s);
781779
}
782780

783781

784782
protected function addConditionComposition(
785783
array $columns,
786784
array $parameters,
787785
array &$conditions,
788-
array &$conditionsParameters
786+
array &$conditionsParameters,
789787
): bool {
790788
if ($this->driver->isSupported(Driver::SUPPORT_MULTI_COLUMN_AS_OR_COND)) {
791789
$conditionFragment = '(' . implode(' = ? AND ', $columns) . ' = ?) OR ';
@@ -817,9 +815,7 @@ private function getConditionHash($condition, array $parameters): string
817815
private function getCachedTableList(): array
818816
{
819817
if (!$this->cacheTableList) {
820-
$this->cacheTableList = array_flip(array_map(function (array $pair): string {
821-
return $pair['fullName'] ?? $pair['name'];
822-
}, $this->structure->getTables()));
818+
$this->cacheTableList = array_flip(array_map(fn(array $pair): string => $pair['fullName'] ?? $pair['name'], $this->structure->getTables()));
823819
}
824820

825821
return $this->cacheTableList;

tests/Database/Explorer/Explorer.backjoin.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ test('', function () use ($explorer, $driver) {
4242
if ($driver->isSupported(Driver::SUPPORT_SCHEMA)) {
4343
Assert::same(
4444
reformat('SELECT [author].* FROM [author] LEFT JOIN [public].[book] [book] ON [author].[id] = [book].[author_id] WHERE ([book].[translator_id] IS NOT NULL) AND ([author].[id] = ?)'),
45-
$authorsSelection->getSql()
45+
$authorsSelection->getSql(),
4646
);
4747
} else {
4848
Assert::same(
4949
reformat('SELECT [author].* FROM [author] LEFT JOIN [book] ON [author].[id] = [book].[author_id] WHERE ([book].[translator_id] IS NOT NULL) AND ([author].[id] = ?)'),
50-
$authorsSelection->getSql()
50+
$authorsSelection->getSql(),
5151
);
5252
}
5353

tests/Database/Explorer/Explorer.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ test('', function () use ($connection, $structure) {
7878
$explorer = new Nette\Database\Explorer(
7979
$connection,
8080
$structure,
81-
new Nette\Database\Conventions\DiscoveredConventions($structure)
81+
new Nette\Database\Conventions\DiscoveredConventions($structure),
8282
);
8383

8484
$book = $explorer->table('book')->get(1);

0 commit comments

Comments
 (0)