Passed
Branch master (fa28a2)
by Wilmer
06:39 queued 03:01
created

BatchQueryResult   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 34
ccs 9
cts 9
cp 1
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
     * @psalm-suppress MixedArrayAccess
26
     */
27 3
    protected function getRows(): array
28
    {
29 3
        $rows = [];
30 3
        $count = 0;
31
32
        try {
33
            do {
34 3
                $this->dataReader?->next();
35
                /** @psalm-var array|bool $row */
36 3
                $row = $this->dataReader?->current();
37 3
            } while ($row && ($rows[] = $row) && ++$count < $this->batchSize);
38 3
        } catch (PDOException $e) {
39 3
            if (($e->errorInfo[1] ?? null) !== $this->mssqlNoMoreRowsErrorCode) {
40
                throw $e;
41
            }
42
        }
43
44 3
        return $rows;
45
    }
46
}
47