Passed
Push — master ( 668d8d...3cb462 )
by Tomasz
03:34
created

DbalPaginatorCapabilities::getCountFrom()   A

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
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
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
        $this->qb
0 ignored issues
show
Bug Best Practice introduced by
The property qb does not exist on ReadModel\Bridge\Doctrin...alPaginatorCapabilities. Did you maybe forget to declare it?
Loading history...
11
             ->setMaxResults($this->limit)
0 ignored issues
show
Bug Best Practice introduced by
The property limit does not exist on ReadModel\Bridge\Doctrin...alPaginatorCapabilities. Did you maybe forget to declare it?
Loading history...
12
             ->setFirstResult($this->offset);
0 ignored issues
show
Bug Best Practice introduced by
The property offset does not exist on ReadModel\Bridge\Doctrin...alPaginatorCapabilities. Did you maybe forget to declare it?
Loading history...
13
14
        return $this->qb->execute()->fetchAll();
15
    }
16
17
    protected function getTotal(): int
18
    {
19
        $qb = clone $this->qb;
0 ignored issues
show
Bug Best Practice introduced by
The property qb does not exist on ReadModel\Bridge\Doctrin...alPaginatorCapabilities. Did you maybe forget to declare it?
Loading history...
20
        $countFrom = $this->getCountFrom();
21
22
        $qb->select("COUNT($countFrom)")
23
           ->setMaxResults(null)
24
           ->setFirstResult(null)
25
           ->resetQueryPart('orderBy');
26
27
        return (int) $qb->execute()->fetchColumn();
28
    }
29
30
    protected function getCountFrom(): string
31
    {
32
        $select = $this->qb->getQueryPart('select');
0 ignored issues
show
Bug Best Practice introduced by
The property qb does not exist on ReadModel\Bridge\Doctrin...alPaginatorCapabilities. Did you maybe forget to declare it?
Loading history...
33
34
        if (!is_array($select)) {
35
            return '*';
36
        }
37
38
        $select = explode(',', array_shift($select));
39
40
        return array_shift($select);
41
    }
42
}
43