Passed
Push — renovate/php-8.x ( bfb893...222c0a )
by
unknown
02:20
created

TopLikeFormatter::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * This file is part of the sj-i/ package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Inspector\Output\TopLike;
15
16
use PhpProfiler\Lib\DateTime\Clock;
17
use PhpProfiler\Lib\PhpProcessReader\CallTrace;
18
19
final class TopLikeFormatter
20
{
21
    private Stat $stat;
22
    private \DateTimeImmutable $previous;
23
24
    public function __construct(
25
        private string $trace_target,
26
        private Outputter $outputter,
27
        private Clock $clock,
28
    ) {
29
        $this->stat = new Stat();
30
        $this->previous = $this->clock->now();
31
    }
32
33
    public function format(CallTrace $call_trace): void
34
    {
35
        $this->stat->addTrace($call_trace);
36
        $now = $this->clock->now();
37
        if ($now >= $this->previous->modify('+1 second')) {
38
            $this->outputter->display($this->trace_target, $this->stat);
39
            $this->previous = $now;
40
        }
41
    }
42
}
43