Skip to content

Commit d523f52

Browse files
committed
Amend previous with running code
Added phpstan to the list of things I need to run before a push.
1 parent ac4c9fd commit d523f52

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

src/Driver/IBMDB2/Statement.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\DBAL\Driver\Statement as StatementInterface;
1111
use Doctrine\DBAL\ParameterType;
1212
use Doctrine\Deprecations\Deprecation;
13+
use Throwable;
1314

1415
use function assert;
1516
use function db2_bind_param;
@@ -30,7 +31,7 @@
3031
use const DB2_LONG;
3132
use const DB2_PARAM_FILE;
3233
use const DB2_PARAM_IN;
33-
use const SEEK_CUR;
34+
use const SEEK_SET;
3435

3536
final class Statement implements StatementInterface
3637
{
@@ -214,25 +215,23 @@ private function createTemporaryFile()
214215
*/
215216
private function copyStreamToStream($source, $target): void
216217
{
217-
$resettable = false;
218+
$resetTo = false;
218219
try {
219-
if (stream_get_meta_data($resource)['seekable']) {
220-
$resettable = true;
221-
$position = ftell($resource);
220+
if (stream_get_meta_data($source)['seekable']) {
221+
$resetTo = ftell($source);
222222
}
223223
} catch (Throwable $e) {
224224
// Swallow
225225
}
226226

227-
$bytesCopied = @stream_copy_to_stream($source, $target);
228-
if ($bytesCopied === false) {
227+
if (@stream_copy_to_stream($source, $target) === false) {
229228
throw CannotCopyStreamToStream::new(error_get_last());
230229
}
231230

232-
if (! $resettable) {
231+
if ($resetTo === false) {
233232
return;
234233
}
235234

236-
fseek($source, -$bytesCopied, SEEK_CUR);
235+
fseek($source, $resetTo, SEEK_SET);
237236
}
238237
}

src/Driver/Mysqli/Statement.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Doctrine\Deprecations\Deprecation;
1414
use mysqli_sql_exception;
1515
use mysqli_stmt;
16+
use Throwable;
1617

1718
use function array_fill;
1819
use function assert;
@@ -215,7 +216,7 @@ private function bindTypedParameters(): void
215216
private function sendLongData(array $streams): void
216217
{
217218
foreach ($streams as $paramNr => $stream) {
218-
$resetTo = -1;
219+
$resetTo = false;
219220
try {
220221
if (stream_get_meta_data($stream)['seekable']) {
221222
$resetTo = ftell($stream);
@@ -237,7 +238,7 @@ private function sendLongData(array $streams): void
237238
}
238239
}
239240
} finally {
240-
if ($resetTo !== -1) {
241+
if ($resetTo !== false) {
241242
fseek($stream, $resetTo, SEEK_SET);
242243
}
243244
}

src/Driver/PDO/Statement.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -169,40 +169,34 @@ private function trackParamResource($resource): void
169169
* restored to after the statement is executed. Call immediately
170170
* before execute (not during bindValue) to get the most accurate offset.
171171
*
172-
* @returns int[]|null Return offsets to restore if needed.
172+
* @return int[]|null Return offsets to restore if needed.
173173
*/
174174
private function getResourceOffsets()
175175
{
176176
$resources = &$this->paramResources;
177177
if ($resources === null) {
178-
return;
178+
return null;
179179
}
180180

181181
$count = count($resources);
182182
$resourceOffsets = null;
183183
$deref = [];
184184
for ($i = 0; $i < $count; ++$i) {
185185
$resource = $resources[$i];
186-
$position = -1;
186+
$position = false;
187187
try {
188188
if (stream_get_meta_data($resource)['seekable']) {
189189
$position = ftell($resource);
190190
}
191191
} catch (Throwable $e) {
192192
// Swallow
193193
} finally {
194-
if ($position === -1) {
194+
if ($position === false) {
195195
if ($resourceOffsets !== null) {
196-
$resourceOffsets[] = $position;
196+
$resourceOffsets[] = -1;
197197
}
198198
} else {
199-
if ($resourceOffsets === null) {
200-
$resourceOffsets = [];
201-
if ($i !== 0) {
202-
array_fill(0, $i, -1);
203-
}
204-
}
205-
199+
$resourceOffsets ??= $i !== 0 ? array_fill(0, $i, -1) : [];
206200
$resourceOffsets[] = $position;
207201
}
208202
}

src/Driver/PgSQL/Statement.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\ParameterType;
88
use Doctrine\Deprecations\Deprecation;
99
use PgSql\Connection as PgSqlConnection;
10+
use Throwable;
1011
use TypeError;
1112

1213
use function assert;
@@ -158,7 +159,7 @@ public function execute($params = null): Result
158159
case ParameterType::LARGE_OBJECT:
159160
$isResource = $value !== null && is_resource($value);
160161
$resource = $value;
161-
$resetTo = -1;
162+
$resetTo = false;
162163
if ($isResource) {
163164
try {
164165
if (stream_get_meta_data($resource)['seekable']) {
@@ -174,7 +175,7 @@ public function execute($params = null): Result
174175
$isResource ? stream_get_contents($value) : $value,
175176
);
176177

177-
if ($resetTo !== -1) {
178+
if ($resetTo !== false) {
178179
fseek($resource, $resetTo, SEEK_SET);
179180
}
180181

0 commit comments

Comments
 (0)