Passed
Pull Request — master (#126)
by Wilmer
10:57 queued 06:28
created

BatchQueryResult   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
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 29
ccs 10
cts 10
cp 1
rs 10
wmc 6

1 Method

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