Passed
Push — master ( a8ac3c...b503e4 )
by Klochok
11:06
created

ActiveDataProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 39
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A enableSynchronousCount() 0 3 1
A prepareTotalCount() 0 3 2
A refresh() 0 5 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
    /**
22
     * To improve performance, implemented grid summary and pager loading via AJAX when this attribute is `false`
23
     * There is a possibility set this attribute via DI
24
     * @see \hipanel\base\SearchModelTrait::search()
25
     *
26
     * @var bool
27
     */
28
    public bool $countSynchronously = false;
29
30
    public function enableSynchronousCount(): void
31
    {
32
        $this->countSynchronously = true;
33
    }
34
35
    /**
36
     * When receiving the pager and summary through AJAX, to calculate the limit and offset of Grid,
37
     * you need to get the maximum possible total count, otherwise the Grid pages will not switch
38
     *
39
     * @return int
40
     * @throws \yii\base\InvalidConfigException
41
     */
42
    protected function prepareTotalCount(): int
43
    {
44
        return $this->countSynchronously ? parent::prepareTotalCount() : PHP_INT_MAX;
45
    }
46
47
    public function refresh(bool $keepTotalCount = false): void
0 ignored issues
show
Unused Code introduced by
The parameter $keepTotalCount is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
    public function refresh(/** @scrutinizer ignore-unused */ bool $keepTotalCount = false): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        $tc = $this->getTotalCount();
50
        parent::refresh();
51
        $this->setTotalCount($tc);
52
    }
53
}
54