Completed
Push — master ( 04df52...146700 )
by Lauri
16s
created

Xhgui_Profiles   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A insert() 0 5 1
A getLastProfilingId() 0 6 2
1
<?php
2
/**
3
 * Contains logic for getting/creating/removing profile records.
4
 */
5
class Xhgui_Profiles
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...
6
{
7
    protected $_collection;
8
9
    protected $_mapper;
10
11
    /**
12
     * @var MongoId lastProfilingId
13
     */
14
    private static $lastProfilingId;
15
16
    public function __construct(MongoDb $db)
17
    {
18
        $this->_collection = $db->results;
0 ignored issues
show
Bug introduced by
The property results does not seem to exist in MongoDB.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
19
    }
20
21
    /**
22
     * Insert a profile run.
23
     *
24
     * Does unchecked inserts.
25
     *
26
     * @param array $profile The profile data to save.
27
     */
28
    public function insert($profile)
29
    {
30
        $profile['_id'] = self::getLastProfilingId();
31
        return $this->_collection->insert($profile, array('w' => 0));
32
    }
33
34
    /**
35
     * Return profiling ID
36
     * @return MongoId lastProfilingId
37
     */
38
    public static function getLastProfilingId() {
39
        if (!self::$lastProfilingId) {
40
            self::$lastProfilingId = new MongoId();
41
        }
42
        return self::$lastProfilingId;
43
    }
44
}
45