MongoProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStorageState() 0 10 1
A setStorageState() 0 7 1
1
<?php
2
3
namespace yiicod\pagesizepager\providers;
4
5
use Yii;
6
use yii\mongodb\Query;
7
8
/**
9
 * Class MongoProvider
10
 *
11
 * @author Orlov Aleksey <[email protected]>
12
 * @package yiicod\pagesizepager\providers
13
 */
14
class MongoProvider extends ProviderAbstract
15
{
16
    /**
17
     * Get storage state value
18
     *
19
     * @param string $key
20
     * @param $default
21
     *
22
     * @return mixed
23
     */
24
    public function getStorageState(string $key, $default = null): array
25
    {
26
        $query = new Query();
27
        $row = $query
28
            ->from('yii_page_size')
29
            ->where(['name' => $key])
30
            ->one();
31
32
        return $row['value'] ?? [];
33
    }
34
35
    /**
36
     * Set storage state value
37
     *
38
     * @param string $key
39
     * @param $value
40
     */
41
    public function setStorageState(string $key, array $value)
42
    {
43
        $collection = Yii::$app->mongodb->getCollection('yii_page_size');
44
        $collection->update(['name' => $key], ['value' => $value], [
45
            'upsert' => true,
46
        ]);
47
    }
48
}
49