Passed
Push — fix-9163 ( 4cfde3...07a516 )
by Ingo
17:14
created

DataListQueryCounter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ORM\Tests\DataObjectTest;
4
5
use SilverStripe\ORM\DataQuery;
6
7
/**
8
 * This is designed around the chunk method so we can count the number of queries run.
9
 */
10
class DataListQueryCounter extends DataQuery
11
{
12
    private $queryCount = 0;
13
    
14
    /**
15
     * When the DataList gets clone our reference to parent will be attached to our cloned DataListQueryCounter. So all
16
     * DataListQueryCounter::parent will point back to the original one that go created by with the constructor.
17
     * @var DataListQueryCounter
18
     */
19
    private $parent;
20
21
    public function __construct($dataClass)
22
    {
23
        parent::__construct($dataClass);
24
        $this->parent = $this;
25
    }
26
27
    public function getFinalisedQuery($queriedColumns = null)
28
    {
29
        $this->increment();
30
        return parent::getFinalisedQuery($queriedColumns);
31
    }
32
33
    private function increment()
34
    {
35
        $this->parent->queryCount++;
36
    }
37
38
    public function getCount()
39
    {
40
        return $this->parent->queryCount;
41
    }
42
}
43