Passed
Push — dev ( 332d94...aa1494 )
by Def
03:03
created

BatchQueryResult   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

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

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
use Yiisoft\Db\Exception\InvalidCallException;
9
use Yiisoft\Db\Query\BatchQueryResult as BaseBatchQueryResult;
10
11
class BatchQueryResult extends BaseBatchQueryResult
12
{
13
    /**
14
     * @var int MSSQL error code for exception that is thrown when last batch is size less than specified batch size
15
     *
16
     * {@see https://github.com/yiisoft/yii2/issues/10023}
17
     */
18
    private int $mssqlNoMoreRowsErrorCode = -13;
19
20
    /**
21
     * Reads and collects rows for batch.
22
     *
23
     * @throws InvalidCallException
24
     *
25
     * @return array
26
     *
27
     * @psalm-suppress MixedArrayAccess
28
     */
29 3
    protected function getRows(): array
30
    {
31 3
        $rows = [];
32 3
        $count = 0;
33
34
        try {
35
            do {
36 3
                $this->dataReader?->next();
37
                /** @psalm-var array|bool $row */
38 3
                $row = $this->dataReader?->current();
39 3
            } while ($row && ($rows[] = $row) && ++$count < $this->batchSize);
40 3
        } catch (PDOException $e) {
41 3
            if (($e->errorInfo[1] ?? null) !== $this->mssqlNoMoreRowsErrorCode) {
42
                throw $e;
43
            }
44
        }
45
46 3
        return $rows;
47
    }
48
}
49