Skip to content

Commit cd75f89

Browse files
committed
coding style
1 parent 4efff65 commit cd75f89

27 files changed

+220
-139
lines changed

src/Bridges/DatabaseTracy/ConnectionPanel.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public function logQuery(Connection $connection, $result): void
6161
$this->count++;
6262

6363
$source = null;
64-
$trace = $result instanceof \PDOException ? $result->getTrace() : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
64+
$trace = $result instanceof \PDOException
65+
? $result->getTrace()
66+
: debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
6567
foreach ($trace as $row) {
6668
if (
6769
(isset($row['file']) && is_file($row['file']) && !Tracy\Debugger::getBluescreen()->isCollapsed($row['file']))
@@ -123,10 +125,14 @@ public function getPanel(): ?string
123125
foreach ($this->queries as $query) {
124126
[$connection, $sql, $params, , , , $error] = $query;
125127
$explain = null;
126-
$command = preg_match('#\s*\(?\s*(SELECT|INSERT|UPDATE|DELETE)\s#iA', $sql, $m) ? strtolower($m[1]) : null;
128+
$command = preg_match('#\s*\(?\s*(SELECT|INSERT|UPDATE|DELETE)\s#iA', $sql, $m)
129+
? strtolower($m[1])
130+
: null;
127131
if (!$error && $this->explain && $command === 'select') {
128132
try {
129-
$cmd = is_string($this->explain) ? $this->explain : 'EXPLAIN';
133+
$cmd = is_string($this->explain)
134+
? $this->explain
135+
: 'EXPLAIN';
130136
$explain = (new Nette\Database\ResultSet($connection, "$cmd $sql", $params))->fetchAll();
131137
} catch (\PDOException $e) {
132138
}

src/Database/Context.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ class Context
3333
private $cacheStorage;
3434

3535

36-
public function __construct(Connection $connection, IStructure $structure, IConventions $conventions = null, Nette\Caching\IStorage $cacheStorage = null)
37-
{
36+
public function __construct(
37+
Connection $connection,
38+
IStructure $structure,
39+
IConventions $conventions = null,
40+
Nette\Caching\IStorage $cacheStorage = null
41+
) {
3842
$this->connection = $connection;
3943
$this->structure = $structure;
4044
$this->conventions = $conventions ?: new StaticConventions;

src/Database/Conventions/StaticConventions.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public function getBelongsToReference(string $table, string $key): ?array
7272

7373
protected function getColumnFromTable(string $name): string
7474
{
75-
if ($this->table !== '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '$)D', $name, $match)) {
75+
if (
76+
$this->table !== '%s'
77+
&& preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '$)D', $name, $match)
78+
) {
7679
return $match[1];
7780
}
7881

src/Database/Drivers/MySqlDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
105105

106106
} elseif ($limit !== null || $offset) {
107107
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
108-
$sql .= ' LIMIT ' . ($limit === null ? '18446744073709551615' : $limit)
108+
$sql .= ' LIMIT ' . ($limit ?? '18446744073709551615')
109109
. ($offset ? ' OFFSET ' . $offset : '');
110110
}
111111
}

src/Database/Drivers/SqliteDriver.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
9999
throw new Nette\InvalidArgumentException('Negative offset or limit.');
100100

101101
} elseif ($limit !== null || $offset) {
102-
$sql .= ' LIMIT ' . ($limit === null ? '-1' : $limit)
102+
$sql .= ' LIMIT ' . ($limit ?? '-1')
103103
. ($offset ? ' OFFSET ' . $offset : '');
104104
}
105105
}
@@ -138,7 +138,7 @@ public function getColumns(string $table): array
138138
$columns = [];
139139
foreach ($this->connection->query("PRAGMA table_info({$this->delimite($table)})") as $row) {
140140
$column = $row['name'];
141-
$pattern = "/(\"$column\"|`$column`|\[$column\]|$column)\\s+[^,]+\\s+PRIMARY\\s+KEY\\s+AUTOINCREMENT/Ui";
141+
$pattern = "/(\"$column\"|`$column`|\\[$column\\]|$column)\\s+[^,]+\\s+PRIMARY\\s+KEY\\s+AUTOINCREMENT/Ui";
142142
$type = explode('(', $row['type']);
143143
$columns[] = [
144144
'name' => $column,
@@ -224,11 +224,9 @@ public function getColumnTypes(\PDOStatement $statement): array
224224
for ($col = 0; $col < $count; $col++) {
225225
$meta = $statement->getColumnMeta($col);
226226
if (isset($meta['sqlite:decl_type'])) {
227-
if (in_array($meta['sqlite:decl_type'], ['DATE', 'DATETIME'], true)) {
228-
$types[$meta['name']] = Nette\Database\IStructure::FIELD_UNIX_TIMESTAMP;
229-
} else {
230-
$types[$meta['name']] = Nette\Database\Helpers::detectType($meta['sqlite:decl_type']);
231-
}
227+
$types[$meta['name']] = in_array($meta['sqlite:decl_type'], ['DATE', 'DATETIME'], true)
228+
? Nette\Database\IStructure::FIELD_UNIX_TIMESTAMP
229+
: Nette\Database\Helpers::detectType($meta['sqlite:decl_type']);
232230
} elseif (isset($meta['native_type'])) {
233231
$types[$meta['name']] = Nette\Database\Helpers::detectType($meta['native_type']);
234232
}

src/Database/Drivers/SqlsrvDriver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ public function getColumnTypes(\PDOStatement $statement): array
227227
$count = $statement->columnCount();
228228
for ($col = 0; $col < $count; $col++) {
229229
$meta = $statement->getColumnMeta($col);
230-
if (isset($meta['sqlsrv:decl_type']) && $meta['sqlsrv:decl_type'] !== 'timestamp') { // timestamp does not mean time in sqlsrv
230+
if (
231+
isset($meta['sqlsrv:decl_type'])
232+
&& $meta['sqlsrv:decl_type'] !== 'timestamp'
233+
) { // timestamp does not mean time in sqlsrv
231234
$types[$meta['name']] = Nette\Database\Helpers::detectType($meta['sqlsrv:decl_type']);
232235
} elseif (isset($meta['native_type'])) {
233236
$types[$meta['name']] = Nette\Database\Helpers::detectType($meta['native_type']);

src/Database/Helpers.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ public static function dumpSql(string $sql, array $params = null, Connection $co
120120
return '?';
121121
}
122122
$param = $params[$i++];
123-
if (is_string($param) && (preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $param) || preg_last_error())) {
123+
if (
124+
is_string($param)
125+
&& (
126+
preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $param)
127+
|| preg_last_error()
128+
)
129+
) {
124130
return '<i title="Length ' . strlen($param) . ' bytes">&lt;binary&gt;</i>';
125131

126132
} elseif (is_string($param)) {
@@ -234,8 +240,11 @@ public static function loadFromFile(Connection $connection, string $file, callab
234240
}
235241

236242

237-
public static function createDebugPanel($connection, bool $explain = true, string $name = null): Nette\Bridges\DatabaseTracy\ConnectionPanel
238-
{
243+
public static function createDebugPanel(
244+
$connection,
245+
bool $explain = true,
246+
string $name = null
247+
): Nette\Bridges\DatabaseTracy\ConnectionPanel {
239248
$panel = new Nette\Bridges\DatabaseTracy\ConnectionPanel($connection);
240249
$panel->explain = $explain;
241250
$panel->name = $name;

src/Database/ResultSet.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ public function normalizeRow(array $row): array
150150
} elseif ($type === IStructure::FIELD_BOOL) {
151151
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
152152

153-
} elseif ($type === IStructure::FIELD_DATETIME || $type === IStructure::FIELD_DATE || $type === IStructure::FIELD_TIME) {
153+
} elseif (
154+
$type === IStructure::FIELD_DATETIME
155+
|| $type === IStructure::FIELD_DATE
156+
|| $type === IStructure::FIELD_TIME
157+
) {
154158
$row[$key] = new Nette\Utils\DateTime($value);
155159

156160
} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
@@ -186,7 +190,7 @@ public function dump(): void
186190
public function rewind(): void
187191
{
188192
if ($this->result === false) {
189-
throw new Nette\InvalidStateException(__CLASS__ . ' implements only one way iterator.');
193+
throw new Nette\InvalidStateException(self::class . ' implements only one way iterator.');
190194
}
191195
}
192196

@@ -222,9 +226,6 @@ public function valid(): bool
222226
/********************* interface IRowContainer ****************d*g**/
223227

224228

225-
/**
226-
* @inheritDoc
227-
*/
228229
public function fetch(): ?IRow
229230
{
230231
$data = $this->pdoStatement ? $this->pdoStatement->fetch() : null;

src/Database/SqlPreprocessor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class SqlPreprocessor
1919
{
2020
use Nette\SmartObject;
2121

22-
/** @var array */
2322
private const MODE_LIST = ['and', 'or', 'set', 'values', 'order'];
2423

2524
private const ARRAY_MODES = [
@@ -222,7 +221,9 @@ private function formatValue($value, string $mode = null): string
222221
} elseif (!$mode || $mode === 'set') {
223222
foreach ($value as $k => $v) {
224223
if (is_int($k)) { // value, value, ... OR (1, 2), (3, 4)
225-
$vx[] = is_array($v) ? '(' . $this->formatValue($v) . ')' : $this->formatValue($v);
224+
$vx[] = is_array($v)
225+
? '(' . $this->formatValue($v) . ')'
226+
: $this->formatValue($v);
226227
} elseif (substr($k, -1) === '=') { // key+=value, key-=value, ...
227228
$k2 = $this->delimite(substr($k, 0, -2));
228229
$vx[] = $k2 . '=' . $k2 . ' ' . substr($k, -2, 1) . ' ' . $this->formatValue($v);
@@ -255,7 +256,9 @@ private function formatValue($value, string $mode = null): string
255256
$vx[] = $k . ' ' . $operator . ' ' . $v;
256257
}
257258
}
258-
return $value ? '(' . implode(') ' . strtoupper($mode) . ' (', $vx) . ')' : '1=1';
259+
return $value
260+
? '(' . implode(') ' . strtoupper($mode) . ' (', $vx) . ')'
261+
: '1=1';
259262

260263
} elseif ($mode === 'order') { // key, key DESC, ...
261264
foreach ($value as $k => $v) {

src/Database/Table/GroupedSelection.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ class GroupedSelection extends Selection
3636
/**
3737
* Creates filtered and grouped table representation.
3838
*/
39-
public function __construct(Context $context, IConventions $conventions, string $tableName, string $column, Selection $refTable, Nette\Caching\IStorage $cacheStorage = null)
40-
{
39+
public function __construct(
40+
Context $context,
41+
IConventions $conventions,
42+
string $tableName,
43+
string $column,
44+
Selection $refTable,
45+
Nette\Caching\IStorage $cacheStorage = null
46+
) {
4147
$this->refTable = $refTable;
4248
$this->column = $column;
4349
parent::__construct($context, $conventions, $tableName, $cacheStorage);
@@ -154,7 +160,12 @@ protected function execute(): void
154160
foreach ((array) $this->rows as $key => $row) {
155161
$ref = &$data[$row[$this->column]];
156162
$skip = &$offset[$row[$this->column]];
157-
if ($limit === null || $rows <= 1 || (count($ref ?? []) < $limit && $skip >= $this->sqlBuilder->getOffset())) {
163+
if (
164+
$limit === null
165+
|| $rows <= 1
166+
|| (count($ref ?? []) < $limit
167+
&& $skip >= $this->sqlBuilder->getOffset())
168+
) {
158169
$ref[$key] = $row;
159170
} else {
160171
unset($this->rows[$key]);

0 commit comments

Comments
 (0)