Completed
Pull Request — master (#6)
by Marcel
01:15
created

Xhgui_Saver_Mongo   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 6 1
A getLastProfilingId() 0 6 2
1
<?php
2
3
class Xhgui_Saver_Mongo implements Xhgui_Saver_Interface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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
        $data['_id'] = self::getLastProfilingId();
23
24
        return $this->_collection->insert($data, array('w' => 0));
25
    }
26
27
    /**
28
     * Return profiling ID
29
     * @return MongoId lastProfilingId
30
     */
31
    public static function getLastProfilingId() {
32
        if (!self::$lastProfilingId) {
33
            self::$lastProfilingId = new MongoId();
34
        }
35
        return self::$lastProfilingId;
36
    }
37
}
38