Xhgui_Saver_Mongo   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 20 4
A getLastProfilingId() 0 6 2
1
<?php
2
3
class Xhgui_Saver_Mongo implements Xhgui_Saver_Interface
4
{
5
    /**
6
     * @var MongoCollection
7
     */
8
    private $_collection;
9
10
    /**
11
     * @var MongoId lastProfilingId
12
     */
13
    private static $lastProfilingId;
14
15
    public function __construct(MongoCollection $collection)
16
    {
17
        $this->_collection = $collection;
18
    }
19
20
    public function save(array $data)
21
    {
22
        if (!isset($data['_id'])) {
23
            $data['_id'] = self::getLastProfilingId();
24
        }
25
26
        if (isset($data['meta']['request_ts'])) {
27
            $data['meta']['request_ts'] = new MongoDate($data['meta']['request_ts']['sec']);
28
        }
29
30
        if (isset($data['meta']['request_ts_micro'])) {
31
            $data['meta']['request_ts_micro'] = new MongoDate(
32
                $data['meta']['request_ts_micro']['sec'],
33
                $data['meta']['request_ts_micro']['usec']
34
            );
35
        }
36
37
38
        return $this->_collection->insert($data, array('w' => 0));
39
    }
40
41
    /**
42
     * Return profiling ID
43
     * @return MongoId lastProfilingId
44
     */
45
    public static function getLastProfilingId() {
46
        if (!self::$lastProfilingId) {
47
            self::$lastProfilingId = new MongoId();
48
        }
49
        return self::$lastProfilingId;
50
    }
51
}
52