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