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

ActiveDataProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareTotalCount() 0 3 2
A enableCount() 0 3 1
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