DoctrineProcessingService::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ViewComponents\Doctrine;
4
5
use ArrayIterator;
6
use Doctrine\DBAL\Query\QueryBuilder;
7
use PDO;
8
use Traversable;
9
use ViewComponents\ViewComponents\Data\ProcessingService\AbstractProcessingService;
10
11
class DoctrineProcessingService extends AbstractProcessingService
12
{
13
    /**
14
     * @param QueryBuilder $data
15
     * @return Traversable
16
     */
17 13
    protected function afterOperations($data)
18
    {
19 13
        return new ArrayIterator($data->execute()->fetchAll(PDO::FETCH_OBJ));
20
    }
21
22
    /**
23
     * @param QueryBuilder $data
24
     * @return QueryBuilder
25
     */
26 15
    protected function beforeOperations($data)
27
    {
28 15
        return clone $data;
29
    }
30
31
    /**
32
     * Returns count of processed items after applying all operations.
33
     *
34
     * @return int
35
     */
36 2
    public function count()
37
    {
38
        /** @var QueryBuilder $builder */
39 2
        $builder = $this->applyOperations(
40 2
            $this->beforeOperations($this->dataSource)
41 2
        );
42 2
        $builder->select('count(*) as row_count');
43 2
        return $builder->execute()->fetchColumn();
44
    }
45
}
46