Passed
Push — main ( d846f8...8b63c1 )
by mikhail
04:31
created

PerformanceMonitor::getPerformanceMetrics()   A

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
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\Metrics;
6
7
use SavinMikhail\CommentsDensity\DTO\Output\PerformanceMetricsDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...t\PerformanceMetricsDTO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use function memory_get_peak_usage;
9
use function microtime;
10
use function round;
11
12
final class PerformanceMonitor
13
{
14
    private float $startTime;
15
    private float $endTime;
16
    private float $peakMemoryUsage;
17
18 1
    public function start(): void
19
    {
20 1
        $this->startTime = microtime(true);
21
    }
22
23 1
    public function stop(): void
24
    {
25 1
        $this->endTime = microtime(true);
26 1
        $this->peakMemoryUsage = memory_get_peak_usage(true);
27
    }
28
29 1
    private function getExecutionTime(): float
30
    {
31 1
        return round(($this->endTime - $this->startTime) * 1000, 2);
32
    }
33
34 1
    private function getPeakMemoryUsage(): float
35
    {
36 1
        return round($this->peakMemoryUsage / 1024 / 1024, 2); // Convert to MB
37
    }
38
39 1
    public function getPerformanceMetrics(): PerformanceMetricsDTO
40
    {
41 1
        return new PerformanceMetricsDTO(
42 1
            $this->getExecutionTime(),
43 1
            $this->getPeakMemoryUsage()
44 1
        );
45
    }
46
}
47