Skip to content

Commit 536c13a

Browse files
committed
Fixed logging
1 parent 5b2c92b commit 536c13a

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

composer.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,5 @@
3131
"scripts": {
3232
"phpunit": "phpunit -c tests.xml",
3333
"phpstan": "phpstan analyse -c phpstan.neon"
34-
},
35-
"config": {
36-
"platform": {
37-
"php": "7.1.10"
38-
}
3934
}
4035
}

src/Builder/QueryStatement.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array
6363
* @return $this
6464
*/
6565
public function execute(array $params = []) {
66-
$this->exceptionHandler($this->query, function() use ($params) {
67-
$response = $this->statement->execute($params);
68-
if(!$response) {
69-
throw new SqlException('Execution returned with "false".');
70-
}
66+
$this->exceptionHandler(function() use ($params) {
67+
$this->queryLoggers->logRegion($this->query, function() use ($params) {
68+
$response = $this->statement->execute($params);
69+
if(!$response) {
70+
throw new SqlException('Execution returned with "false".');
71+
}
72+
});
7173
});
7274
return $this;
7375
}
@@ -79,11 +81,13 @@ public function execute(array $params = []) {
7981
* @return array<mixed, mixed>
8082
*/
8183
public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = []): array {
82-
$result = $this->exceptionHandler($this->query, function() use ($fetchStyle, $fetchArgument, $ctorArgs) {
83-
if($fetchArgument !== null) {
84-
return $this->statement->fetchAll($fetchStyle, $fetchArgument, ...$ctorArgs);
85-
}
86-
return $this->statement->fetchAll($fetchStyle);
84+
$result = $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) {
85+
return $this->queryLoggers->logRegion($this->query, function () use ($fetchStyle, $fetchArgument, $ctorArgs) {
86+
if($fetchArgument !== null) {
87+
return $this->statement->fetchAll($fetchStyle, $fetchArgument, ...$ctorArgs);
88+
}
89+
return $this->statement->fetchAll($fetchStyle);
90+
});
8791
});
8892
if(is_bool($result)) {
8993
return [];
@@ -98,8 +102,10 @@ public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null,
98102
* @return mixed
99103
*/
100104
public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) {
101-
return $this->exceptionHandler($this->query, function() use ($fetchStyle, $cursorOrientation, $cursorOffset) {
102-
return $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset);
105+
return $this->exceptionHandler(function() use ($fetchStyle, $cursorOrientation, $cursorOffset) {
106+
return $this->queryLoggers->logRegion($this->query, function () use ($fetchStyle, $cursorOrientation, $cursorOffset) {
107+
return $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset);
108+
});
103109
});
104110
}
105111

@@ -108,16 +114,18 @@ public function fetch($fetchStyle = PDO::FETCH_ASSOC, $cursorOrientation = PDO::
108114
* @return mixed
109115
*/
110116
public function fetchColumn($columnNo = 0) {
111-
return $this->exceptionHandler($this->query, function() use ($columnNo) {
112-
return $this->statement->fetchColumn($columnNo);
117+
return $this->exceptionHandler(function() use ($columnNo) {
118+
return $this->queryLoggers->logRegion($this->query, function () use ($columnNo) {
119+
return $this->statement->fetchColumn($columnNo);
120+
});
113121
});
114122
}
115123

116124
/**
117125
* @return bool
118126
*/
119127
public function closeCursor(): bool {
120-
return $this->exceptionHandler($this->query, function() {
128+
return $this->exceptionHandler(function() {
121129
return $this->statement->closeCursor();
122130
});
123131
}
@@ -126,7 +134,7 @@ public function closeCursor(): bool {
126134
* @return int
127135
*/
128136
public function columnCount(): int {
129-
return $this->exceptionHandler($this->query, function() {
137+
return $this->exceptionHandler(function() {
130138
return $this->statement->columnCount();
131139
});
132140
}
@@ -136,7 +144,7 @@ public function columnCount(): int {
136144
* @return null|array<string, mixed>
137145
*/
138146
public function getColumnMeta(int $columnNo): ?array {
139-
return $this->exceptionHandler($this->query, function() use ($columnNo) {
147+
return $this->exceptionHandler(function() use ($columnNo) {
140148
$columnMeta = $this->statement->getColumnMeta($columnNo);
141149
if($columnMeta === false) {
142150
return null;
@@ -150,13 +158,11 @@ public function getColumnMeta(int $columnNo): ?array {
150158
* @param callable(): T $fn
151159
* @return T
152160
*/
153-
private function exceptionHandler(string $query, callable $fn) {
154-
return $this->queryLoggers->logRegion($query, function () use ($fn) {
155-
try {
156-
return $fn();
157-
} catch (PDOException $exception) {
158-
throw $this->exceptionInterpreter->getMoreConcreteException($exception);
159-
}
160-
});
161+
private function exceptionHandler(callable $fn) {
162+
try {
163+
return $fn();
164+
} catch (PDOException $exception) {
165+
throw $this->exceptionInterpreter->getMoreConcreteException($exception);
166+
}
161167
}
162168
}

src/Builder/Traits/OrderByBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public function orderByValues(string $fieldName, array $values) {
4040
}
4141

4242
/**
43-
* @param string $fieldName
44-
* @param array<int, int|float|string> $values
45-
* @return
43+
* @return array<int, array{string, string}>
4644
*/
4745
public function getOrderBy() {
4846
return $this->orderBy;

0 commit comments

Comments
 (0)