DbalPaginatorCapabilities::getCountFrom()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
declare(strict_types=1);
3
4
namespace ReadModel\Bridge\Doctrine;
5
6
trait DbalPaginatorCapabilities
7
{
8
    protected function findAll(): array
9
    {
10
        if (null !== $this->limit) {
11
            $this->qb->setMaxResults($this->limit);
12
        }
13
        $this->qb->setFirstResult($this->offset);
14
15
        return $this->qb->execute()->fetchAll();
16
    }
17
18
    protected function getTotal(): int
19
    {
20
        $qb = clone $this->qb;
21
        $countFrom = $this->getCountFrom();
22
23
        $qb->select("COUNT($countFrom)")
24
           ->setMaxResults(null)
25
           ->setFirstResult(null)
26
           ->resetQueryPart('orderBy');
27
28
        return (int) $qb->execute()->fetchColumn();
29
    }
30
31
    protected function getCountFrom(): string
32
    {
33
        $select = $this->qb->getQueryPart('select');
34
35
        if (!is_array($select)) {
36
            return '*';
37
        }
38
39
        $select = explode(',', array_shift($select));
40
41
        return array_shift($select);
42
    }
43
}
44