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

Xhgui_Profiles::getLastProfilingId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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