Mongo::stop()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @author @fabfuel <[email protected]>
4
 * @created 13.11.14, 20:41 
5
 */
6
namespace Fabfuel\Prophiler\Adapter\Fabfuel;
7
8
use Fabfuel\Prophiler\Adapter\AdapterAbstract;
9
use Fabfuel\Prophiler\Benchmark\BenchmarkInterface;
10
use Mongo\Profiler\ProfilerInterface;
11
12
/**
13
 * Class Mongo
14
 * Profiler adapter for Fabfuel\Mongo
15
 *
16
 * Usage:
17
 * $profiler = new \Fabfuel\Prophiler\Profiler();
18
 * $adapter = new \Fabfuel\Prophiler\Adapter\Fabfuel\Mongo($profiler);
19
 * $mongoDb->setProfiler($adapter);
20
 *
21
 * @package Fabfuel\Prophiler\Adapter\Fabfuel
22
 */
23
class Mongo extends AdapterAbstract implements ProfilerInterface
24
{
25
    /**
26
     * @var BenchmarkInterface[]
27
     */
28
    protected $benchmarks = [];
29
30
    /**
31
     * Start a new benchmark
32
     *
33
     * @param string $name Unique identifier like e.g. Class::Method (\Foobar\MyClass::doSomething)
34
     * @param array $metadata Addtional interesting metadata for this benchmark
35
     * @return string benchmark identifier
36
     */
37 1
    public function start($name, array $metadata = [])
38
    {
39 1
        $benchmark = $this->getProfiler()->start($name, $metadata, 'MongoDB');
40 1
        $identifier = spl_object_hash($benchmark);
41 1
        $this->benchmarks[$identifier] = $benchmark;
42 1
        return $identifier;
43
    }
44
45
    /**
46
     * Stop a running benchmark
47
     *
48
     * @param string $identifier benchmark identifier
49
     * @return void
50
     */
51 1
    public function stop($identifier)
52
    {
53 1
        $benchmark = $this->benchmarks[$identifier];
54 1
        $this->getProfiler()->stop($benchmark);
55 1
    }
56
}
57