Passed
Pull Request — master (#29)
by Klochok
13:48
created

ActiveDataProvider::enableCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart;
12
13
class ActiveDataProvider extends \yii\data\ActiveDataProvider
14
{
15
    /**
16
     * @var ActiveQuery the query that is used to fetch data models and [[totalCount]]
17
     * if it is not explicitly set
18
     */
19
    public $query;
20
21
    public bool $useRealCount = false;
22
23
    public function enableCount(): void
24
    {
25
        $this->useRealCount = true;
26
    }
27
28
    protected function prepareTotalCount()
29
    {
30
        return $this->useRealCount ? parent::prepareTotalCount() : $this->getPagination()->pageSize + 1;
31
    }
32
}
33