Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
Profiler
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
8 / 8
9
100.00% covered (success)
100.00%
1 / 1
 init
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 add
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 addMemoryPeak
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getList
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getSeconds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMilliSeconds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Slim;
4
5class Profiler
6{
7    public static $startupMicrotime = null;
8    public static $profileList = [];
9
10    /**
11     * @SuppressWarnings(Superglobal)
12     *
13     */
14    public static function init()
15    {
16        static::$startupMicrotime = microtime(true);
17        if (isset($_SERVER["REQUEST_TIME_FLOAT"])) {
18            static::$startupMicrotime = $_SERVER["REQUEST_TIME_FLOAT"];
19        }
20    }
21
22    public static function add($message)
23    {
24        $profile = new static($message);
25        static::$profileList[] = $profile;
26        return $profile;
27    }
28
29    public static function addMemoryPeak($message = 'Mem')
30    {
31        $memoryKb = round(memory_get_peak_usage() / 1024, 0);
32        static::add("$message " . $memoryKb . "kb");
33    }
34
35    public static function getList()
36    {
37        return implode(";", static::$profileList);
38    }
39
40    protected $message = '';
41    protected $instanceMicrotime = null;
42    protected $includedFiles = 0;
43
44    public function __construct($message)
45    {
46        $this->message = $message;
47        $this->instanceMicrotime = microtime(true);
48        $this->includedFiles = count(get_included_files());
49    }
50
51    public function getSeconds()
52    {
53        return round(($this->instanceMicrotime - static::$startupMicrotime), 3);
54    }
55
56    public function getMilliSeconds()
57    {
58        return $this->getSeconds() * 1000;
59    }
60
61    public function __toString()
62    {
63        return $this->message . "=" . $this->getMilliSeconds() . "ms/#" . $this->includedFiles;
64    }
65}