Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractProfiler
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStart
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 finish
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFinish
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getElapsed
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Db\Adapter\Profiler;
15
16/**
17 * Db abstract adapter profiler class
18 *
19 * @category   Pop
20 * @package    Pop\Db
21 * @author     Nick Sagona, III <dev@nolainteractive.com>
22 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    6.5.0
25 */
26abstract class AbstractProfiler implements ProfilerInterface
27{
28
29    /**
30     * Step start time
31     * @var ?float
32     */
33    protected ?float $start = null;
34
35    /**
36     * Step finish time
37     * @var ?float
38     */
39    protected ?float $finish = null;
40
41    /**
42     * Constructor
43     *
44     * Instantiate the profiler object
45     */
46    public function __construct()
47    {
48        $this->start = microtime(true);
49    }
50
51    /**
52     * Get start
53     *
54     * @return float|null
55     */
56    public function getStart(): float|null
57    {
58        return $this->start;
59    }
60
61    /**
62     * Finish profiler
63     *
64     * @return AbstractProfiler
65     */
66    public function finish(): AbstractProfiler
67    {
68        $this->finish = microtime(true);
69        return $this;
70    }
71
72    /**
73     * Get finish
74     *
75     * @return float|null
76     */
77    public function getFinish(): float|null
78    {
79        return $this->finish;
80    }
81
82    /**
83     * Get elapsed time
84     *
85     * @return string
86     */
87    public function getElapsed(): string
88    {
89        if ($this->finish === null) {
90            $this->finish();
91        }
92        return number_format(($this->finish - $this->start), 5);
93    }
94
95}