Passed
Pull Request — master (#74)
by Rustam
02:41
created

ConsoleAppInfoCollector::getIndexData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\Yii\Console\Event\ApplicationShutdown;
8
use Yiisoft\Yii\Console\Event\ApplicationStartup;
9
10
final class ConsoleAppInfoCollector implements CollectorInterface, IndexCollectorInterface
11
{
12
    use CollectorTrait;
13
14
    private float $applicationProcessingTimeStarted = 0;
15
    private float $applicationProcessingTimeStopped = 0;
16
    private float $requestProcessingTimeStarted = 0;
0 ignored issues
show
introduced by
The private property $requestProcessingTimeStarted is not used, and could be removed.
Loading history...
17
    private float $requestProcessingTimeStopped = 0;
0 ignored issues
show
introduced by
The private property $requestProcessingTimeStopped is not used, and could be removed.
Loading history...
18
19 1
    public function getCollected(): array
20
    {
21
        return [
22 1
            'application_processing_time' => $this->applicationProcessingTimeStopped - $this->applicationProcessingTimeStarted,
23 1
            'memory_peak_usage' => memory_get_peak_usage(),
24 1
            'memory_usage' => memory_get_usage(),
25
        ];
26
    }
27
28 1
    public function collect(object $event): void
29
    {
30 1
        if (!is_object($event) || !$this->isActive()) {
31
            return;
32
        }
33
34 1
        if ($event instanceof ApplicationStartup) {
35 1
            $this->applicationProcessingTimeStarted = microtime(true);
36 1
        } elseif ($event instanceof ApplicationShutdown) {
37 1
            $this->applicationProcessingTimeStopped = microtime(true);
38
        }
39 1
    }
40
41 1
    public function getIndexData(): array
42
    {
43
        return [
44 1
            'time' => $this->applicationProcessingTimeStopped - $this->applicationProcessingTimeStarted,
45 1
            'memory' => memory_get_peak_usage(),
46 1
            'timestamp' => $this->applicationProcessingTimeStarted,
47
        ];
48
    }
49
50 1
    private function reset(): void
0 ignored issues
show
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
51
    {
52 1
        $this->applicationProcessingTimeStarted = 0;
53 1
        $this->applicationProcessingTimeStopped = 0;
54 1
    }
55
}
56