Skip to content

Commit dca8b55

Browse files
committed
Made some php 8.0 specific changes
1 parent 720d80a commit dca8b55

File tree

12 files changed

+47
-68
lines changed

12 files changed

+47
-68
lines changed

src/Builder/Expr/DBExprFilter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public function __construct(string $expression, array $data, $keyPath, $validato
3131
$this->value = RecursiveStructureAccess::recursiveGet($data, $this->keyPath, null);
3232
$this->hasValue = is_scalar($this->value) ? trim((string) $this->value) !== '' : !empty($this->value);
3333
if($validator === null) {
34-
$validator = function() {
35-
return true;
36-
};
34+
$validator = static fn() => true;
3735
}
3836
$this->validator = $validator;
3937
if($validationResultHandler === null) {

src/Builder/Internal/ConditionBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ private static function formatKey(string $key): string {
5959
return $key;
6060
}
6161
$keyParts = explode('.', $key);
62-
$fn = static function (string $part) {
63-
return "`{$part}`";
64-
};
62+
$fn = static fn(string $part) => "`{$part}`";
6563
$enclosedKeyParts = array_map($fn, $keyParts);
6664
return implode('.', $enclosedKeyParts);
6765
}

src/Builder/QueryStatement.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,37 +101,29 @@ public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null,
101101
* @return mixed
102102
*/
103103
public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) {
104-
return $this->exceptionHandler(function() use ($fetchStyle, $cursorOrientation, $cursorOffset) {
105-
return $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset);
106-
});
104+
return $this->exceptionHandler(fn() => $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset));
107105
}
108106

109107
/**
110108
* @param int $columnNo
111109
* @return mixed
112110
*/
113111
public function fetchColumn($columnNo = 0) {
114-
return $this->exceptionHandler(function() use ($columnNo) {
115-
return $this->statement->fetchColumn($columnNo);
116-
});
112+
return $this->exceptionHandler(fn() => $this->statement->fetchColumn($columnNo));
117113
}
118114

119115
/**
120116
* @return bool
121117
*/
122118
public function closeCursor(): bool {
123-
return $this->exceptionHandler(function() {
124-
return $this->statement->closeCursor();
125-
});
119+
return $this->exceptionHandler(fn() => $this->statement->closeCursor());
126120
}
127121

128122
/**
129123
* @return int
130124
*/
131125
public function columnCount(): int {
132-
return $this->exceptionHandler(function() {
133-
return $this->statement->columnCount();
134-
});
126+
return $this->exceptionHandler(fn() => $this->statement->columnCount());
135127
}
136128

137129
/**

src/Builder/RunnableDelete.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ public function run(array $params = []) {
2626
public function prepare(): DDLRunnable {
2727
return $this->createPreparable(
2828
$this->db()->prepare($this),
29-
/**
30-
* @param scalar $v
31-
* @return int
32-
*/
33-
function ($v) {
34-
return (int) $v;
35-
}
29+
fn($v) => (int) $v
3630
);
3731
}
3832
}

src/Builder/RunnableInsert.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ public function run(array $params = []): int {
4242
* @return DDLRunnable<int>
4343
*/
4444
public function prepare(): DDLRunnable {
45-
return $this->createPreparable($this->db()->prepare($this), function() {
46-
return (int) $this->db()->getLastInsertId();
47-
});
45+
return $this->createPreparable(
46+
$this->db()->prepare($this),
47+
fn() => (int) $this->db()->getLastInsertId()
48+
);
4849
}
4950
}

src/Builder/RunnableUpdate.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ public function run(array $params = []): int {
2626
public function prepare(): DDLRunnable {
2727
return $this->createPreparable(
2828
$this->db()->prepare($this),
29-
/**
30-
* @param bool|int|float|string $v
31-
* @return int
32-
*/
33-
function ($v) {
34-
return (int) $v;
35-
}
29+
fn($v) => (int) $v
3630
);
3731
}
3832
}

src/Builder/Traits/HavingBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait HavingBuilder {
2020
* @return $this
2121
*/
2222
public function having($expression, ...$args) {
23-
$fn = function ($expression, $args) { $this->having[] = [$expression, $args]; };
23+
$fn = fn($expression, $args) => $this->having[] = [$expression, $args];
2424
ConditionAddHelper::addCondition($fn, $expression, $args);
2525
return $this;
2626
}

src/Builder/Traits/TableNameBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function buildTableName(?string $alias, $name): string {
1717
if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) {
1818
$name = (string) $name;
1919
$lines = explode("\n", $name);
20-
$lines = array_map(static function (string $line) { return "\t{$line}"; }, $lines);
20+
$lines = array_map(static fn(string $line) => "\t{$line}", $lines);
2121
$name = implode("\n", $lines);
2222
$name = '(' . trim(rtrim(trim($name), ';')) . ')';
2323
}

src/Builder/Traits/WhereBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait WhereBuilder {
2020
* @return $this
2121
*/
2222
public function where($expression, ...$args) {
23-
$fn = function ($expression, $args) { $this->where[] = [$expression, $args]; };
23+
$fn = fn($expression, $args) => $this->where[] = [$expression, $args];
2424
ConditionAddHelper::addCondition($fn, $expression, $args);
2525
return $this;
2626
}

src/Databases/MySQL.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public function query(
104104
#[Language('MySQL')]
105105
string $query
106106
) {
107-
return $this->getQueryLoggers()->logRegion($query, function() use ($query) {
108-
return $this->buildQueryStatement($query, function ($query) {
109-
return $this->pdo->query($query);
110-
});
111-
});
107+
return $this->getQueryLoggers()->logRegion($query, fn() =>
108+
$this->buildQueryStatement($query, fn($query) =>
109+
$this->pdo->query($query)
110+
)
111+
);
112112
}
113113

114114
/**
@@ -119,9 +119,9 @@ public function prepare(
119119
#[Language('MySQL')]
120120
string $query
121121
) {
122-
return $this->buildQueryStatement((string) $query, function ($query) {
123-
return $this->pdo->prepare($query);
124-
});
122+
return $this->buildQueryStatement((string) $query, fn($query) =>
123+
$this->pdo->prepare($query)
124+
);
125125
}
126126

127127
/**
@@ -134,17 +134,17 @@ public function exec(
134134
string $query,
135135
array $params = []
136136
): int {
137-
return $this->getQueryLoggers()->logRegion($query, function() use ($query, $params) {
138-
return $this->exceptionHandler(function () use ($query, $params) {
137+
return $this->getQueryLoggers()->logRegion($query, fn() =>
138+
$this->exceptionHandler(function () use ($query, $params) {
139139
$stmt = $this->pdo->prepare($query);
140140
$timer = microtime(true);
141141
$stmt->execute($params);
142142
$this->queryLoggers->log($query, microtime(true) - $timer);
143143
$result = $stmt->rowCount();
144144
$stmt->closeCursor();
145145
return $result;
146-
});
147-
});
146+
})
147+
);
148148
}
149149

150150
/**
@@ -165,23 +165,23 @@ public function getTableFields(string $table): array {
165165
return $this->tableFields[$fqTable];
166166
}
167167
$query = "DESCRIBE {$fqTable}";
168-
return $this->getQueryLoggers()->logRegion($query, function() use ($query, $fqTable) {
169-
return $this->exceptionHandler(function () use ($query, $fqTable) {
168+
return $this->getQueryLoggers()->logRegion($query, fn() =>
169+
$this->exceptionHandler(function () use ($query, $fqTable) {
170170
$stmt = $this->pdo->query($query);
171171
try {
172172
if($stmt === false) {
173173
throw new RuntimeException('Invalid return type');
174174
}
175175
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
176-
$this->tableFields[$fqTable] = array_map(static function ($row) { return $row['Field']; }, $rows ?: []);
176+
$this->tableFields[$fqTable] = array_map(static fn($row) => $row['Field'], $rows ?: []);
177177
return $this->tableFields[$fqTable];
178178
} finally {
179179
try {
180180
$stmt->closeCursor();
181181
} catch (Throwable $e) {}
182182
}
183-
});
184-
});
183+
})
184+
);
185185
}
186186

187187
/**

0 commit comments

Comments
 (0)