Skip to content

Commit 19c4acd

Browse files
committed
coding style
1 parent a0133ac commit 19c4acd

26 files changed

Lines changed: 81 additions & 95 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: 1 addition & 1 deletion
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;

src/Database/Helpers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static function createDebugPanel(
246246
bool $explain,
247247
string $name,
248248
Tracy\Bar $bar,
249-
Tracy\BlueScreen $blueScreen
249+
Tracy\BlueScreen $blueScreen,
250250
): Nette\Bridges\DatabaseTracy\ConnectionPanel {
251251
return self::initializeTracy($connection, true, $name, $explain, $bar, $blueScreen);
252252
}
@@ -258,10 +258,10 @@ public static function initializeTracy(
258258
string $name = '',
259259
bool $explain = true,
260260
Tracy\Bar $bar = null,
261-
Tracy\BlueScreen $blueScreen = null
261+
Tracy\BlueScreen $blueScreen = null,
262262
): Nette\Bridges\DatabaseTracy\ConnectionPanel {
263-
$blueScreen = $blueScreen ?? Tracy\Debugger::getBlueScreen();
264-
$bar = $bar ?? Tracy\Debugger::getBar();
263+
$blueScreen ??= Tracy\Debugger::getBlueScreen();
264+
$bar ??= Tracy\Debugger::getBar();
265265

266266
$panel = new Nette\Bridges\DatabaseTracy\ConnectionPanel($connection, $blueScreen);
267267
$panel->explain = $explain;

src/Database/SqlPreprocessor.php

Lines changed: 2 additions & 2 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.');
@@ -219,7 +219,7 @@ private function formatValue($value, string $mode = null): string
219219
if (!is_array($value[0]) && !$value[0] instanceof Row) {
220220
throw new Nette\InvalidArgumentException(
221221
'Automaticaly detected multi-insert, but values aren\'t array. If you need try to change mode like "?['
222-
. implode('|', self::MODES) . ']". Mode "' . $mode . '" was used.'
222+
. implode('|', self::MODES) . ']". Mode "' . $mode . '" was used.',
223223
);
224224
}
225225
foreach ($value[0] as $k => $v) {

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/Helpers.dumpSql.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,35 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName
1717
test('int check', function () use ($connection) {
1818
Assert::same(
1919
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> id = 10 <strong style=\"color:green\">OR</strong> id = 11</pre>\n",
20-
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE id = ? OR id = ?', [10, 11], $connection)
20+
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE id = ? OR id = ?', [10, 11], $connection),
2121
);
2222
});
2323

2424
test('bool check', function () use ($connection) {
2525
Assert::same(
2626
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> deleted = 0</pre>\n",
27-
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE deleted = ?', [false], $connection)
27+
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE deleted = ?', [false], $connection),
2828
);
2929
});
3030

3131
test('string check', function () use ($connection) {
3232
Assert::same(
3333
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> name = <span title=\"Length 15 characters\">'Alexej Chruščev'</span></pre>\n",
34-
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ['Alexej Chruščev'], $connection)
34+
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ['Alexej Chruščev'], $connection),
3535
);
3636
});
3737

3838
test('string check with \'', function () use ($connection) {
3939
Assert::same(
4040
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> name = <span title=\"Length 16 characters\">'Alexej Ch\\'ruščev'</span></pre>\n",
41-
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection)
41+
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection),
4242
);
4343
});
4444

4545
test('string check without connection', function () {
4646
Assert::same(
4747
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> name = <span title=\"Length 16 characters\">'Alexej Ch'ruščev'</span></pre>\n",
48-
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"])
48+
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"]),
4949
);
5050
});
5151

@@ -58,6 +58,6 @@ test('string check with \'', function () use ($connection) {
5858
Nette\Database\Helpers::$maxLength = 10;
5959
Assert::same(
6060
"<pre class=\"dump\"><strong style=\"color:blue\">SELECT</strong> id \n<strong style=\"color:blue\">FROM</strong> author \n<strong style=\"color:blue\">WHERE</strong> name = <span title=\"Length 16 characters\">'Alexej Ch…'</span></pre>\n",
61-
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection)
61+
Nette\Database\Helpers::dumpSql('SELECT id FROM author WHERE name = ?', ["Alexej Ch'ruščev"], $connection),
6262
);
6363
});

tests/Database/Reflection.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName
1717

1818
$driver = $connection->getDriver();
1919
$tables = $driver->getTables();
20-
$tables = array_filter($tables, function ($t) { return in_array($t['name'], ['author', 'book', 'book_tag', 'tag'], true); });
21-
usort($tables, function ($a, $b) { return strcmp($a['name'], $b['name']); });
20+
$tables = array_filter($tables, fn($t) => in_array($t['name'], ['author', 'book', 'book_tag', 'tag'], true));
21+
usort($tables, fn($a, $b) => strcmp($a['name'], $b['name']));
2222

2323
if ($driver->isSupported(Driver::SUPPORT_SCHEMA)) {
2424
Assert::same(
@@ -28,7 +28,7 @@ if ($driver->isSupported(Driver::SUPPORT_SCHEMA)) {
2828
['name' => 'book_tag', 'view' => false, 'fullName' => 'public.book_tag'],
2929
['name' => 'tag', 'view' => false, 'fullName' => 'public.tag'],
3030
],
31-
$tables
31+
$tables,
3232
);
3333
} else {
3434
Assert::same([

0 commit comments

Comments
 (0)