DoctrineProcessingService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A afterOperations() 0 4 1
A beforeOperations() 0 4 1
A count() 0 9 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