AbstractStorage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 0
cbo 3
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 15 4
getHistory() 0 1 ?
storeMessage() 0 1 ?
1
<?php
2
namespace jones\wschat\components;
3
4
use Yii;
5
use jones\wschat\collections\History;
6
7
/**
8
 * Class AbstractStorage
9
 *
10
 * Base class to create concrete implementer of message storing
11
 * @package jones\wschat\components
12
 */
13
abstract class AbstractStorage
14
{
15
    /**
16
     * Create instance of storage
17
     *
18
     * @access public
19
     * @static
20
     * @param string $storage default null
21
     * @return \jones\wschat\components\AbstractStorage
22
     */
23
    public static function factory($storage = null)
24
    {
25
        if (empty($storage)) {
26
            $components = Yii::$app->getComponents();
27
            $storage = !empty($components['mongodb']) ? 'mongodb' : Yii::$app->getDb()->driverName;
28
        }
29
        switch ($storage) {
30
            case 'mongodb':
31
                $class = new History();
32
                break;
33
            default:
34
                $class = new DbStorage();
35
        }
36
        return $class;
37
    }
38
39
    /**
40
     * Load chat history
41
     *
42
     * @access public
43
     * @param mixed $chatId
44
     * @param integer $limit
45
     * @return array
46
     */
47
    abstract public function getHistory($chatId, $limit = 10);
48
49
    /**
50
     * Store chat message
51
     *
52
     * @access public
53
     * @param array $params
54
     * @return boolean
55
     */
56
    abstract public function storeMessage(array $params);
57
}
58
59