BatchQueryResult   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 32
ccs 9
cts 10
cp 0.9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRows() 0 18 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use PDOException;
8
9
use function in_array;
10
11
/**
12
 * Represents the result of a batch query execution for MSSQL Server.
13
 */
14
final class BatchQueryResult extends \Yiisoft\Db\Query\BatchQueryResult
15
{
16
    /**
17
     * @var int MSSQL error code for exception that's thrown when the last batch is size less than specified batch size
18
     *
19
     * @link https://github.com/yiisoft/yii2/issues/10023
20
     */
21
    private int $mssqlNoMoreRowsErrorCode = -13;
22
23
    /**
24
     * Reads and collects rows for batch.
25
     *
26
     * @psalm-suppress MixedArrayAccess
27
     */
28 4
    protected function getRows(): array
29
    {
30 4
        $rows = [];
31 4
        $count = 0;
32
33
        try {
34
            do {
35 4
                $this->dataReader?->next();
36
                /** @psalm-var array|bool $row */
37 4
                $row = $this->dataReader?->current();
38 4
            } while ($row && ($rows[] = $row) && ++$count < $this->batchSize);
39 4
        } catch (PDOException $e) {
40 4
            if (!in_array($this->mssqlNoMoreRowsErrorCode, (array) $e->errorInfo, true)) {
41
                throw $e;
42
            }
43
        }
44
45 4
        return $rows;
46
    }
47
}
48